Wed, 24 Oct 2018 11:55:39 +0200
Removed old logfiles
0 | 1 | /** |
2 | * @file setup.c | |
3 | * @brief Setup functions. | |
4 | */ | |
5 | ||
6 | #include "config.h" | |
7 | ||
8 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
9 | extern sButton Buttons[MAXBUTTONS]; |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
10 | extern int Main_Screen; |
0 | 11 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
12 | bool UpdateRec = false; ///< Update record flag |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
13 | int CurrentRec = 1; ///< Current record |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
14 | int Records = 1; ///< Total records. |
0 | 15 | |
16 | ||
17 | static const char *TAG = "setup"; | |
18 | ||
19 | ||
20 | ||
21 | /* | |
22 | * Setup init function that only runs once a new screen | |
23 | * is entered. | |
24 | */ | |
25 | void Setup_Init(void) | |
26 | { | |
27 | FILE *f; | |
28 | size_t bytes; | |
29 | uint8_t *dst; | |
30 | ||
31 | switch (Main_Screen) { | |
32 | ||
33 | case MAIN_TOOLS_SETUP: | |
34 | TopMessage("Setup menu"); | |
35 | Buttons_Add( 20, 40,120, 40, "Config", 0); | |
36 | Buttons_Add(180, 40,120, 40, "Apparatuur", 1); | |
37 | Buttons_Add( 20,120,120, 40, "WiFi", 2); | |
38 | Buttons_Add(180,120,120, 40, "Calibratie", 3); | |
39 | Buttons_Add(130, 200, 60, 40, "Ok", 4); | |
40 | Buttons[4].dark = true; | |
41 | Buttons_Show(); | |
42 | break; | |
43 | ||
44 | case MAIN_TOOLS_SETUP_CONFIG: | |
45 | _bg = TFT_BLACK; | |
46 | TopMessage("Configuratie"); | |
47 | TFT_setFont(DEFAULT_FONT, NULL); | |
48 | ShowFloat(2, 28, "Kook temp.", "C", config.BoilTemperature, 2); | |
49 | ShowBool(2, 44, "Vraag mout storten", config.AskAdd); | |
50 | ShowBool(2, 60, "Vraag mout verwijderen", config.AskRemove); | |
51 | ShowBool(2, 76, "Vraag Jodium proef", config.AskIodine); | |
52 | ShowInteger(2, 92, "Jodiumtest wachttijd", " min.", config.IodineTime); | |
53 | ShowText(2, 108, "Hostnaam", config.hostname); | |
54 | ShowText(2, 124, "AP SSID", config.ap_ssid); | |
55 | ShowText(2, 140, "AP pwd", config.ap_pwd); | |
56 | ShowInteger(2, 156, "AP kanaal", NULL, config.ap_channel); | |
57 | ShowBool(2, 172, "AP SSID verborgen", config.ap_ssid_hidden); | |
58 | Buttons_Clear(); | |
59 | Buttons_Add( 0, 210, 45, 30, "Ok" , 0); | |
60 | Buttons_Add(276, 210, 45, 30, "Ed" , 1); | |
61 | Buttons[0].dark = true; | |
62 | Buttons_Show(); | |
63 | break; | |
64 | ||
65 | case MAIN_TOOLS_SETUP_CO_EDIT: | |
66 | break; | |
67 | ||
68 | case MAIN_TOOLS_SETUP_EQUIPMENT: | |
69 | TopMessage("Apparatuur"); | |
70 | f = fopen("/spiffs/etc/equipments.conf", "r"); | |
71 | dst = (uint8_t*)&equipment; | |
72 | Records = 0; | |
73 | while ((bytes = fread(dst, 1, sizeof(equipment), f))) { | |
74 | Records++; | |
75 | } | |
76 | fclose(f); | |
77 | // Load the default record. | |
78 | CurrentRec = config.EquipmentRec; | |
79 | UpdateRec = true; | |
80 | break; | |
81 | ||
82 | case MAIN_TOOLS_SETUP_EQ_EDIT: | |
83 | break; | |
84 | ||
85 | case MAIN_TOOLS_SETUP_CALIBRATION: | |
86 | Calibration_Init(); | |
87 | break; | |
88 | ||
89 | default: | |
90 | break; | |
91 | } | |
92 | } | |
93 | ||
94 | ||
95 | ||
96 | /* | |
97 | * Setup loop screens, non-blocking. | |
98 | */ | |
99 | void Setup_Loop(void) | |
100 | { | |
101 | uint32_t crc1, crc2; | |
102 | uint8_t *dst; | |
103 | ||
104 | switch (Main_Screen) { | |
105 | ||
106 | case MAIN_TOOLS_SETUP: | |
107 | switch (Buttons_Scan()) { | |
108 | case 0: Main_Screen = MAIN_TOOLS_SETUP_CONFIG; | |
109 | break; | |
110 | ||
111 | case 1: Main_Screen = MAIN_TOOLS_SETUP_EQUIPMENT; | |
112 | break; | |
113 | ||
114 | case 2: Main_Screen = MAIN_TOOLS_SETUP_WIFI; | |
115 | break; | |
116 | ||
117 | case 3: Main_Screen = MAIN_TOOLS_SETUP_CALIBRATION; | |
118 | break; | |
119 | ||
120 | case 4: Main_Screen = MAIN_TOOLS; | |
121 | break; | |
122 | ||
123 | default: break; | |
124 | } | |
125 | break; | |
126 | ||
127 | case MAIN_TOOLS_SETUP_CONFIG: | |
128 | switch (Buttons_Scan()) { | |
129 | case 0: Main_Screen = MAIN_TOOLS_SETUP; | |
130 | break; | |
131 | ||
132 | case 1: Main_Screen = MAIN_TOOLS_SETUP_CO_EDIT; | |
133 | break; | |
134 | ||
135 | default: break; | |
136 | } | |
137 | break; | |
138 | ||
139 | case MAIN_TOOLS_SETUP_CO_EDIT: | |
140 | dst = (uint8_t*)&config; | |
141 | crc1 = crc32_le(0, dst, sizeof(config)); | |
142 | EditFloat("Kook temperatuur", &config.BoilTemperature, 80, 105, 2); | |
143 | // Round to 0.25 degrees | |
144 | config.BoilTemperature = ((int)(config.BoilTemperature * 4)) / 4.0; | |
145 | EditBool("Vraag mout storten", &config.AskAdd); | |
146 | EditBool("Vraag mout verwijderen", &config.AskRemove); | |
147 | EditBool("Vraag Jodium proef", &config.AskIodine); | |
148 | EditUint8("Jodium test wachttijd", &config.IodineTime, 0, 120); | |
149 | EditText("DHCP hostnaam", config.hostname, 31); | |
150 | EditText("AP SSID", config.ap_ssid, 31); | |
151 | EditTextMin("AP password", config.ap_pwd, 40, 8); | |
152 | EditUint8("AP kanaal", &config.ap_channel, 1, 14); | |
153 | bool hidden = config.ap_ssid_hidden; | |
154 | EditBool("AP SSID verborgen", &hidden); | |
155 | config.ap_ssid_hidden = (uint8_t)hidden; | |
156 | ||
157 | crc2 = crc32_le(0, dst, sizeof(config)); | |
158 | if ((crc1 != crc2) && Confirm("Gewijzigd, opslaan?", "Ja", "Nee")) { | |
159 | write_config(); | |
160 | } else { | |
161 | read_config(); | |
162 | } | |
163 | Main_Screen = MAIN_TOOLS_SETUP_CONFIG; | |
164 | break; | |
165 | ||
166 | case MAIN_TOOLS_SETUP_EQUIPMENT: | |
167 | if (UpdateRec) { | |
168 | _bg = TFT_BLACK; | |
169 | TFT_fillScreen(_bg); | |
170 | TFT_resetclipwin(); | |
171 | TopMessage("Apparatuur"); | |
172 | UpdateRec = false; | |
173 | read_equipment(CurrentRec); | |
174 | TFT_setFont(DEFAULT_FONT, NULL); | |
175 | ShowText(2, 28, "Naam", equipment.Name); | |
176 | ShowInteger( 2, 44, "Kook vermogen", "%", equipment.BoilPower); | |
177 | ShowInteger(161, 44, "Maisch verm.", "%", equipment.MashPower); | |
178 | ShowInteger( 2, 60, "Pomp cyclus", "m", equipment.PumpCycle); | |
179 | ShowInteger(161, 60, "Pomp rust", "m", equipment.PumpRest); | |
180 | ShowBool( 2, 76, "Pomp opwarmen", equipment.PumpPreMash); | |
181 | ShowBool(161, 76, "Pomp maischen", equipment.PumpOnMash); | |
182 | ShowBool( 2, 92, "Pomp uitmaischen", equipment.PumpMashOut); | |
183 | ShowBool(161, 92, "Pomp bij koken", equipment.PumpOnBoil); | |
184 | ShowInteger(2, 108, "Pomp maxtemp.", "C", equipment.PumpMaxTemp); | |
185 | ShowBool(161, 108, "PID bij mout weg", equipment.PIDPipe); | |
186 | ShowSSR2(2, 124, equipment.SSR2); | |
187 | ShowFloat(161, 124, "Spoelwater", NULL, equipment.TempHLT, 2); | |
188 | ShowDouble(2, 140, "PID P", NULL, equipment.PID_kP, 3); | |
189 | ShowBool(161, 140, "PID klassiek", equipment.PID_POn); | |
190 | ShowDouble(2, 156, "PID I", NULL, equipment.PID_kI, 3); | |
191 | ShowInteger(161, 156, "Sample tijd", "mS", equipment.SampleTime); | |
192 | ShowDouble(2, 172, "PID D", NULL, equipment.PID_kD, 3); | |
193 | Buttons_Clear(); | |
194 | Buttons_Add( 0, 210, 45, 30, "Ok" , 0); | |
195 | Buttons_Add( 46, 210, 45, 30, "+" , 1); | |
196 | if (CurrentRec != config.EquipmentRec) | |
197 | Buttons_Add( 92, 210, 45, 30, "-", 2); | |
198 | else | |
199 | Buttons_Add( 92, 210, 45, 30, "" , 2); | |
200 | if (CurrentRec > 1) | |
201 | Buttons_Add(138, 210, 45, 30, "<", 3); | |
202 | else | |
203 | Buttons_Add(138, 210, 45, 30, "", 3); | |
204 | if (CurrentRec < Records) | |
205 | Buttons_Add(184, 210, 45, 30, ">", 4); | |
206 | else | |
207 | Buttons_Add(184, 210, 45, 30, "", 4); | |
208 | if (CurrentRec != config.EquipmentRec) | |
209 | Buttons_Add(230, 210, 45, 30, "Std", 5); | |
210 | else | |
211 | Buttons_Add(230, 210, 45, 30, "", 5); | |
212 | Buttons_Add(276, 210, 45, 30, "Ed" , 6); | |
213 | Buttons[0].dark = true; | |
214 | Buttons_Show(); | |
215 | } | |
216 | switch (Buttons_Scan()) { | |
217 | case 0: Main_Screen = MAIN_TOOLS_SETUP; | |
218 | break; | |
219 | ||
220 | case 1: memset(&equipment, 0, sizeof(equipment)); | |
221 | equipment.Version = 1; | |
222 | equipment.Record = Records + 1; | |
223 | sprintf(equipment.Name, "new eq %d", Records + 1); | |
224 | equipment.BoilPower = 80; | |
225 | equipment.MashPower = 100; | |
226 | equipment.PumpCycle = 8; | |
227 | equipment.PumpRest = 2; | |
228 | equipment.PumpPreMash = true; | |
229 | equipment.PumpOnMash = true; | |
230 | equipment.PumpMashOut = true; | |
231 | equipment.PumpOnBoil = false; | |
232 | equipment.PumpMaxTemp = 80; | |
233 | equipment.PIDPipe = true; | |
234 | equipment.SSR2 = 0; | |
235 | equipment.TempHLT = 85.0; | |
236 | equipment.PID_kP = 150.0; | |
237 | equipment.PID_kI = 1.5; | |
238 | equipment.PID_kD = 15000.0; | |
239 | equipment.PID_POn = PID_P_ON_E; | |
240 | equipment.SampleTime = 5000; | |
241 | append_equipment(); | |
242 | Records++; | |
243 | CurrentRec = Records; | |
244 | UpdateRec = true; | |
245 | ESP_LOGI(TAG, "New equipment record %d", equipment.Record); | |
246 | break; | |
247 | ||
248 | case 2: if ((CurrentRec != config.EquipmentRec) && (Records > 1)) { | |
249 | delete_equipment(CurrentRec); | |
250 | Records--; | |
251 | if (CurrentRec > Records) | |
252 | CurrentRec = Records; | |
253 | UpdateRec = true; | |
254 | } | |
255 | break; | |
256 | ||
257 | case 3: if (CurrentRec > 1) { | |
258 | CurrentRec--; | |
259 | UpdateRec = true; | |
260 | } | |
261 | break; | |
262 | ||
263 | case 4: if (CurrentRec < Records) { | |
264 | CurrentRec++; | |
265 | UpdateRec = true; | |
266 | } | |
267 | break; | |
268 | ||
269 | case 5: if (CurrentRec != config.EquipmentRec) { | |
270 | config.EquipmentRec = CurrentRec; | |
271 | write_config(); | |
272 | UpdateRec = true; | |
273 | ESP_LOGI(TAG, "Equipment %d `%s' set as default", CurrentRec, equipment.Name); | |
274 | } | |
275 | break; | |
276 | ||
277 | case 6: Main_Screen = MAIN_TOOLS_SETUP_EQ_EDIT; | |
278 | break; | |
279 | ||
280 | default: break; | |
281 | } | |
282 | break; | |
283 | ||
284 | case MAIN_TOOLS_SETUP_EQ_EDIT: | |
285 | dst = (uint8_t*)&equipment; | |
286 | crc1 = crc32_le(0, dst, sizeof(equipment)); | |
287 | EditText("Naam", equipment.Name, 31); | |
288 | EditInt("Kook vermogen in %", &equipment.BoilPower, 0, 100); | |
289 | EditInt("Maisch vermogen in %", &equipment.MashPower, 0, 100); | |
290 | EditInt("Pomp cyclus minuten", &equipment.PumpCycle, 5, 15); | |
291 | EditInt("Pomp rust minuten", &equipment.PumpRest, 0, 5); | |
292 | EditBool("Pomp bij opwarmen", &equipment.PumpPreMash); | |
293 | EditBool("Pomp bij maischen", &equipment.PumpOnMash); | |
294 | EditBool("Pomp bij uitmasichen", &equipment.PumpMashOut); | |
295 | EditBool("Pomp tijdens koken", &equipment.PumpOnBoil); | |
296 | EditInt("Pomp max. temperatuur", &equipment.PumpMaxTemp, 60, 105); | |
297 | EditBool("PID by mout verwijderen", &equipment.PIDPipe); | |
298 | EditSSR2(&equipment.SSR2); | |
299 | EditFloat("Spoelwater temp", &equipment.TempHLT, 75, 98, 2); | |
300 | // Round to 0.25 values. | |
301 | equipment.TempHLT = ((int)(equipment.TempHLT * 4)) / 4.0; | |
302 | EditBool("PID klassiek", &equipment.PID_POn); | |
303 | EditDouble("PID P", &equipment.PID_kP, 20, 2000, 3); | |
304 | EditDouble("PID I", &equipment.PID_kI, 0, 100, 3); | |
305 | EditDouble("PID D", &equipment.PID_kD, 0, 50000, 3); | |
306 | EditInt("Sample tijd in mS", &equipment.SampleTime, 1000, 20000); | |
307 | // Round to 250 mSec units. | |
308 | equipment.SampleTime = ((int)(equipment.SampleTime / 250)) * 250; | |
309 | ||
310 | crc2 = crc32_le(0, dst, sizeof(equipment)); | |
311 | if ((crc1 != crc2) && Confirm("Gewijzigd, opslaan?", "Ja", "Nee")) { | |
312 | write_equipment(equipment.Record); | |
313 | } | |
314 | Main_Screen = MAIN_TOOLS_SETUP_EQUIPMENT; | |
315 | break; | |
316 | ||
317 | case MAIN_TOOLS_SETUP_WIFI: | |
318 | break; | |
319 | ||
320 | case MAIN_TOOLS_SETUP_CALIBRATION: | |
321 | Calibration_Loop(); | |
322 | Main_Screen = MAIN_TOOLS_SETUP; | |
323 | break; | |
324 | ||
325 | default: | |
326 | break; | |
327 | } | |
328 | } | |
329 |