diff -r afd58d4c7b5b -r 30aca5888d2b main/recipes.c --- a/main/recipes.c Tue Nov 02 14:47:43 2021 +0100 +++ b/main/recipes.c Sat Jun 25 15:24:55 2022 +0200 @@ -20,8 +20,8 @@ int r_Imported = 0; ///< Total imported char _xml_element[10][32]; ///< XML element array int _xml_depth; ///< Current depths -char _xml_add_name[64]; ///< Mash name -int _xml_add_type; ///< Mash type +char _xml_add_name[64]; ///< Addition name +int _xml_add_type; ///< Addition type int _xml_add_time; ///< Mash rest time int _xml_add_ramp; ///< Mash ramp time float _xml_add_temp; ///< Mash start temperature @@ -49,6 +49,16 @@ */ void Addition_Add(char *Name, uint8_t Type, uint16_t Time) { + if (Type == ADDITION_HOP_AROMA && Time > 0) { + /* + * Whirlpool hop. + */ + recipe.Whirlpool7 = Time; + return; + } + if (Type == ADDITION_HOP_AROMA) + Type = ADDITION_HOP_BOIL; /* Flame-out hop, change to boil with zero time. */ + if (! recipe.Additions) { // No entries yet, add the first one. snprintf(recipe.Addition[recipe.Additions].Name, 63, "%s", Name); @@ -72,10 +82,10 @@ for (int i = 0; i < recipe.Additions; i++) { if (Time > recipe.Addition[i].Time) { // Make room - for (int j = i; j < recipe.Additions; j++) { - sprintf(recipe.Addition[j+1].Name, "%s", recipe.Addition[j].Name); - recipe.Addition[j+1].Type = recipe.Addition[j].Type; - recipe.Addition[j+1].Time = recipe.Addition[j].Time; + for (int j = recipe.Additions; j > i; j--) { + sprintf(recipe.Addition[j].Name, "%s", recipe.Addition[j-1].Name); + recipe.Addition[j].Type = recipe.Addition[j-1].Type; + recipe.Addition[j].Time = recipe.Addition[j-1].Time; } snprintf(recipe.Addition[i].Name, 63, "%s", Name); recipe.Addition[i].Type = Type; @@ -151,19 +161,23 @@ } else if ((_xml_depth == 3) && (strcmp("BOIL_TIME", _xml_element[2]) == 0)) { recipe.BoilTime = atoi(char_data_buffer); } else if ((_xml_depth == 3) && (strcmp("BMS_COOLING_TO", _xml_element[2]) == 0)) { - recipe.CoolTemp = atoi(char_data_buffer); + recipe.CoolTemp = atof(char_data_buffer); } else if ((_xml_depth == 5) && (strcmp("HOPS", _xml_element[2]) == 0) && (strcmp("HOP", _xml_element[3]) == 0)) { /* * Hops that are added during the boil. - * But check for whirlpool hops too. + * But check for "Aroma" hops too. */ if (strcmp("NAME", _xml_element[4]) == 0) { _xml_add_name[0] = '\0'; strncat(_xml_add_name, char_data_buffer, 63); + _xml_add_time = 0; // reset } else if (strcmp("USE", _xml_element[4]) == 0) { - _xml_add_valid = (strcmp("Boil", char_data_buffer) == 0); // Only "Boil" is a valid hop - if (strcmp("Aroma", char_data_buffer) == 0) { - recipe.Whirlpool7 = 30; + if (strcmp("Boil", char_data_buffer) == 0) { + _xml_add_valid = true; + _xml_add_type = ADDITION_HOP_BOIL; + } else if (strcmp("Aroma", char_data_buffer) == 0) { + _xml_add_type = ADDITION_HOP_AROMA; + _xml_add_valid = true; } } else if (strcmp("TIME", _xml_element[4]) == 0) { _xml_add_time = atoi(char_data_buffer); @@ -285,7 +299,7 @@ reset_char_data_buffer(); if ((_xml_depth == 4) && (strcmp("HOP", _xml_element[3]) == 0)) { if (_xml_add_valid) { - Addition_Add(_xml_add_name, ADDITION_HOP, _xml_add_time); + Addition_Add(_xml_add_name, _xml_add_type, _xml_add_time); } } if ((_xml_depth == 4) && (strcmp("FERMENTABLE", _xml_element[3]) == 0)) { @@ -311,7 +325,6 @@ */ if (_xml_add_type == MASHTYPE_TEMPERATURE && recipe.Mashsteps == 0) { _xml_add_type = MASHTYPE_INFUSION; -// _xml_add_infusion = _xml_add_temp + 1.25; recipe.MashStep[recipe.Mashsteps].Ramp_time = 1; } recipe.MashStep[recipe.Mashsteps].Type = _xml_add_type; @@ -388,18 +401,16 @@ #if 0 printf("Recipe: %s\n", recipe.Name); printf("Code : %s\n", recipe.Code); - printf("Boil time %d minutes\n", recipe.BoilTime); + printf("Boil : %d minutes\n", recipe.BoilTime); printf("n Stepname T temp end time ramp inft infa\n"); printf("- ------------------------------ - ----- ----- ---- ---- ----- -----\n"); - for (int i = 0; i < 8; i++) { - if (recipe.MashStep[i].Step_time) { - printf("%d %-30s %d %5.2f %5.2f %4d %4d %5.2f %5.2f\n", i, recipe.MashStep[i].Name, recipe.MashStep[i].Type, + for (int i = 0; i < recipe.Mashsteps; i++) { + printf("%d %-30s %d %5.2f %5.2f %4d %4d %5.2f %5.2f\n", i, recipe.MashStep[i].Name, recipe.MashStep[i].Type, recipe.MashStep[i].Step_temp, recipe.MashStep[i].End_temp, recipe.MashStep[i].Step_time, recipe.MashStep[i].Ramp_time, recipe.MashStep[i].Infuse_temp, recipe.MashStep[i].Infuse_amount); - } } - printf("%d additions\n", recipe.Additions); + printf("\n%d additions\n", recipe.Additions); printf("n Addition name t Tim\n"); printf("- --------------------------------------------------------------- - ---\n"); for (int i = 0; i < recipe.Additions; i++) { @@ -642,10 +653,10 @@ recipe.Additions = 2; sprintf(recipe.Addition[0].Name, "Bitterhop"); recipe.Addition[0].Time = 60; - recipe.Addition[0].Type = ADDITION_HOP; + recipe.Addition[0].Type = ADDITION_HOP_BOIL; sprintf(recipe.Addition[1].Name, "Aromahop"); recipe.Addition[1].Time = 10; - recipe.Addition[1].Type = ADDITION_HOP; + recipe.Addition[1].Type = ADDITION_HOP_BOIL; recipe.CoolTemp = 20.0; recipe.Whirlpool9 = 0; recipe.Whirlpool7 = 0; @@ -786,7 +797,7 @@ } else { EditUint16(tmp, &recipe.Addition[i].Time, 0, recipe.Addition[i-1].Time - 1); } - recipe.Addition[i].Type = ADDITION_HOP; + recipe.Addition[i].Type = ADDITION_HOP_BOIL; } } else { recipe.Additions = 0;