diff -r 3ff381bfa469 -r 66c77497d86d main/recipes.c --- a/main/recipes.c Mon Jun 01 20:27:00 2020 +0200 +++ b/main/recipes.c Sat Jun 06 13:28:46 2020 +0200 @@ -20,12 +20,12 @@ int r_Imported = 0; ///< Total imported char _xml_element[10][32]; ///< XML element array int _xml_depth; ///< Current depths -int _xml_mashsteps; ///< Mash steps char _xml_add_name[64]; ///< Mash name int _xml_add_type; ///< Mash type int _xml_add_time; ///< Mash rest time int _xml_add_ramp; ///< Mash ramp time -float _xml_add_temp; ///< Mash temperature +float _xml_add_temp; ///< Mash start temperature +float _xml_add_end; ///< Mash end temperature float _xml_add_amount; ///< Mash infusion amount float _xml_add_infusion; ///< Mash infusion temperature float _xml_tun_temp; ///< TUN temperature @@ -52,8 +52,6 @@ if (! recipe.Additions) { // No entries yet, add the first one. snprintf(recipe.Addition[recipe.Additions].Name, 63, "%s", Name); -// recipe.Addition[recipe.Additions].Name = ""; -// strncat(recipe.Addition[recipe.Additions].Name, Name, 63); recipe.Addition[recipe.Additions].Type = Type; recipe.Addition[recipe.Additions].Time = Time; recipe.Additions++; @@ -64,7 +62,6 @@ for (int i = 0; i < recipe.Additions; i++) { if (recipe.Addition[i].Time == Time) { // Yes, update the name. - //snprintf(recipe.Addition[i].Name, 63, "%s, %s", recipe.Addition[i].Name, Name); strncat(recipe.Addition[i].Name, ", ", 63 - strlen(recipe.Addition[i].Name)); strncat(recipe.Addition[i].Name, Name, 63 - strlen(recipe.Addition[i].Name)); return; @@ -223,8 +220,8 @@ _xml_add_name[0] = '\0'; strncat(_xml_add_name, char_data_buffer, 63); } else if (strcmp("TYPE", _xml_element[5]) == 0) { - // Temperature Infusion Decoction - _xml_add_valid = (strcmp("Temperature", char_data_buffer) == 0); + // Step_temp Infusion Decoction + _xml_add_valid = (strcmp("Step_temp", char_data_buffer) == 0); if (strcmp("Infusion", char_data_buffer) == 0) _xml_add_type = MASHTYPE_INFUSION; else if (strcmp("Temperature", char_data_buffer) == 0) @@ -241,6 +238,10 @@ _xml_add_amount = atof(char_data_buffer); } else if (strcmp("INFUSE_TEMP", _xml_element[5]) == 0) { _xml_add_infusion = atof(char_data_buffer); + } else if (strcmp("DECOCTION_AMT", _xml_element[5]) == 0) { + _xml_add_amount = atof(char_data_buffer); + } else if (strcmp("END_TEMP", _xml_element[5]) == 0) { + _xml_add_end = atof(char_data_buffer); } } else if ((_xml_depth >= 4) && (strcmp("TUN_TEMP", _xml_element[3]) == 0)) { // Save this and check later if this is the strike temperature. @@ -296,20 +297,24 @@ } } if ((_xml_depth == 5) && (strcmp("MASH_STEP", _xml_element[4]) == 0)) { - _xml_mashsteps++; - recipe.MashStep[_xml_mashsteps].Name[0] = '\0'; - strncat(recipe.MashStep[_xml_mashsteps].Name, _xml_add_name, 31); - recipe.MashStep[_xml_mashsteps].Type = _xml_add_type; - recipe.MashStep[_xml_mashsteps].Temperature = _xml_add_temp; - recipe.MashStep[_xml_mashsteps].Resttime = _xml_add_time; - recipe.MashStep[_xml_mashsteps].Ramptime = _xml_add_ramp; + recipe.MashStep[recipe.Mashsteps].Name[0] = '\0'; + strncat(recipe.MashStep[recipe.Mashsteps].Name, _xml_add_name, 31); + recipe.MashStep[recipe.Mashsteps].Type = _xml_add_type; + recipe.MashStep[recipe.Mashsteps].Step_temp = _xml_add_temp; + recipe.MashStep[recipe.Mashsteps].Step_time = _xml_add_time; + recipe.MashStep[recipe.Mashsteps].Ramp_time = _xml_add_ramp; + recipe.MashStep[recipe.Mashsteps].End_temp = _xml_add_end; if (_xml_add_type == MASHTYPE_INFUSION) { - recipe.MashStep[_xml_mashsteps].Infusion_temp = _xml_add_infusion; - recipe.MashStep[_xml_mashsteps].Infusion_amount = _xml_add_amount; + recipe.MashStep[recipe.Mashsteps].Infuse_temp = _xml_add_infusion; + recipe.MashStep[recipe.Mashsteps].Infuse_amount = _xml_add_amount; + } else if (_xml_add_type == MASHTYPE_DECOCTION) { + recipe.MashStep[recipe.Mashsteps].Infuse_temp = 0.0; + recipe.MashStep[recipe.Mashsteps].Infuse_amount = _xml_add_amount; } else { - recipe.MashStep[_xml_mashsteps].Infusion_temp = 0.0; - recipe.MashStep[_xml_mashsteps].Infusion_amount = 0.0; + recipe.MashStep[recipe.Mashsteps].Infuse_temp = 0.0; + recipe.MashStep[recipe.Mashsteps].Infuse_amount = 0.0; } + recipe.Mashsteps++; } _xml_depth--; } @@ -320,12 +325,13 @@ { char buf[512]; - memset(&recipe, 0, sizeof(recipe)); + memset(&recipe, 0, recipe_hdr.recsize); + for (int i = 0; i < recipe_hdr.mashmax; i++) + recipe.MashStep[i].Type = 255; XML_Parser parser = XML_ParserCreate(NULL); int done; _xml_depth = 0; - _xml_mashsteps = 0; _xml_tun_temp = 0.0; XML_SetElementHandler(parser, startElement, endElement); @@ -337,7 +343,7 @@ int len = (int)fread(buf, 1, sizeof(buf), fp); done = len < sizeof(buf); if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) { - printf( "%s at line %5lu\n", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); + ESP_LOGE(TAG, "%s at line %5lu", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); return 1; } vTaskDelay(2 / portTICK_PERIOD_MS); @@ -358,49 +364,6 @@ } } recipe.CoolTemp = 20.0; - sprintf(recipe.MashStep[0].Name, "Mash-in"); - if ((recipe.MashStep[1].Type == MASHTYPE_INFUSION) && (recipe.MashStep[1].Infusion_temp > 0.0)) { - /* If next (first original) step is infusion, take that temperature. */ - recipe.MashStep[0].Temperature = recipe.MashStep[1].Infusion_temp; - } else if (_xml_tun_temp > recipe.MashStep[1].Temperature) { - recipe.MashStep[0].Temperature = _xml_tun_temp; - } else { - recipe.MashStep[0].Temperature = recipe.MashStep[1].Temperature + 1.25; - } - recipe.MashStep[0].Resttime = recipe.MashStep[0].Ramptime = 1; - recipe.MashStep[0].Type = MASHTYPE_INFUSION; - /* - * Because we inserted the first infusion step and the next (original first) - * step is infusion, change that one into temperature. - */ - if (recipe.MashStep[1].Type == MASHTYPE_INFUSION) { - recipe.MashStep[1].Type = MASHTYPE_TEMPERATURE; - recipe.MashStep[1].Infusion_temp = recipe.MashStep[1].Infusion_amount = 0.0; - } - - if (! recipe.MashStep[7].Resttime) { - // Move last mash step to position 7. - for (int i = 6; i > 1; i--) { - if (recipe.MashStep[i].Resttime) { - // Got it, move. - sprintf(recipe.MashStep[7].Name, "%s", recipe.MashStep[i].Name); - recipe.MashStep[i].Name[0] = '\0'; - recipe.MashStep[7].Type = recipe.MashStep[i].Type; - recipe.MashStep[i].Type = 0; - recipe.MashStep[7].Temperature = recipe.MashStep[i].Temperature; - recipe.MashStep[i].Temperature = 0.0; - recipe.MashStep[7].Resttime = recipe.MashStep[i].Resttime; - recipe.MashStep[i].Resttime = 0; - recipe.MashStep[7].Ramptime = recipe.MashStep[i].Ramptime; - recipe.MashStep[i].Ramptime = 0; - recipe.MashStep[7].Infusion_temp = recipe.MashStep[i].Infusion_temp; - recipe.MashStep[i].Infusion_temp = 0.0; - recipe.MashStep[7].Infusion_amount = recipe.MashStep[i].Infusion_amount; - recipe.MashStep[i].Infusion_amount = 0.0; - break; - } - } - } #if 0 printf("Recipe: %s\n", recipe.Name); @@ -409,10 +372,10 @@ printf("n Stepname T temp time ramp inft infa\n"); printf("- ------------------------------ - ----- ---- ---- ----- -----\n"); for (int i = 0; i < 8; i++) { - if (recipe.MashStep[i].Resttime) { - printf("%d %-30s %d %5.2f %4d %4d %5.2f %5.2f\n", i, recipe.MashStep[i].Name, recipe.MashStep[i].Type, recipe.MashStep[i].Temperature, - recipe.MashStep[i].Resttime, recipe.MashStep[i].Ramptime, - recipe.MashStep[i].Infusion_temp, recipe.MashStep[i].Infusion_amount); + if (recipe.MashStep[i].Step_time) { + printf("%d %-30s %d %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].Step_time, recipe.MashStep[i].Ramp_time, + recipe.MashStep[i].Infuse_temp, recipe.MashStep[i].Infuse_amount); } } printf("%d additions\n", recipe.Additions); @@ -488,9 +451,10 @@ } f = fopen("/spiffs/etc/recipe.conf", "r"); + fseek(f, recipe_hdr.hdrsize, SEEK_SET); dst = (uint8_t*)&recipe; r_Records = 0; - while ((bytes = fread(dst, 1, sizeof(recipe), f))) { + while ((bytes = fread(dst, 1, recipe_hdr.recsize, f))) { r_Records++; } fclose(f); @@ -515,10 +479,10 @@ { uint32_t crc1, crc2; uint8_t *dst; - int mashsteps; uint16_t y; char tmp[64]; - float mintemp; + float mintemp, maxtemp; + int i; switch (Main_Screen) { case MAIN_TOOLS_RECIPE: @@ -548,25 +512,28 @@ ShowInteger(162, 44, (char *)"Record", NULL, r_CurrentRec); ShowInteger(2, 60, (char *)"Kooktijd", (char *)" min", recipe.BoilTime); ShowFloat(162, 60, (char *)"Koel tot", (char *)" C", recipe.CoolTemp, 2); - ShowFloat(2, 76, (char *)"Maisch in", (char *)" C", recipe.MashStep[0].Temperature, 2); + ShowFloat(2, 76, (char *)"Maisch in", (char *)" C", recipe.MashStep[0].Infuse_temp, 3); ShowFloat(162, 76, (char *)"Spoelwater", (char *)" C", recipe.SpargeTemp, 2); y = 92; _fg = TFT_WHITE; TFT_print((char *)"Maisch stap", 2, y); - TFT_print((char *)"T", 200, y); - TFT_print((char *)"Temp.", 220, y); + TFT_print((char *)"T", 180, y); + TFT_print((char *)"Temp.", 200, y); TFT_print((char *)"Rust", 280, y); _fg = TFT_YELLOW; y += 16; - for (int i = 1; i < 8; i++) { - if (recipe.MashStep[i].Resttime) { + for (i = 0; i < recipe_hdr.mashmax; i++) { + ESP_LOGI(TAG, "%2d %-31s %3d %5.2f %5.2f %2d %2d %7.4f %6.3f", 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); + if (recipe.MashStep[i].Type != 255) { TFT_print(recipe.MashStep[i].Name, 2, y); strcpy(tmp, mashTypes[recipe.MashStep[i].Type]); tmp[1] = '\0'; + TFT_print(tmp, 180, y); + sprintf(tmp, "%.1f %.1f", recipe.MashStep[i].Step_temp, recipe.MashStep[i].End_temp); TFT_print(tmp, 200, y); - sprintf(tmp, "%.2f", recipe.MashStep[i].Temperature); - TFT_print(tmp, 220, y); - sprintf(tmp, "%2d m", recipe.MashStep[i].Resttime); + sprintf(tmp, "%2d m", recipe.MashStep[i].Step_time); TFT_print(tmp, 280, y); y += 16; } @@ -632,26 +599,24 @@ case 0: Main_Screen = MAIN_TOOLS; break; - case 1: memset(&recipe, 0, sizeof(recipe)); - recipe.Version = 1; - for (int i = 1; i < 8; i++) - recipe.MashStep[i].Type = MASHTYPE_TEMPERATURE; - sprintf(recipe.Name, "Recipe %d", r_Records + 1); + case 1: memset(&recipe, 0, sizeof(recipe)); // new recipe + for (i = 1; i < recipe_hdr.mashmax; i++) + recipe.MashStep[i].Type = 255; + sprintf(recipe.Name, "Recept %d", r_Records + 1); sprintf(recipe.Code, "00%d", r_Records + 1); - sprintf(recipe.MashStep[0].Name, "Mash-in"); + sprintf(recipe.MashStep[0].Name, "Maischen"); recipe.MashStep[0].Type = MASHTYPE_INFUSION; - recipe.MashStep[0].Temperature = recipe.MashStep[0].Infusion_temp = 67.5; - recipe.MashStep[0].Infusion_amount = 15.0; - recipe.MashStep[0].Resttime = 1; - recipe.MashStep[0].Ramptime = 1; - sprintf(recipe.MashStep[1].Name, "Mash"); - recipe.MashStep[1].Temperature = 67.0; - recipe.MashStep[1].Resttime = 75; - recipe.MashStep[1].Ramptime = 1; - sprintf(recipe.MashStep[7].Name, "Mash-out"); - recipe.MashStep[7].Temperature = 78.0; - recipe.MashStep[7].Resttime = 5; - recipe.MashStep[7].Ramptime = 11; + recipe.MashStep[0].Step_temp = recipe.MashStep[0].End_temp = 67.0; + recipe.MashStep[0].Infuse_temp = 67.5; + recipe.MashStep[0].Infuse_amount = 15.0; + recipe.MashStep[0].Step_time = 75; + recipe.MashStep[0].Ramp_time = 1; + sprintf(recipe.MashStep[1].Name, "Mash-out"); + recipe.MashStep[1].Type = MASHTYPE_TEMPERATURE; + recipe.MashStep[1].Step_temp = recipe.MashStep[1].End_temp = 78.0; + recipe.MashStep[1].Step_time = 10; + recipe.MashStep[1].Ramp_time = 13; + recipe.Mashsteps = 2; recipe.BoilTime = 60; recipe.Additions = 2; sprintf(recipe.Addition[0].Name, "Bitterhop"); @@ -674,9 +639,13 @@ break; case 2: if ((r_CurrentRec != config.RecipeRec) && (r_Records > 1)) { + _bg = TFT_BLACK; + TFT_fillScreen(_bg); + TFT_resetclipwin(); + TopMessage((char *)"Recept verwijderen"); delete_recipe(r_CurrentRec); r_Records--; - if (r_CurrentRec > r_Records) + if (r_CurrentRec >= r_Records) r_CurrentRec = r_Records; r_UpdateRec = true; } @@ -715,52 +684,71 @@ EditText((char *)"Naam", recipe.Name, 31); EditText((char *)"Code", recipe.Code, 31); - mashsteps = 0; - for (int i = 1; i < 7; i++) { - if (recipe.MashStep[i].Resttime) - mashsteps++; - } - EditInt((char *)"Maisch stappen", &mashsteps, 1, 6); - EditFloat((char *)"Inmaisch temperatuur", &recipe.MashStep[0].Temperature, 38, 74, 2); - // Round to 0.0625 values - recipe.MashStep[0].Temperature = ((int)(recipe.MashStep[0].Temperature * 16)) / 16.0; - for (int i = 1; i <= mashsteps; i++) { - sprintf(tmp, "Maisch stap %d naam", i); + EditUint8((char *)"Maisch stappen", &recipe.Mashsteps, 1, 6); + for (i = 0; i < recipe.Mashsteps; i++) { + int step = i + 1; + if (i == (recipe.Mashsteps - 1)) { + mintemp = 75.0; + maxtemp = 80.0; + } else { + mintemp = 35.0; + maxtemp = 74.0; + } + if (recipe.MashStep[i].Type == 255) { + // A new step, set default values. + recipe.MashStep[i].Type = MASHTYPE_TEMPERATURE; + recipe.MashStep[i].Step_time = 20; + if (i == 0) { + recipe.MashStep[i].Type = MASHTYPE_INFUSION; + recipe.MashStep[i].Step_temp = recipe.MashStep[i].End_temp = 62.0; + recipe.MashStep[i].Infuse_temp = 62.5; + recipe.MashStep[i].Infuse_amount = 15; + recipe.MashStep[i].Ramp_time = 1; + } else if (i == (recipe.Mashsteps - 1)) { + recipe.MashStep[i].Step_temp = recipe.MashStep[i].End_temp = 78.0; + recipe.MashStep[i].Step_time = 10; + recipe.MashStep[i].Ramp_time = (int)(recipe.MashStep[i].Step_temp - recipe.MashStep[i - 1].Step_temp + 2); + } else { + recipe.MashStep[i].Step_temp = recipe.MashStep[i].End_temp = recipe.MashStep[i - 1].Step_temp + 2.0; + recipe.MashStep[i].Ramp_time = (int)(recipe.MashStep[i].Step_temp - recipe.MashStep[i - 1].Step_temp + 2); + } + } + sprintf(tmp, "Maisch stap %d naam", step); EditText(tmp, recipe.MashStep[i].Name, 31); EditMashType(&recipe.MashStep[i].Type); - sprintf(tmp, "Maisch stap %d temperatuur", i); - if (i == 1) - mintemp = recipe.MashStep[0].Temperature - 5; - else - mintemp = recipe.MashStep[i - 1].Temperature; - EditFloat(tmp, &recipe.MashStep[i].Temperature, mintemp, 74, 2); + sprintf(tmp, "Maisch stap %d start temperatuur", step); + EditFloat(tmp, &recipe.MashStep[i].Step_temp, mintemp, maxtemp, 2); // Round to 0.25 values - recipe.MashStep[i].Temperature = ((int)(recipe.MashStep[i].Temperature * 4)) / 4.0; - sprintf(tmp, "Maisch stap %d rusttijd in minuten", i); - EditUint16(tmp, &recipe.MashStep[i].Resttime, 1, 480); - if (i == 1) { - recipe.MashStep[i].Ramptime = 1; + recipe.MashStep[i].Step_temp = ((int)(recipe.MashStep[i].Step_temp * 4)) / 4.0; + sprintf(tmp, "Maisch stap %d eind temperatuur", step); + EditFloat(tmp, &recipe.MashStep[i].End_temp, mintemp, maxtemp, 2); + recipe.MashStep[i].End_temp = ((int)(recipe.MashStep[i].End_temp * 4)) / 4.0; + sprintf(tmp, "Maisch stap %d rusttijd in minuten", step); + EditUint16(tmp, &recipe.MashStep[i].Step_time, 1, 480); + if (recipe.MashStep[i].Type == MASHTYPE_INFUSION) { + sprintf(tmp, "Stap %d infusie temperatuur", step); + EditFloat(tmp, &recipe.MashStep[i].Infuse_temp, 10, 99, 3); + recipe.MashStep[i].Infuse_temp = ((int)(recipe.MashStep[i].Infuse_temp * 16)) / 16.0; + sprintf(tmp, "Stap %d infusie volume", step); + EditFloat(tmp, &recipe.MashStep[i].Infuse_amount, 0.5, 1000.0, 3); + recipe.MashStep[i].Ramp_time = 2; + } else if (recipe.MashStep[i].Type == MASHTYPE_DECOCTION) { + recipe.MashStep[i].Infuse_temp = 0.0; + recipe.MashStep[i].Ramp_time = 2; + sprintf(tmp, "Stap %d decoctie volume", step); + EditFloat(tmp, &recipe.MashStep[i].Infuse_amount, 0.5, 1000.0, 3); } else { - recipe.MashStep[i].Ramptime = (int)(recipe.MashStep[i].Temperature - recipe.MashStep[i - 1].Temperature); - } - if (recipe.MashStep[i].Type == MASHTYPE_INFUSION) { - sprintf(tmp, "Stap %d infusie temperatuur", i); - mintemp = recipe.MashStep[i].Temperature; - EditFloat(tmp, &recipe.MashStep[i].Infusion_temp, mintemp, 100, 2); - sprintf(tmp, "Stap %d infusie volume", i); - EditFloat(tmp, &recipe.MashStep[i].Infusion_amount, 0.5, 1000.0, 2); - } else { - recipe.MashStep[i].Infusion_temp = recipe.MashStep[i].Infusion_amount = 0.0; + recipe.MashStep[i].Infuse_temp = recipe.MashStep[i].Infuse_amount = 0.0; + sprintf(tmp, "Stap %d opwarm tijd", step); + EditUint16(tmp, &recipe.MashStep[i].Ramp_time, 1, 480); } } - mintemp = recipe.MashStep[mashsteps].Temperature; - EditFloat((char *)"Uitmaischen temperatuur", &recipe.MashStep[7].Temperature, mintemp, 80, 2); - recipe.MashStep[7].Temperature = ((int)(recipe.MashStep[7].Temperature * 4)) / 4.0; - EditUint16((char *)"Uitmaischen tijd in minuten", &recipe.MashStep[7].Resttime, 1, 15); - recipe.MashStep[7].Ramptime = (int)(recipe.MashStep[7].Temperature - recipe.MashStep[mashsteps].Temperature); - // Zero any higher steps to diable them. - for (int i = (mashsteps + 1); i < 7; i++) - recipe.MashStep[i].Resttime = 0; + for (i = recipe.Mashsteps; i < recipe_hdr.mashmax; i++) { + recipe.MashStep[i].Type = 255; + recipe.MashStep[i].Step_temp = recipe.MashStep[i].End_temp = recipe.MashStep[i].Infuse_temp = recipe.MashStep[i].Infuse_amount = 0.0; + recipe.MashStep[i].Step_time = recipe.MashStep[i].Ramp_time = 0; + recipe.MashStep[i].Name[0] = '\0'; + } EditUint16((char *)"Kook tijd in minuten", &recipe.BoilTime, 0, 480); if (recipe.BoilTime) { @@ -779,6 +767,8 @@ } recipe.Addition[i].Type = ADDITION_HOP; } + } else { + recipe.Additions = 0; } EditFloat((char *)"Koel temperatuur", &recipe.CoolTemp, 10, 45, 2);