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