Fri, 05 Jul 2019 16:14:58 +0200
Version 0.3.5
0 | 1 | /** |
2 | * @file recipes.c | |
4 | 3 | * @brief Recipes management. If new beerxml recipes are detected in |
4 | * the /recipe directory on the SD card they will be imported | |
5 | * when you enter the recipes menu. After successfull import the | |
6 | * xml file extensions will be changed to xok to prevent that | |
7 | * the recipe is imported again. After the import the recipe | |
8 | * editor is shown. | |
0 | 9 | */ |
10 | ||
11 | #include "config.h" | |
12 | ||
13 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
14 | extern sButton Buttons[MAXBUTTONS]; ///< Buttons definitions |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
15 | extern int Main_Screen; ///< Current screen |
0 | 16 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
17 | bool r_UpdateRec = false; ///< Update record flag |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
18 | int r_CurrentRec = 1; ///< Current record |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
19 | int r_Records = 1; ///< Total records |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
20 | int r_Imported = 0; ///< Total imported |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
21 | char _xml_element[10][32]; ///< XML element array |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
22 | int _xml_depth; ///< Current depths |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
23 | int _xml_mashsteps; ///< Mash steps |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
24 | char _xml_add_name[64]; ///< Mash name |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
25 | int _xml_add_type; ///< Mash type |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
26 | int _xml_add_time; ///< Mash rest time |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
27 | int _xml_add_ramp; ///< Mash ramp time |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
28 | float _xml_add_temp; ///< Mash temperature |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
29 | float _xml_add_amount; ///< Mash infusion amount |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
30 | float _xml_add_infusion; ///< Mash infusion temperature |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
31 | float _xml_tun_temp; ///< TUN temperature |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
32 | bool _xml_add_valid; ///< Add is valid |
0 | 33 | |
34 | static const char *TAG = "recipes"; | |
35 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
36 | char char_data_buffer[1024]; ///< Data buffer |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
37 | size_t offs; ///< Offset in buffer |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
38 | bool overflow; ///< Overflow in buffer |
0 | 39 | |
19 | 40 | extern const char *mashTypes[]; |
41 | ||
0 | 42 | |
43 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
44 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
45 | * @brief Add addition to the recipe. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
46 | * @param Name The addition name. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
47 | * @param Type The addition type. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
48 | * @param Time The addition time to add. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
49 | */ |
0 | 50 | void Addition_Add(char *Name, uint8_t Type, uint16_t Time) |
51 | { | |
52 | if (! recipe.Additions) { | |
53 | // No entries yet, add the first one. | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
54 | snprintf(recipe.Addition[recipe.Additions].Name, 63, "%s", Name); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
55 | // recipe.Addition[recipe.Additions].Name = ""; |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
56 | // strncat(recipe.Addition[recipe.Additions].Name, Name, 63); |
0 | 57 | recipe.Addition[recipe.Additions].Type = Type; |
58 | recipe.Addition[recipe.Additions].Time = Time; | |
59 | recipe.Additions++; | |
60 | return; | |
61 | } | |
62 | ||
63 | // See if we already got one with the same time. | |
64 | for (int i = 0; i < recipe.Additions; i++) { | |
65 | if (recipe.Addition[i].Time == Time) { | |
66 | // Yes, update the name. | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
67 | //snprintf(recipe.Addition[i].Name, 63, "%s, %s", recipe.Addition[i].Name, Name); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
68 | strncat(recipe.Addition[i].Name, ", ", 63 - strlen(recipe.Addition[i].Name)); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
69 | strncat(recipe.Addition[i].Name, Name, 63 - strlen(recipe.Addition[i].Name)); |
0 | 70 | return; |
71 | } | |
72 | } | |
73 | ||
74 | // A new entry and we already have some. Add it and keep the list sorted. | |
75 | for (int i = 0; i < recipe.Additions; i++) { | |
76 | if (Time > recipe.Addition[i].Time) { | |
17
f3451031d6c6
Version 0.2.5. Removed debug console messages during recipe import. Removed old SyncDirs code to install /spiffs from the SD card since we now do this via the internet.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
77 | // Make room |
0 | 78 | for (int j = i; j < recipe.Additions; j++) { |
79 | sprintf(recipe.Addition[j+1].Name, "%s", recipe.Addition[j].Name); | |
80 | recipe.Addition[j+1].Type = recipe.Addition[j].Type; | |
81 | recipe.Addition[j+1].Time = recipe.Addition[j].Time; | |
82 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
83 | snprintf(recipe.Addition[i].Name, 63, "%s", Name); |
0 | 84 | recipe.Addition[i].Type = Type; |
85 | recipe.Addition[i].Time = Time; | |
86 | recipe.Additions++; | |
87 | return; | |
88 | } | |
89 | } | |
90 | ||
91 | // Just append. | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
92 | snprintf(recipe.Addition[recipe.Additions].Name, 63, "%s", Name); |
0 | 93 | recipe.Addition[recipe.Additions].Type = Type; |
94 | recipe.Addition[recipe.Additions].Time = Time; | |
95 | recipe.Additions++; | |
96 | } | |
97 | ||
98 | ||
99 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
100 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
101 | * @brief Reset the parser buffer. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
102 | */ |
0 | 103 | void reset_char_data_buffer (void) |
104 | { | |
105 | offs = 0; | |
106 | overflow = false; | |
107 | } | |
108 | ||
109 | ||
110 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
111 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
112 | * @brief Datahandler get bytes into the data buffer. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
113 | */ |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
114 | void char_data(void *userData, const XML_Char *s, int len) |
0 | 115 | { |
116 | if (!overflow) { | |
117 | if (len + offs >= sizeof(char_data_buffer) ) { | |
118 | overflow = true; | |
119 | } else { | |
120 | memcpy(char_data_buffer + offs, s, len); | |
121 | offs += len; | |
122 | } | |
123 | } | |
124 | } | |
125 | ||
126 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
127 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
128 | * @brief Process the XML parser data buffer. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
129 | */ |
0 | 130 | void process_char_data_buffer (void) |
131 | { | |
132 | bool allspace = true; | |
133 | ||
134 | if (offs > 0) { | |
135 | char_data_buffer[ offs ] = '\0'; | |
136 | ||
137 | /* | |
138 | * If all spaces and control characters, the data is invalid. | |
139 | */ | |
140 | for (int i = 0; i < strlen(char_data_buffer); i++) { | |
141 | if (char_data_buffer[i] > ' ') | |
142 | allspace = false; | |
143 | } | |
144 | if (allspace) | |
145 | return; | |
146 | ||
147 | if ((_xml_depth > 2) && (strcmp(_xml_element[0], "RECIPES") == 0) && (strcmp(_xml_element[1], "RECIPE") == 0)) { | |
148 | /* | |
149 | * We are in a recipe | |
150 | */ | |
151 | if ((_xml_depth == 3) && (strcmp("NAME", _xml_element[2]) == 0)) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
152 | recipe.Name[0] = '\0'; |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
153 | strncat(recipe.Name, char_data_buffer, 127); |
0 | 154 | } else if ((_xml_depth == 3) && (strcmp("BOIL_TIME", _xml_element[2]) == 0)) { |
155 | recipe.BoilTime = atoi(char_data_buffer); | |
156 | } else if ((_xml_depth == 5) && (strcmp("HOPS", _xml_element[2]) == 0) && (strcmp("HOP", _xml_element[3]) == 0)) { | |
157 | /* | |
158 | * Hops that are added during the boil. | |
159 | * But check for whirlpool hops too. | |
160 | */ | |
161 | if (strcmp("NAME", _xml_element[4]) == 0) { | |
56
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
162 | _xml_add_name[0] = '\0'; |
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
163 | strncat(_xml_add_name, char_data_buffer, 63); |
0 | 164 | } else if (strcmp("USE", _xml_element[4]) == 0) { |
165 | _xml_add_valid = (strcmp("Boil", char_data_buffer) == 0); // Only "Boil" is a valid hop | |
166 | if (strcmp("Aroma", char_data_buffer) == 0) { | |
167 | recipe.Whirlpool7 = 30; | |
168 | } | |
169 | } else if (strcmp("TIME", _xml_element[4]) == 0) { | |
170 | _xml_add_time = atoi(char_data_buffer); | |
171 | } | |
172 | } else if ((_xml_depth >= 3) && (strcmp("STYLE", _xml_element[2]) == 0)) { | |
173 | // Ignore | |
174 | } else if ((_xml_depth >= 3) && (strcmp("EQUIPMENT", _xml_element[2]) == 0)) { | |
175 | // Ignora | |
176 | } else if ((_xml_depth >= 3) && (strcmp("YEASTS", _xml_element[2]) == 0)) { | |
177 | // Ignore | |
178 | } else if ((_xml_depth >= 3) && (strcmp("WATERS", _xml_element[2]) == 0)) { | |
179 | // Ignore | |
180 | } else if ((_xml_depth == 5) && (strcmp("FERMENTABLES", _xml_element[2]) == 0) && (strcmp("FERMENTABLE", _xml_element[3]) == 0)) { | |
181 | /* | |
182 | * Fermentabes that must be added during the boil. | |
183 | */ | |
184 | if (strcmp("NAME", _xml_element[4]) == 0) { | |
56
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
185 | _xml_add_name[0] = '\0'; |
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
186 | strncat(_xml_add_name, char_data_buffer, 63); |
0 | 187 | } else if (strcmp("TYPE", _xml_element[4]) == 0) { |
188 | if ((strcmp("Sugar", char_data_buffer) == 0)/* || (strcmp("Adjunct", char_data_buffer) == 0)*/) { | |
189 | _xml_add_type = ADDITION_FERMENTABLE; | |
190 | _xml_add_time = 10; | |
191 | } else { | |
192 | _xml_add_type = -1; | |
193 | } | |
194 | } else if (strcmp("ADD_AFTER_BOIL", _xml_element[4]) == 0) { | |
195 | _xml_add_valid = (strcmp("FALSE", char_data_buffer) == 0); | |
196 | } | |
197 | } else if ((_xml_depth == 5) && (strcmp("MISCS", _xml_element[2]) == 0) && (strcmp("MISC", _xml_element[3]) == 0)) { | |
198 | /* | |
199 | * Check for Misc additions to add during the boil. | |
200 | */ | |
201 | if (strcmp("NAME", _xml_element[4]) == 0) { | |
56
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
202 | _xml_add_name[0] = '\0'; |
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
203 | strncat(_xml_add_name, char_data_buffer, 63); |
0 | 204 | } else if (strcmp("USE", _xml_element[4]) == 0) { |
205 | _xml_add_valid = (strcmp("Boil", char_data_buffer) == 0); // Only "Boil" is a valid hop. | |
206 | } else if (strcmp("TYPE", _xml_element[4]) == 0) { | |
207 | if (strcmp("Spice", char_data_buffer) == 0) | |
208 | _xml_add_type = ADDITION_SPICE; | |
209 | if (strcmp("Fining", char_data_buffer) == 0) | |
210 | _xml_add_type = ADDITION_FINING; | |
211 | if (strcmp("Herb", char_data_buffer) == 0) | |
212 | _xml_add_type = ADDITION_HERB; | |
213 | if (strcmp("Flavor", char_data_buffer) == 0) | |
214 | _xml_add_type = ADDITION_FLAVOR; | |
215 | if (strcmp("Other", char_data_buffer) == 0) | |
216 | _xml_add_type = ADDITION_OTHER; | |
217 | } else if (strcmp("TIME", _xml_element[4]) == 0) { | |
218 | _xml_add_time = atoi(char_data_buffer); | |
219 | } | |
220 | } else if ((_xml_depth >= 4) && (strcmp("MASH", _xml_element[2]) == 0)) { | |
221 | if ((_xml_depth >= 6) && (strcmp("MASH_STEP", _xml_element[4]) == 0)) { | |
222 | if (strcmp("NAME", _xml_element[5]) == 0) { | |
56
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
223 | _xml_add_name[0] = '\0'; |
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
224 | strncat(_xml_add_name, char_data_buffer, 63); |
0 | 225 | } else if (strcmp("TYPE", _xml_element[5]) == 0) { |
226 | // Temperature Infusion Decoction | |
227 | _xml_add_valid = (strcmp("Temperature", char_data_buffer) == 0); | |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
228 | if (strcmp("Infusion", char_data_buffer) == 0) |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
229 | _xml_add_type = MASHTYPE_INFUSION; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
230 | else if (strcmp("Temperature", char_data_buffer) == 0) |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
231 | _xml_add_type = MASHTYPE_TEMPERATURE; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
232 | else if (strcmp("Decoction", char_data_buffer) == 0) |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
233 | _xml_add_type = MASHTYPE_DECOCTION; |
0 | 234 | } else if (strcmp("STEP_TEMP", _xml_element[5]) == 0) { |
235 | _xml_add_temp = atof(char_data_buffer); | |
236 | } else if (strcmp("STEP_TIME", _xml_element[5]) == 0) { | |
237 | _xml_add_time = atoi(char_data_buffer); | |
238 | } else if (strcmp("RAMP_TIME", _xml_element[5]) == 0) { | |
239 | _xml_add_ramp = atoi(char_data_buffer); | |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
240 | } else if (strcmp("INFUSE_AMOUNT", _xml_element[5]) == 0) { |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
241 | _xml_add_amount = atof(char_data_buffer); |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
242 | } else if (strcmp("INFUSE_TEMP", _xml_element[5]) == 0) { |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
243 | _xml_add_infusion = atof(char_data_buffer); |
0 | 244 | } |
245 | } else if ((_xml_depth >= 4) && (strcmp("TUN_TEMP", _xml_element[3]) == 0)) { | |
246 | // Save this and check later if this is the strike temperature. | |
247 | _xml_tun_temp = atof(char_data_buffer); | |
248 | } else if ((_xml_depth >= 4) && (strcmp("SPARGE_TEMP", _xml_element[3]) == 0)) { | |
249 | recipe.SpargeTemp = atof(char_data_buffer); | |
250 | } | |
251 | } | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | ||
257 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
258 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
259 | * @brief Start new XML element. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
260 | * @param userData |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
261 | * @param name XML element name |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
262 | * @param attr XML element attribute |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
263 | */ |
0 | 264 | void startElement(void *userData, const char *name, const char **attr) |
265 | { | |
266 | sprintf(_xml_element[_xml_depth], "%s", name); | |
267 | _xml_depth++; | |
268 | process_char_data_buffer(); | |
269 | reset_char_data_buffer(); | |
270 | } | |
271 | ||
272 | ||
273 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
274 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
275 | * @brief End XML element |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
276 | * @param userData |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
277 | * @param name XML element name |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
278 | */ |
0 | 279 | void endElement(void *userData, const char *name) |
280 | { | |
281 | process_char_data_buffer(); | |
282 | reset_char_data_buffer(); | |
283 | if ((_xml_depth == 4) && (strcmp("HOP", _xml_element[3]) == 0)) { | |
284 | if (_xml_add_valid) { | |
285 | Addition_Add(_xml_add_name, ADDITION_HOP, _xml_add_time); | |
286 | } | |
287 | } | |
288 | if ((_xml_depth == 4) && (strcmp("FERMENTABLE", _xml_element[3]) == 0)) { | |
289 | if (_xml_add_valid && (_xml_add_type == ADDITION_FERMENTABLE)) { | |
290 | Addition_Add(_xml_add_name, _xml_add_type, _xml_add_time); | |
291 | } | |
292 | } | |
293 | if ((_xml_depth == 4) && (strcmp("MISC", _xml_element[3]) == 0)) { | |
294 | if (_xml_add_valid) { | |
295 | Addition_Add(_xml_add_name, _xml_add_type, _xml_add_time); | |
296 | } | |
297 | } | |
298 | if ((_xml_depth == 5) && (strcmp("MASH_STEP", _xml_element[4]) == 0)) { | |
299 | _xml_mashsteps++; | |
56
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
300 | recipe.MashStep[_xml_mashsteps].Name[0] = '\0'; |
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
301 | strncat(recipe.MashStep[_xml_mashsteps].Name, _xml_add_name, 31); |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
302 | recipe.MashStep[_xml_mashsteps].Type = _xml_add_type; |
0 | 303 | recipe.MashStep[_xml_mashsteps].Temperature = _xml_add_temp; |
304 | recipe.MashStep[_xml_mashsteps].Resttime = _xml_add_time; | |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
305 | recipe.MashStep[_xml_mashsteps].Ramptime = _xml_add_ramp; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
306 | if (_xml_add_type == MASHTYPE_INFUSION) { |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
307 | recipe.MashStep[_xml_mashsteps].Infusion_temp = _xml_add_infusion; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
308 | recipe.MashStep[_xml_mashsteps].Infusion_amount = _xml_add_amount; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
309 | } else { |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
310 | recipe.MashStep[_xml_mashsteps].Infusion_temp = 0.0; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
311 | recipe.MashStep[_xml_mashsteps].Infusion_amount = 0.0; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
312 | } |
0 | 313 | } |
314 | _xml_depth--; | |
315 | } | |
316 | ||
317 | ||
318 | ||
319 | int ParseRecipe(char *fn, char *code) | |
320 | { | |
321 | char buf[512]; | |
322 | ||
323 | memset(&recipe, 0, sizeof(recipe)); | |
324 | XML_Parser parser = XML_ParserCreate(NULL); | |
325 | ||
326 | int done; | |
327 | _xml_depth = 0; | |
328 | _xml_mashsteps = 0; | |
329 | _xml_tun_temp = 0.0; | |
330 | ||
331 | XML_SetElementHandler(parser, startElement, endElement); | |
332 | XML_SetCharacterDataHandler(parser, char_data); | |
333 | ||
334 | FILE *fp = fopen(fn, "r"); | |
335 | ||
336 | do { | |
337 | int len = (int)fread(buf, 1, sizeof(buf), fp); | |
338 | done = len < sizeof(buf); | |
339 | if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) { | |
340 | printf( "%s at line %5lu\n", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); | |
341 | return 1; | |
342 | } | |
343 | vTaskDelay(2 / portTICK_PERIOD_MS); | |
344 | } while (!done); | |
345 | ||
346 | XML_ParserFree(parser); | |
347 | fclose(fp); | |
348 | ||
349 | /* | |
350 | * Fix missing things. | |
351 | */ | |
352 | snprintf(recipe.Code, 31, "%s", code); | |
353 | // The code is created from the recipe filename. | |
354 | for (int i = 0; i < strlen(recipe.Code); i++) { | |
355 | if ((recipe.Code[i] == ' ') || (recipe.Code[i] == '.')) { | |
356 | recipe.Code[i] = '\0'; | |
357 | break; | |
358 | } | |
359 | } | |
360 | recipe.CoolTemp = 20.0; | |
361 | sprintf(recipe.MashStep[0].Name, "Mash-in"); | |
19 | 362 | if ((recipe.MashStep[1].Type == MASHTYPE_INFUSION) && (recipe.MashStep[1].Infusion_temp > 0.0)) { |
363 | /* If next (first original) step is infusion, take that temperature. */ | |
364 | recipe.MashStep[0].Temperature = recipe.MashStep[1].Infusion_temp; | |
365 | } else if (_xml_tun_temp > recipe.MashStep[1].Temperature) { | |
0 | 366 | recipe.MashStep[0].Temperature = _xml_tun_temp; |
367 | } else { | |
368 | recipe.MashStep[0].Temperature = recipe.MashStep[1].Temperature + 1.25; | |
369 | } | |
16 | 370 | recipe.MashStep[0].Resttime = recipe.MashStep[0].Ramptime = 1; |
371 | recipe.MashStep[0].Type = MASHTYPE_INFUSION; | |
372 | /* | |
373 | * Because we inserted the first infusion step and the next (original first) | |
374 | * step is infusion, change that one into temperature. | |
375 | */ | |
17
f3451031d6c6
Version 0.2.5. Removed debug console messages during recipe import. Removed old SyncDirs code to install /spiffs from the SD card since we now do this via the internet.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
376 | if (recipe.MashStep[1].Type == MASHTYPE_INFUSION) { |
16 | 377 | recipe.MashStep[1].Type = MASHTYPE_TEMPERATURE; |
17
f3451031d6c6
Version 0.2.5. Removed debug console messages during recipe import. Removed old SyncDirs code to install /spiffs from the SD card since we now do this via the internet.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
378 | recipe.MashStep[1].Infusion_temp = recipe.MashStep[1].Infusion_amount = 0.0; |
f3451031d6c6
Version 0.2.5. Removed debug console messages during recipe import. Removed old SyncDirs code to install /spiffs from the SD card since we now do this via the internet.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
379 | } |
0 | 380 | |
381 | if (! recipe.MashStep[7].Resttime) { | |
382 | // Move last mash step to position 7. | |
383 | for (int i = 6; i > 1; i--) { | |
384 | if (recipe.MashStep[i].Resttime) { | |
385 | // Got it, move. | |
386 | sprintf(recipe.MashStep[7].Name, "%s", recipe.MashStep[i].Name); | |
387 | recipe.MashStep[i].Name[0] = '\0'; | |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
388 | recipe.MashStep[7].Type = recipe.MashStep[i].Type; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
389 | recipe.MashStep[i].Type = 0; |
0 | 390 | recipe.MashStep[7].Temperature = recipe.MashStep[i].Temperature; |
391 | recipe.MashStep[i].Temperature = 0.0; | |
392 | recipe.MashStep[7].Resttime = recipe.MashStep[i].Resttime; | |
393 | recipe.MashStep[i].Resttime = 0; | |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
394 | recipe.MashStep[7].Ramptime = recipe.MashStep[i].Ramptime; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
395 | recipe.MashStep[i].Ramptime = 0; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
396 | recipe.MashStep[7].Infusion_temp = recipe.MashStep[i].Infusion_temp; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
397 | recipe.MashStep[i].Infusion_temp = 0.0; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
398 | recipe.MashStep[7].Infusion_amount = recipe.MashStep[i].Infusion_amount; |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
399 | recipe.MashStep[i].Infusion_amount = 0.0; |
0 | 400 | break; |
401 | } | |
402 | } | |
403 | } | |
404 | ||
17
f3451031d6c6
Version 0.2.5. Removed debug console messages during recipe import. Removed old SyncDirs code to install /spiffs from the SD card since we now do this via the internet.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
405 | #if 0 |
0 | 406 | printf("Recipe: %s\n", recipe.Name); |
407 | printf("Code : %s\n", recipe.Code); | |
408 | printf("Boil time %d minutes\n", recipe.BoilTime); | |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
409 | printf("n Stepname T temp time ramp inft infa\n"); |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
410 | printf("- ------------------------------ - ----- ---- ---- ----- -----\n"); |
0 | 411 | for (int i = 0; i < 8; i++) { |
412 | if (recipe.MashStep[i].Resttime) { | |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
413 | 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, |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
414 | recipe.MashStep[i].Resttime, recipe.MashStep[i].Ramptime, |
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
415 | recipe.MashStep[i].Infusion_temp, recipe.MashStep[i].Infusion_amount); |
0 | 416 | } |
417 | } | |
418 | printf("%d additions\n", recipe.Additions); | |
419 | printf("n Addition name t Tim\n"); | |
420 | printf("- --------------------------------------------------------------- - ---\n"); | |
421 | for (int i = 0; i < recipe.Additions; i++) { | |
422 | printf("%d %-63s %d %3d\n", i, recipe.Addition[i].Name, recipe.Addition[i].Type, recipe.Addition[i].Time); | |
423 | } | |
424 | printf("Cooltemp %5.2f\n", recipe.CoolTemp); | |
425 | if (recipe.Whirlpool9) | |
426 | printf("Whirlpool9 %d\n", recipe.Whirlpool9); | |
427 | if (recipe.Whirlpool7) | |
428 | printf("Whirlpool7 %d\n", recipe.Whirlpool7); | |
429 | if (recipe.Whirlpool6) | |
430 | printf("Whirlpool6 %d\n", recipe.Whirlpool6); | |
431 | if (recipe.Whirlpool2) | |
432 | printf("Whirlpool2 %d\n", recipe.Whirlpool2); | |
433 | printf("SpargeTemp %5.2f\n", recipe.SpargeTemp); | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
434 | #endif |
0 | 435 | |
436 | return 0; | |
437 | } | |
438 | ||
439 | ||
440 | ||
441 | /* | |
442 | * Recipes init function, only runs once a new screen is entered. | |
443 | */ | |
444 | void Recipes_Init(void) | |
445 | { | |
446 | FILE *f; | |
447 | DIR *dir; | |
448 | struct dirent *de; | |
449 | size_t bytes; | |
450 | uint8_t *dst; | |
451 | uint16_t y; | |
56
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
452 | char filename[288], newname[288]; |
0 | 453 | int rc; |
454 | ||
455 | switch (Main_Screen) { | |
456 | case MAIN_TOOLS_RECIPE: | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
457 | TopMessage((char *)"Recepten importeren"); |
0 | 458 | r_Imported = 0; |
459 | TFT_setFont(DEFAULT_FONT, NULL); | |
460 | y = 28; | |
461 | if ((dir = opendir("/sdcard/recipe"))) { | |
462 | de = readdir(dir); | |
463 | while (de) { | |
464 | if (strstr(de->d_name, ".xml") || strstr(de->d_name, ".XML")) { | |
465 | _fg = TFT_YELLOW; | |
466 | TFT_print(de->d_name, 2, y); | |
56
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
467 | snprintf(filename, 287, "/sdcard/recipe/%s", de->d_name); |
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
468 | snprintf(newname, 287, "/sdcard/recipe/%s", de->d_name); |
0 | 469 | newname[strlen(newname) -2] = 'o'; |
470 | newname[strlen(newname) -1] = 'k'; | |
471 | rc = ParseRecipe(filename, de->d_name); | |
472 | ESP_LOGI(TAG, "Recipe %s parsed, rc=%d", filename, rc); | |
473 | if (rc == 0) { | |
474 | append_recipe(); | |
475 | rename(filename, newname); | |
476 | _fg = TFT_GREEN; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
477 | TFT_print((char *)" Ok", LASTX, y); |
0 | 478 | } else { |
479 | _fg = TFT_RED; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
480 | TFT_print((char *)" Fout", LASTX, y); |
0 | 481 | } |
482 | r_Imported++; // Count them all | |
483 | y += 16; | |
484 | } | |
485 | de = readdir(dir); | |
486 | } | |
487 | closedir(dir); | |
488 | } | |
489 | ||
490 | f = fopen("/spiffs/etc/recipe.conf", "r"); | |
491 | dst = (uint8_t*)&recipe; | |
492 | r_Records = 0; | |
493 | while ((bytes = fread(dst, 1, sizeof(recipe), f))) { | |
494 | r_Records++; | |
495 | } | |
496 | fclose(f); | |
497 | // Load the default record. | |
498 | r_CurrentRec = config.RecipeRec; | |
499 | r_UpdateRec = true; | |
500 | break; | |
501 | ||
502 | case MAIN_TOOLS_RECIPE_EDIT: | |
503 | break; | |
504 | ||
505 | default: break; | |
506 | } | |
507 | } | |
508 | ||
509 | ||
510 | ||
511 | /* | |
512 | * Recipes management loop, non-blocking. | |
513 | */ | |
514 | void Recipes_Loop(void) | |
515 | { | |
516 | uint32_t crc1, crc2; | |
517 | uint8_t *dst; | |
518 | int mashsteps; | |
519 | uint16_t y; | |
56
756d1a63d129
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
520 | char tmp[64]; |
0 | 521 | float mintemp; |
522 | ||
523 | switch (Main_Screen) { | |
524 | case MAIN_TOOLS_RECIPE: | |
525 | if (r_Imported) { | |
526 | Buttons_Clear(); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
527 | Buttons_Add(135, 210, 50, 30, (char *)"Ok" , 0); |
0 | 528 | Buttons_Show(); |
529 | ||
530 | while (true) { | |
531 | if (Buttons_Scan() == 0) | |
532 | break; | |
533 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
534 | } | |
535 | Buttons_Clear(); | |
536 | r_Imported = 0; | |
537 | } | |
538 | if (r_UpdateRec) { | |
539 | _bg = TFT_BLACK; | |
540 | TFT_fillScreen(_bg); | |
541 | TFT_resetclipwin(); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
542 | TopMessage((char *)"Recepten"); |
0 | 543 | r_UpdateRec = false; |
544 | read_recipe(r_CurrentRec); | |
545 | TFT_setFont(DEFAULT_FONT, NULL); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
546 | ShowText(2, 28, (char *)"Naam", recipe.Name); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
547 | ShowText(2, 44, (char *)"Code", recipe.Code); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
548 | ShowInteger(162, 44, (char *)"Record", NULL, r_CurrentRec); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
549 | ShowInteger(2, 60, (char *)"Kooktijd", (char *)" min", recipe.BoilTime); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
550 | ShowFloat(162, 60, (char *)"Koel tot", (char *)" C", recipe.CoolTemp, 2); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
551 | ShowFloat(2, 76, (char *)"Maisch in", (char *)" C", recipe.MashStep[0].Temperature, 2); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
552 | ShowFloat(162, 76, (char *)"Spoelwater", (char *)" C", recipe.SpargeTemp, 2); |
0 | 553 | y = 92; |
554 | _fg = TFT_WHITE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
555 | TFT_print((char *)"Maisch stap", 2, y); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
556 | TFT_print((char *)"T", 200, y); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
557 | TFT_print((char *)"Temp.", 220, y); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
558 | TFT_print((char *)"Rust", 280, y); |
0 | 559 | _fg = TFT_YELLOW; |
560 | y += 16; | |
561 | for (int i = 1; i < 8; i++) { | |
562 | if (recipe.MashStep[i].Resttime) { | |
563 | TFT_print(recipe.MashStep[i].Name, 2, y); | |
19 | 564 | strcpy(tmp, mashTypes[recipe.MashStep[i].Type]); |
565 | tmp[1] = '\0'; | |
566 | TFT_print(tmp, 200, y); | |
0 | 567 | sprintf(tmp, "%.2f", recipe.MashStep[i].Temperature); |
16 | 568 | TFT_print(tmp, 220, y); |
569 | sprintf(tmp, "%2d m", recipe.MashStep[i].Resttime); | |
570 | TFT_print(tmp, 280, y); | |
0 | 571 | y += 16; |
572 | } | |
573 | } | |
574 | if (recipe.Additions) { | |
575 | _fg = TFT_YELLOW; | |
576 | sprintf(tmp, "%d ", recipe.Additions); | |
577 | TFT_print(tmp, 2, y); | |
578 | _fg = TFT_WHITE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
579 | TFT_print((char *)"toevoegingen om", LASTX, y); |
0 | 580 | _fg = TFT_YELLOW; |
581 | for (int i = 1; i <= recipe.Additions; i++) { | |
582 | sprintf(tmp, " %d", recipe.Addition[i-1].Time); | |
583 | TFT_print(tmp, LASTX, y); | |
584 | } | |
585 | _fg = TFT_WHITE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
586 | TFT_print((char *)" minuten", LASTX, y); |
0 | 587 | } else { |
588 | _fg = TFT_WHITE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
589 | TFT_print((char *)"Geen hop toevoegingen.", 2, y); |
0 | 590 | } |
591 | y += 16; | |
592 | if (recipe.Whirlpool9 || recipe.Whirlpool7 || recipe.Whirlpool6 || recipe.Whirlpool2) { | |
593 | _fg = TFT_WHITE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
594 | TFT_print((char *)"Whirlpool ", 2, y); |
0 | 595 | _fg = TFT_YELLOW; |
596 | if (recipe.Whirlpool9) | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
597 | TFT_print((char *)"88+ ", LASTX, y); |
0 | 598 | if (recipe.Whirlpool7) |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
599 | TFT_print((char *)"71+ ", LASTX, y); |
0 | 600 | if (recipe.Whirlpool6) |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
601 | TFT_print((char *)"60+ ", LASTX, y); |
0 | 602 | if (recipe.Whirlpool2) |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
603 | TFT_print((char *)"koud", LASTX, y); |
0 | 604 | } |
605 | ||
606 | Buttons_Clear(); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
607 | Buttons_Add( 0, 210, 45, 30, (char *)"Ok" , 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
608 | Buttons_Add( 46, 210, 45, 30, (char *)"+" , 1); |
0 | 609 | if (r_CurrentRec != config.RecipeRec) |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
610 | Buttons_Add( 92, 210, 45, 30, (char *)"-", 2); |
0 | 611 | else |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
612 | Buttons_Add( 92, 210, 45, 30, (char *)"" , 2); |
0 | 613 | if (r_CurrentRec > 1) |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
614 | Buttons_Add(138, 210, 45, 30, (char *)"<", 3); |
0 | 615 | else |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
616 | Buttons_Add(138, 210, 45, 30, (char *)"", 3); |
0 | 617 | if (r_CurrentRec < r_Records) |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
618 | Buttons_Add(184, 210, 45, 30, (char *)">", 4); |
0 | 619 | else |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
620 | Buttons_Add(184, 210, 45, 30, (char *)"", 4); |
0 | 621 | if (r_CurrentRec != config.RecipeRec) |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
622 | Buttons_Add(230, 210, 45, 30, (char *)"Std", 5); |
0 | 623 | else |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
624 | Buttons_Add(230, 210, 45, 30, (char *)"", 5); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
625 | Buttons_Add(276, 210, 45, 30, (char *)"Ed" , 6); |
0 | 626 | Buttons[0].dark = true; |
627 | Buttons_Show(); | |
628 | } /* if (r_UpdateRec) */ | |
629 | switch (Buttons_Scan()) { | |
630 | case 0: Main_Screen = MAIN_TOOLS; | |
631 | break; | |
632 | ||
633 | case 1: memset(&recipe, 0, sizeof(recipe)); | |
634 | recipe.Version = 1; | |
19 | 635 | for (int i = 1; i < 8; i++) |
636 | recipe.MashStep[i].Type = MASHTYPE_TEMPERATURE; | |
0 | 637 | sprintf(recipe.Name, "Recipe %d", r_Records + 1); |
638 | sprintf(recipe.Code, "00%d", r_Records + 1); | |
639 | sprintf(recipe.MashStep[0].Name, "Mash-in"); | |
16 | 640 | recipe.MashStep[0].Type = MASHTYPE_INFUSION; |
641 | recipe.MashStep[0].Temperature = recipe.MashStep[0].Infusion_temp = 67.5; | |
642 | recipe.MashStep[0].Infusion_amount = 15.0; | |
0 | 643 | recipe.MashStep[0].Resttime = 1; |
16 | 644 | recipe.MashStep[0].Ramptime = 1; |
0 | 645 | sprintf(recipe.MashStep[1].Name, "Mash"); |
646 | recipe.MashStep[1].Temperature = 67.0; | |
647 | recipe.MashStep[1].Resttime = 75; | |
16 | 648 | recipe.MashStep[1].Ramptime = 1; |
0 | 649 | sprintf(recipe.MashStep[7].Name, "Mash-out"); |
650 | recipe.MashStep[7].Temperature = 78.0; | |
651 | recipe.MashStep[7].Resttime = 5; | |
16 | 652 | recipe.MashStep[7].Ramptime = 11; |
0 | 653 | recipe.BoilTime = 60; |
654 | recipe.Additions = 2; | |
16 | 655 | sprintf(recipe.Addition[0].Name, "Bitterhop"); |
0 | 656 | recipe.Addition[0].Time = 60; |
657 | recipe.Addition[0].Type = ADDITION_HOP; | |
16 | 658 | sprintf(recipe.Addition[1].Name, "Aromahop"); |
0 | 659 | recipe.Addition[1].Time = 10; |
660 | recipe.Addition[1].Type = ADDITION_HOP; | |
661 | recipe.CoolTemp = 20.0; | |
662 | recipe.Whirlpool9 = 0; | |
663 | recipe.Whirlpool7 = 0; | |
664 | recipe.Whirlpool6 = 0; | |
665 | recipe.Whirlpool2 = 0; | |
666 | recipe.SpargeTemp = 85.0; | |
667 | append_recipe(); | |
668 | r_Records++; | |
669 | r_CurrentRec = r_Records; | |
670 | r_UpdateRec = true; | |
6
e84200edc852
Updated esp-ide. Removed VNC server corre encoding because no clients would use it. Enabled WiFi error logmessages. Write runtime record is now debug logging. Removed recipe.Record number, not usefull and was wrong too. Removed console print of json log data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
671 | ESP_LOGI(TAG, "New recipe record %d", r_CurrentRec); |
0 | 672 | break; |
673 | ||
674 | case 2: if ((r_CurrentRec != config.RecipeRec) && (r_Records > 1)) { | |
675 | delete_recipe(r_CurrentRec); | |
676 | r_Records--; | |
677 | if (r_CurrentRec > r_Records) | |
678 | r_CurrentRec = r_Records; | |
679 | r_UpdateRec = true; | |
680 | } | |
681 | break; | |
682 | ||
683 | case 3: if (r_CurrentRec > 1) { | |
684 | r_CurrentRec--; | |
685 | r_UpdateRec = true; | |
686 | } | |
687 | break; | |
688 | ||
689 | case 4: if (r_CurrentRec < r_Records) { | |
690 | r_CurrentRec++; | |
691 | r_UpdateRec = true; | |
692 | } | |
693 | break; | |
694 | ||
695 | case 5: if (r_CurrentRec != config.RecipeRec) { | |
696 | config.RecipeRec = r_CurrentRec; | |
697 | write_config(); | |
698 | r_UpdateRec = true; | |
699 | ESP_LOGI(TAG, "Recipe %d `%s' set as default", r_CurrentRec, recipe.Name); | |
700 | } | |
701 | break; | |
702 | ||
703 | case 6: Main_Screen = MAIN_TOOLS_RECIPE_EDIT; | |
704 | break; | |
705 | ||
706 | default: break; | |
707 | } | |
708 | break; | |
709 | ||
710 | case MAIN_TOOLS_RECIPE_EDIT: | |
711 | dst = (uint8_t*)&recipe; | |
712 | crc1 = crc32_le(0, dst, sizeof(recipe)); | |
713 | ||
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
714 | EditText((char *)"Naam", recipe.Name, 31); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
715 | EditText((char *)"Code", recipe.Code, 31); |
0 | 716 | mashsteps = 0; |
717 | for (int i = 1; i < 7; i++) { | |
718 | if (recipe.MashStep[i].Resttime) | |
719 | mashsteps++; | |
720 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
721 | EditInt((char *)"Maisch stappen", &mashsteps, 1, 6); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
722 | EditFloat((char *)"Inmaisch temperatuur", &recipe.MashStep[0].Temperature, 38, 74, 2); |
0 | 723 | // Round to 0.25 values |
724 | recipe.MashStep[0].Temperature = ((int)(recipe.MashStep[0].Temperature * 4)) / 4.0; | |
725 | for (int i = 1; i <= mashsteps; i++) { | |
726 | sprintf(tmp, "Maisch stap %d naam", i); | |
727 | EditText(tmp, recipe.MashStep[i].Name, 31); | |
19 | 728 | EditMashType(&recipe.MashStep[i].Type); |
0 | 729 | sprintf(tmp, "Maisch stap %d temperatuur", i); |
730 | if (i == 1) | |
731 | mintemp = recipe.MashStep[0].Temperature - 5; | |
732 | else | |
733 | mintemp = recipe.MashStep[i - 1].Temperature; | |
3 | 734 | EditFloat(tmp, &recipe.MashStep[i].Temperature, mintemp, 74, 2); |
0 | 735 | recipe.MashStep[i].Temperature = ((int)(recipe.MashStep[i].Temperature * 4)) / 4.0; |
736 | sprintf(tmp, "Maisch stap %d rusttijd in minuten", i); | |
737 | EditUint16(tmp, &recipe.MashStep[i].Resttime, 1, 480); | |
738 | if (i == 1) { | |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
739 | recipe.MashStep[i].Ramptime = 1; |
0 | 740 | } else { |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
741 | recipe.MashStep[i].Ramptime = (int)(recipe.MashStep[i].Temperature - recipe.MashStep[i - 1].Temperature); |
0 | 742 | } |
19 | 743 | if (recipe.MashStep[i].Type == MASHTYPE_INFUSION) { |
744 | sprintf(tmp, "Stap %d infusie temperatuur", i); | |
745 | mintemp = recipe.MashStep[i].Temperature; | |
746 | EditFloat(tmp, &recipe.MashStep[i].Infusion_temp, mintemp, 100, 2); | |
747 | sprintf(tmp, "Stap %d infusie volume", i); | |
748 | EditFloat(tmp, &recipe.MashStep[i].Infusion_amount, 0.5, 1000.0, 2); | |
749 | } else { | |
750 | recipe.MashStep[i].Infusion_temp = recipe.MashStep[i].Infusion_amount = 0.0; | |
751 | } | |
0 | 752 | } |
753 | mintemp = recipe.MashStep[mashsteps].Temperature; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
754 | EditFloat((char *)"Uitmaischen temperatuur", &recipe.MashStep[7].Temperature, mintemp, 80, 2); |
0 | 755 | recipe.MashStep[7].Temperature = ((int)(recipe.MashStep[7].Temperature * 4)) / 4.0; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
756 | EditUint16((char *)"Uitmaischen tijd in minuten", &recipe.MashStep[7].Resttime, 1, 15); |
15
34b1eb93e71a
Added extra mash step fields for infusion steps. Added these fields in recipe import too.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
757 | recipe.MashStep[7].Ramptime = (int)(recipe.MashStep[7].Temperature - recipe.MashStep[mashsteps].Temperature); |
0 | 758 | // Zero any higher steps to diable them. |
759 | for (int i = (mashsteps + 1); i < 7; i++) | |
760 | recipe.MashStep[i].Resttime = 0; | |
761 | ||
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
762 | EditUint16((char *)"Kook tijd in minuten", &recipe.BoilTime, 3, 480); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
763 | EditUint8((char *)"Hop/kruiden toevoegingen", &recipe.Additions, 1, 10); |
0 | 764 | for (uint8_t i = 0; i < recipe.Additions; i++) { |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
765 | sprintf(tmp, "Toevoeging %d naam", i+1); |
0 | 766 | if (strlen(recipe.Addition[i].Name) == 00) { |
767 | sprintf(recipe.Addition[i].Name, "Hop %d", (int)i+1); | |
768 | } | |
769 | EditText(tmp, recipe.Addition[i].Name, 40); | |
770 | sprintf(tmp, "Toevoeging %d tijd", i+1); | |
771 | if (i == 0) { | |
772 | EditUint16(tmp, &recipe.Addition[i].Time, 0, recipe.BoilTime); | |
773 | } else { | |
774 | EditUint16(tmp, &recipe.Addition[i].Time, 0, recipe.Addition[i-1].Time - 1); | |
775 | } | |
776 | recipe.Addition[i].Type = ADDITION_HOP; | |
777 | } | |
778 | ||
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
779 | EditFloat((char *)"Koel temperatuur", &recipe.CoolTemp, 10, 30, 2); |
0 | 780 | recipe.CoolTemp = ((int)(recipe.CoolTemp * 4)) / 4.0; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
781 | EditFloat((char *)"Spoelwater temperatuur", &recipe.SpargeTemp, 75, 98, 2); |
0 | 782 | recipe.SpargeTemp = ((int)(recipe.SpargeTemp * 4)) / 4.0; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
783 | EditUint16((char *)"Whirlpool 88..100 graden, 0 = niet", &recipe.Whirlpool9, 0, 120); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
784 | EditUint16((char *)"Whirlpool 71..77 graden, 0 = niet", &recipe.Whirlpool7, 0, 120); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
785 | EditUint16((char *)"Whirlpool 60..66 graden, 0 = niet", &recipe.Whirlpool6, 0, 120); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
786 | EditUint16((char *)"Whirlpool koud, 0 = niet", &recipe.Whirlpool2, 0, 120); |
0 | 787 | |
788 | crc2 = crc32_le(0, dst, sizeof(recipe)); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
19
diff
changeset
|
789 | if ((crc1 != crc2) && Confirm((char *)"Gewijzigd, opslaan?", (char *)"Ja", (char *)"Nee")) { |
6
e84200edc852
Updated esp-ide. Removed VNC server corre encoding because no clients would use it. Enabled WiFi error logmessages. Write runtime record is now debug logging. Removed recipe.Record number, not usefull and was wrong too. Removed console print of json log data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
790 | write_recipe(r_CurrentRec); |
0 | 791 | } |
792 | Main_Screen = MAIN_TOOLS_RECIPE; | |
793 | break; | |
794 | ||
795 | default: break; | |
796 | } | |
797 | } | |
798 | ||
799 |