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