Tue, 02 Jul 2019 12:10:23 +0200
Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen.
0 | 1 | /** |
2 | * @file task_tft.c | |
4 | 3 | * @brief BrewBoard TFT and Touch screen driver for a 320x240 ILI9341 based display. |
4 | * But because the application is controlled using the touch screen, all the | |
5 | * processing of menus is also found here. | |
6 | * It's the first started task, but it does nothing until the Main_Screen | |
7 | * variable is set. | |
0 | 8 | */ |
9 | ||
10 | #include "config.h" | |
11 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
12 | spi_lobo_device_handle_t spi; ///< TFT screen SPI handler |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
13 | spi_lobo_device_handle_t tsspi = NULL; ///< Touchscreen SPI handler |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
14 | extern sButton Buttons[MAXBUTTONS]; ///< 40 buttons on a screen. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
15 | time_t now; ///< Current time |
42 | 16 | time_t last = 0; ///< Last time |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
17 | struct tm timeinfo; ///< Current time structure |
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
|
18 | char s_timer[16]; ///< Timer string buffer |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
19 | char s_top_msg[64]; ///< Top message string buffer |
0 | 20 | |
21 | extern float stageTemp; | |
22 | extern uint16_t stageTime; | |
23 | extern uint16_t TimeWhirlPool; | |
24 | extern uint32_t TimeLeft; | |
25 | extern uint32_t TimeSpent; | |
26 | extern uint32_t SecsCount; | |
27 | extern uint32_t pumpTime; | |
28 | extern uint32_t TimeBrewing; | |
29 | extern uint16_t Steady; | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
30 | esp_timer_handle_t timerHandle; ///< Timer handler |
0 | 31 | extern bool _NewMinute; |
32 | extern bool _UseHLT; | |
33 | extern bool System_TimeOk; | |
40
71e06f6d80fd
Work on web interface using websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
39
diff
changeset
|
34 | extern const esp_app_desc_t *app_desc; |
0 | 35 | |
36 | static const char *TAG = "task_tft"; | |
37 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
38 | #define SPI_BUS TFT_HSPI_HOST ///< SPI bus for the TFT, TFT_VSPI_HOST or TFT_HSPI_HOST |
0 | 39 | |
40 | extern int Main_Screen; | |
42 | 41 | extern int Sub_Screen; |
0 | 42 | extern int Old_Screen; |
43 | extern int MLT_pin; | |
44 | extern int HLT_pin; | |
45 | extern int Pump_pin; | |
46 | extern DS18B20_State *ds18b20_state; | |
47 | extern DRIVER_State *driver_state; | |
48 | extern JSON_log *json_log; | |
49 | extern SemaphoreHandle_t xSemaphoreDS18B20; | |
50 | extern SemaphoreHandle_t xSemaphoreDriver; | |
51 | extern SemaphoreHandle_t xSemaphoreWiFi; | |
52 | extern WIFI_State *wifi_state; | |
53 | extern double Output; | |
54 | extern sButton Buttons[MAXBUTTONS]; | |
55 | ||
56 | extern int BoilPower, LastMashStep; | |
57 | extern char temp_buf[], logline[], strftime_buf[64]; | |
58 | extern bool loop, CoolBeep, Resume, pumpRest, updateRuntime; | |
59 | extern bool NewMinute, TempReached; | |
60 | extern uint8_t MashState; | |
61 | extern float temp_MLT, MinMash, MaxMash; | |
62 | extern uint32_t power_MLT, power_HLT, counts; | |
63 | ||
64 | ||
65 | #ifdef CONFIG_TEMP_SENSORS_SIMULATOR | |
66 | extern float Fake_MLT; | |
67 | extern float Fake_HLT; | |
68 | #endif | |
69 | ||
70 | ||
71 | ||
72 | /** | |
73 | * @brief Seconds timer callback. | |
74 | */ | |
75 | void TimerCallback(void *arg); | |
76 | ||
77 | ||
78 | /***************************************************************************/ | |
79 | ||
80 | ||
81 | ||
82 | int init_tft_display(void) | |
83 | { | |
84 | esp_err_t ret; | |
85 | esp_timer_create_args_t timerSecond = { | |
86 | .callback = &TimerCallback, | |
87 | .name = "SecondsTimer" | |
88 | }; | |
89 | ||
90 | ESP_LOGI(TAG, "Initialize TFT"); | |
91 | ||
92 | max_rdclock = 8000000; | |
93 | TFT_PinsInit(); | |
94 | ||
95 | spi_lobo_bus_config_t buscfg = { | |
96 | .miso_io_num=PIN_NUM_MISO, // set SPI MISO pin | |
97 | .mosi_io_num=PIN_NUM_MOSI, // set SPI MOSI pin | |
98 | .sclk_io_num=PIN_NUM_CLK, // set SPI CLK pin | |
99 | .quadwp_io_num=-1, | |
100 | .quadhd_io_num=-1, | |
101 | .max_transfer_sz = 6*1024, | |
102 | }; | |
103 | spi_lobo_device_interface_config_t devcfg={ | |
104 | .clock_speed_hz=8000000, // Initial clock out at 8 MHz | |
105 | .mode=0, // SPI mode 0 | |
106 | .spics_io_num=-1, // we will use external CS pin | |
107 | .spics_ext_io_num=PIN_NUM_CS, // external CS pin | |
108 | .flags=LB_SPI_DEVICE_HALFDUPLEX, // ALWAYS SET to HALF DUPLEX MODE!! for display spi | |
109 | }; | |
110 | spi_lobo_device_interface_config_t tsdevcfg={ | |
111 | .clock_speed_hz=2500000, //Clock out at 2.5 MHz | |
112 | .mode=0, //SPI mode 0 | |
113 | .spics_io_num=PIN_NUM_TCS, //Touch CS pin | |
114 | .spics_ext_io_num=-1, //Not using the external CS | |
115 | }; | |
116 | ||
117 | ESP_LOGI(TAG, "TFT pins: miso=%d, mosi=%d, sck=%d, cs=%d", PIN_NUM_MISO, PIN_NUM_MOSI, PIN_NUM_CLK, PIN_NUM_CS); | |
118 | ||
119 | ret = spi_lobo_bus_add_device(SPI_BUS, &buscfg, &devcfg, &spi); | |
120 | assert(ret == ESP_OK); | |
121 | disp_spi = spi; | |
122 | ||
123 | // ==== Test select/deselect ==== | |
124 | ret = spi_lobo_device_select(spi, 1); | |
125 | assert(ret == ESP_OK); | |
126 | ret = spi_lobo_device_deselect(spi); | |
127 | assert(ret == ESP_OK); | |
128 | ||
129 | ESP_LOGI(TAG, "SPI: attached display, spi bus: %d, speed: %u, bus uses native pins: %s", | |
130 | SPI_BUS, spi_lobo_get_speed(spi), spi_lobo_uses_native_pins(spi) ? "true" : "false"); | |
131 | ||
132 | ESP_LOGI(TAG, "TS pins : miso=%d, mosi=%d, sck=%d, cs=%d", PIN_NUM_MISO, PIN_NUM_MOSI, PIN_NUM_CLK, PIN_NUM_TCS); | |
133 | ||
134 | ret=spi_lobo_bus_add_device(SPI_BUS, &buscfg, &tsdevcfg, &tsspi); | |
135 | assert(ret == ESP_OK); | |
136 | ts_spi = tsspi; | |
137 | ||
138 | // ==== Test select/deselect ==== | |
139 | ret = spi_lobo_device_select(tsspi, 1); | |
140 | assert(ret == ESP_OK); | |
141 | ret = spi_lobo_device_deselect(tsspi); | |
142 | assert(ret == ESP_OK); | |
143 | ||
144 | ESP_LOGI(TAG, "SPI: attached TS device, spi bus: %d, speed: %u", SPI_BUS, spi_lobo_get_speed(tsspi)); | |
145 | ||
146 | // ==== Initialize the Display ==== | |
147 | TFT_display_init(); | |
148 | ||
149 | // ---- Detect maximum read speed ---- | |
150 | max_rdclock = find_rd_speed(); | |
151 | ||
152 | // ==== Set SPI clock used for display operations ==== | |
153 | spi_lobo_set_speed(spi, DEFAULT_SPI_CLOCK); | |
154 | ESP_LOGI(TAG, "SPI: Max rd speed: %u, changed speed to %u", max_rdclock, spi_lobo_get_speed(spi)); | |
155 | ||
156 | font_rotate = 0; | |
157 | text_wrap = 0; | |
158 | font_transparent = 0; | |
159 | font_forceFixed = 0; | |
160 | gray_scale = 0; | |
161 | TFT_setGammaCurve(DEFAULT_GAMMA_CURVE); | |
162 | TFT_setRotation(LANDSCAPE); | |
163 | TFT_setFont(DEFAULT_FONT, NULL); | |
164 | TFT_resetclipwin(); | |
165 | ||
166 | /* | |
167 | * Create a one second periodic timer. | |
168 | */ | |
169 | ret = esp_timer_create(&timerSecond, &timerHandle); | |
170 | assert(ret == ESP_OK); | |
171 | ret = esp_timer_start_periodic(timerHandle, 1000000); | |
172 | assert(ret == ESP_OK); | |
173 | ||
174 | return ret; | |
175 | } | |
176 | ||
177 | ||
178 | ||
179 | void TimerCallback(void *arg) | |
180 | { | |
181 | TimeSpent++; | |
182 | SecsCount++; | |
183 | Steady++; | |
184 | TimeBrewing++; | |
185 | runtime.TimeBrewing++; | |
186 | if ((SecsCount % 60) == 0) | |
187 | _NewMinute = true; | |
188 | ||
189 | if (TimeLeft) { | |
190 | TimeLeft--; | |
191 | if (TimeLeft == 5) { | |
192 | SoundPlay(SOUND_TimeOut); | |
193 | } | |
194 | if ((TimeLeft % 60) == 0) { | |
195 | pumpTime++; | |
196 | } | |
197 | } | |
198 | } | |
199 | ||
200 | ||
201 | ||
202 | void TimerSet(uint32_t seconds) | |
203 | { | |
204 | Steady = TimeSpent = SecsCount = 0; | |
205 | TimeLeft = seconds; | |
206 | } | |
207 | ||
208 | ||
209 | ||
210 | void TimerShow(uint32_t Time, int X, int Y) | |
211 | { | |
212 | uint8_t Hours = (uint8_t)(Time / 3600); | |
213 | uint8_t Minutes = (uint8_t)((Time % 3600) / 60); | |
214 | uint8_t Seconds = (uint8_t)(Time % 60); | |
215 | char msg[32]; | |
216 | static uint32_t _oldTime = 0; | |
217 | ||
218 | if (Time != _oldTime) { | |
219 | _fg = TFT_GREEN; | |
220 | TFT_setFont(FONT_7SEG, NULL); | |
221 | set_7seg_font_atrib(12, 2, 1, TFT_DARKGREY); | |
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
|
222 | snprintf(s_timer, 15, "%02d:%02d:%02d", Hours, Minutes, Seconds); |
0 | 223 | TFT_print(s_timer, X, Y); |
224 | _oldTime = Time; | |
225 | snprintf(msg, 31, "{\"timer\":\"%s\"}", s_timer); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
226 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 227 | } |
228 | } | |
229 | ||
230 | ||
231 | ||
232 | void TopMessage(char *text) | |
233 | { | |
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
|
234 | char msg[96]; |
0 | 235 | |
236 | snprintf(s_top_msg, 63, "%s", text); | |
237 | _fg = TFT_YELLOW; | |
238 | font_transparent = 1; | |
239 | TFT_setFont(DEJAVU24_FONT, NULL); | |
240 | TFT_fillRect(0, 0, 319, 25, TFT_NAVY); | |
241 | TFT_print(s_top_msg, CENTER, 2); | |
242 | font_transparent = 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
|
243 | snprintf(msg, 95, "{\"top_msg\":\"%s\"}", s_top_msg); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
244 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 245 | } |
246 | ||
247 | ||
248 | ||
249 | void MLT_info(int x, int y, bool update) | |
250 | { | |
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
|
251 | char ctemp[16], csp[16], cpower[16], msg[96]; |
0 | 252 | static char ltemp[16], lsp[16], lpower[16]; |
253 | bool con, cpwr, cpump = false; | |
254 | static bool lon, lpwr, lpump; | |
255 | ||
256 | _bg = (color_t){ 48, 48, 48 }; | |
257 | _fg = TFT_WHITE; | |
258 | color_t _led = { 31,255, 31}; | |
259 | color_t _pump = {127,175,255}; | |
260 | color_t _pwr = {255, 47, 47}; | |
261 | ||
262 | if (! update) { | |
263 | TFT_fillRect(x, y, 178, 90, _bg); | |
264 | TFT_drawRect(x, y, 178, 90, _fg); | |
265 | TFT_drawFastHLine(x, y + 21, 178, _fg); | |
266 | TFT_setFont(DEJAVU18_FONT, NULL); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
267 | TFT_print((char *)"MLT", x + 67, y + 3); |
0 | 268 | } |
269 | ||
270 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
271 | sprintf(ctemp, "%7.3f", driver_state->mlt_pv); | |
272 | if (driver_state->mlt_mode) { | |
273 | sprintf(csp, "%6.2f sp", driver_state->mlt_sp); | |
274 | } else { | |
275 | csp[0] = '\0'; | |
276 | } | |
277 | if ((driver_state->mlt_mode == MLT_MODE_BANG) || (driver_state->mlt_mode == MLT_MODE_PID) || (driver_state->mlt_mode == MLT_MODE_EXT)) { | |
278 | sprintf(cpower, "%3d%%", driver_state->mlt_power); | |
279 | } else { | |
280 | cpower[0] = '\0'; | |
281 | } | |
282 | xSemaphoreGive(xSemaphoreDriver); | |
283 | } | |
284 | ||
285 | con = (MLT_pin) ? true : false; | |
286 | if ((con != lon) || (! update)) { | |
287 | if (con) { | |
288 | TFT_fillCircle(x + 166, y + 11, 8, _led); | |
289 | } else { | |
290 | TFT_fillCircle(x + 166, y + 11, 8, _bg); | |
291 | } | |
292 | lon = con; | |
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
|
293 | snprintf(msg, 95, "{\"mlt_led\":\"%s\"}", con ? "1":"0"); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
294 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 295 | } |
296 | ||
297 | cpump = (Pump_pin) ? true : false; | |
298 | if ((cpump != lpump) || (! update)) { | |
299 | if (cpump) { | |
300 | TFT_fillCircle(x + 146, y + 11, 8, _pump); | |
301 | } else { | |
302 | TFT_fillCircle(x + 146, y + 11, 8, _bg); | |
303 | } | |
304 | lpump = cpump; | |
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
|
305 | snprintf(msg, 95, "{\"pump_led\":\"%s\"}", cpump ? "1":"0"); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
306 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 307 | } |
308 | ||
309 | if (equipment.SSR2 == SSR2_ON_IDLE) { | |
310 | cpwr = (HLT_pin) ? true : false; | |
311 | if ((cpwr != lpwr) || (! update)) { | |
312 | if (cpwr) { | |
313 | TFT_fillCircle(x + 126, y + 11, 8, _pwr); | |
314 | } else { | |
315 | TFT_fillCircle(x + 126, y + 11, 8, _bg); | |
316 | } | |
317 | lpwr = cpwr; | |
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
|
318 | snprintf(msg, 95, "{\"hlt_led\":\"%s\"}", cpwr ? "1":"0"); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
319 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 320 | } |
321 | } | |
322 | ||
323 | if (strcmp(ctemp, ltemp) || (! update)) { | |
324 | TFT_setFont(USER_FONT, "/spiffs/fonts/Grotesk24x48.fon"); | |
325 | TFT_print(ctemp, x + 5, y + 23); | |
326 | strncpy(ltemp, ctemp, 16); | |
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
|
327 | snprintf(msg, 95, "{\"mlt_pv\":\"%s\"}", ctemp); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
328 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 329 | } |
330 | ||
331 | TFT_setFont(DEJAVU18_FONT, NULL); | |
332 | if (strcmp(csp, lsp) || (! update)) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
333 | TFT_clearStringRect(x + 5, y + 70, (char *)"123.45 sp"); |
0 | 334 | TFT_print(csp, x + 5, y + 70); |
335 | strncpy(lsp, csp, 16); | |
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
|
336 | snprintf(msg, 95, "{\"mlt_sp\":\"%s\"}", csp); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
337 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 338 | } |
339 | if (strcmp(cpower, lpower) || (! update)) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
340 | TFT_clearStringRect(x + 120, y + 70, (char *)"100%"); |
0 | 341 | TFT_print(cpower, x + 120, y + 70); |
342 | strncpy(lpower, cpower, 16); | |
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
|
343 | snprintf(msg, 95, "{\"mlt_power\":\"%s\"}", cpower); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
344 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 345 | } |
346 | } | |
347 | ||
348 | ||
349 | ||
350 | void HLT_info(int x, int y, bool update, bool small) | |
351 | { | |
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
|
352 | char ctemp[16], csp[16], cpower[16], msg[96]; |
0 | 353 | static char ltemp[16], lsp[16], lpower[16]; |
354 | bool con = false; | |
355 | static bool lon; | |
356 | uint8_t H; | |
357 | ||
358 | _bg = (color_t){ 63, 63, 64 }; | |
359 | _fg = TFT_YELLOW; | |
360 | color_t _led = {255, 47, 47}; | |
361 | H = (small) ? 70 : 90; | |
362 | ||
363 | if (! update) { | |
364 | TFT_fillRect(x, y, 178, H, _bg); | |
365 | TFT_drawRect(x, y, 178, H, _fg); | |
366 | TFT_drawFastHLine(x, y + 21, 178, _fg); | |
367 | TFT_setFont(DEJAVU18_FONT, NULL); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
368 | TFT_print((char *)"HLT", x + 67, y + 3); |
0 | 369 | } |
370 | ||
371 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
372 | sprintf(ctemp, "%7.3f", driver_state->hlt_pv); | |
373 | if (driver_state->hlt_mode == HLT_MODE_BANG) { | |
374 | sprintf(cpower, "%3d%%", driver_state->hlt_power); | |
375 | } else { | |
376 | cpower[0] = '\0'; | |
377 | } | |
378 | if (driver_state->hlt_mode == HLT_MODE_BANG || driver_state->hlt_mode == HLT_MODE_OFF) { | |
379 | sprintf(csp, "%6.2f sp", driver_state->hlt_sp); | |
380 | } else { | |
381 | csp[0] = '\0'; | |
382 | } | |
383 | xSemaphoreGive(xSemaphoreDriver); | |
384 | } | |
385 | ||
386 | con = (HLT_pin) ? true : false; | |
387 | if ((con != lon) || (! update)) { | |
388 | if (con) { | |
389 | TFT_fillCircle(x + 166, y + 11, 8, _led); | |
390 | } else { | |
391 | TFT_fillCircle(x + 166, y + 11, 8, _bg); | |
392 | } | |
393 | lon = con; | |
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
|
394 | snprintf(msg, 95, "{\"hlt_led\":\"%s\"}", con ? "1":"0"); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
395 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 396 | } |
397 | ||
398 | if (strcmp(ltemp, ctemp) || (! update)) { | |
399 | if (small) { | |
400 | TFT_setFont(USER_FONT, "/spiffs/fonts/DejaVuSans24.fon"); | |
401 | TFT_print(ctemp, x + 40, y + 25); | |
402 | } else { | |
403 | TFT_setFont(USER_FONT, "/spiffs/fonts/Grotesk24x48.fon"); | |
404 | TFT_print(ctemp, x + 5, y + 23); | |
405 | } | |
406 | strncpy(ltemp, ctemp, 16); | |
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
|
407 | snprintf(msg, 95, "{\"hlt_pv\":\"%s\"}", ctemp); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
408 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 409 | } |
410 | ||
411 | H = (small) ? 50 : 70; | |
412 | TFT_setFont(DEJAVU18_FONT, NULL); | |
413 | if (strcmp(csp, lsp) || (! update)) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
414 | TFT_clearStringRect(x + 5, y + H, (char *)"123.45 sp"); |
0 | 415 | TFT_print(csp, x + 5, y + H); |
416 | strncpy(lsp, csp, 16); | |
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
|
417 | snprintf(msg, 95, "{\"hlt_sp\":\"%s\"}", csp); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
418 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 419 | } |
420 | if (strcmp(cpower, lpower) || (! update)) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
421 | TFT_clearStringRect(x + 120, y + H, (char *)"100%"); |
0 | 422 | TFT_print(cpower, x + 120, y + H); |
423 | strncpy(lpower, cpower, 16); | |
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
|
424 | snprintf(msg, 95, "{\"hlt_power\":\"%s\"}", cpower); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
425 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 426 | } |
427 | } | |
428 | ||
429 | ||
430 | ||
431 | void update_json(void) | |
432 | { | |
433 | int Hour = (TimeBrewing / 3600); | |
434 | int Minute = ((TimeBrewing % 3600) / 60); | |
435 | ||
436 | if (counts == 0) | |
437 | counts = 1; // Prevent division by zero. | |
438 | ||
439 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
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
|
440 | snprintf(json_log->time, 11, "%02d:%02d", Hour, Minute); |
0 | 441 | json_log->mlt_sp = driver_state->mlt_sp; |
442 | json_log->mlt_pv = driver_state->mlt_pv; | |
443 | json_log->mlt_power = power_MLT / counts; | |
444 | json_log->mlt_tempreached = TempReached ? 1:0; | |
445 | json_log->pump_run = driver_state->pump_run; | |
446 | json_log->hlt_sp = driver_state->hlt_sp; | |
447 | json_log->hlt_pv = driver_state->hlt_pv; | |
448 | json_log->hlt_power = power_HLT / counts; | |
449 | json_log->event[0] = '\0'; | |
450 | xSemaphoreGive(xSemaphoreDriver); | |
451 | } | |
452 | } | |
453 | ||
454 | ||
455 | ||
456 | void TFTstartWS(int client) | |
457 | { | |
458 | char msg[1024]; | |
459 | char mlt_sp[16], mlt_power[16], hlt_sp[16], hlt_power[16]; | |
460 | ||
461 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
462 | if (driver_state->mlt_sp) { | |
463 | snprintf(mlt_sp, 15, "%6.2f sp", driver_state->mlt_sp); | |
464 | snprintf(mlt_power, 15, "%3d%%", driver_state->mlt_power); | |
465 | } else { | |
466 | mlt_sp[0] = '\0'; | |
467 | mlt_power[0] = '\0'; | |
468 | } | |
469 | if (driver_state->hlt_sp) { | |
470 | snprintf(hlt_sp, 15, "%6.2f sp", driver_state->hlt_sp); | |
471 | snprintf(hlt_power, 15, "%3d%%", driver_state->hlt_power); | |
472 | } else { | |
473 | hlt_sp[0] = '\0'; | |
474 | hlt_power[0] = '\0'; | |
475 | } | |
42 | 476 | snprintf(msg, 1023, "{\"main\":\"%d\",\"sub\":\"%d\",\"mlt_led\":\"%d\",\"mlt_pv\":\"%7.3f\",\"mlt_sp\":\"%s\",\"mlt_power\":\"%s\"" \ |
0 | 477 | ",\"pump_led\":\"%d\",\"hlt_led\":\"%d\",\"hlt_pv\":\"%7.3f\",\"hlt_sp\":\"%s\",\"hlt_power\":\"%s\"" \ |
478 | ",\"timer\":\"%s\",\"top_msg\":\"%s\"}", | |
42 | 479 | Main_Screen, Sub_Screen, (MLT_pin) ? 1:0, driver_state->mlt_pv, mlt_sp, mlt_power, |
0 | 480 | (Pump_pin) ? 1:0, (HLT_pin) ? 1:0, driver_state->hlt_pv, hlt_sp, hlt_power, |
481 | s_timer, s_top_msg); | |
482 | ||
483 | xSemaphoreGive(xSemaphoreDriver); | |
484 | ws_server_send_text_client(client, msg, strlen(msg)); | |
485 | } | |
486 | ||
487 | } | |
488 | ||
489 | ||
490 | ||
491 | void task_tft(void *pvParameter) | |
492 | { | |
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
|
493 | char msg[96]; |
0 | 494 | |
495 | ESP_LOGI(TAG, "Initialize TFT/Touch task"); | |
496 | ||
497 | /* | |
498 | * Task loop. Read touchscreen events. | |
499 | */ | |
500 | while (1) { | |
501 | /* | |
502 | * Build new screen. | |
503 | */ | |
504 | startover: | |
505 | ||
506 | updateRuntime = false; | |
507 | if (_NewMinute) { | |
508 | _NewMinute = false; | |
509 | NewMinute = true; | |
510 | } | |
511 | ||
512 | /* | |
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:
42
diff
changeset
|
513 | * Timekeeping. |
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:
42
diff
changeset
|
514 | * In the WiFi task sntp is started and sets System_TimeOk if the |
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:
42
diff
changeset
|
515 | * clock is synced once. |
0 | 516 | */ |
517 | time(&now); | |
518 | localtime_r(&now, &timeinfo); | |
519 | ||
520 | if (Old_Screen != Main_Screen) { | |
521 | ||
522 | if ((Main_Screen == MAIN_MODE_FREE) && ((config.ts_xleft == 0) || (config.ts_ybottom == 0))) { | |
523 | Main_Screen = MAIN_MODE_CALIBRATION; | |
524 | } | |
525 | ||
526 | /* | |
527 | * With each screenchange, remove the timer too. | |
528 | */ | |
42 | 529 | Sub_Screen = 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
|
530 | snprintf(msg, 95, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
531 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 532 | |
533 | ESP_LOGI(TAG, "Change screen %d to %d", Old_Screen, Main_Screen); | |
534 | _bg = TFT_BLACK; | |
535 | TFT_fillScreen(_bg); | |
536 | TFT_resetclipwin(); | |
537 | Buttons_Clear(); | |
538 | Old_Screen = Main_Screen; | |
539 | ||
540 | switch (Main_Screen) { | |
541 | case MAIN_MODE_FREE: | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
542 | TopMessage((char *)"Hoofdmenu"); |
0 | 543 | MLT_info(71, 26, false); |
544 | if ((equipment.SSR2 == SSR2_HLT_SHARE) || (equipment.SSR2 == SSR2_HLT_IND)) { | |
545 | HLT_info(71,150, false, false); | |
546 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
547 | Buttons_Add( 5, 26, 60, 40, (char *)"Hand", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
548 | Buttons_Add(255, 26, 60, 40, (char *)"Auto", 1); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
549 | Buttons_Add( 5, 200, 60, 40, (char *)"Info", 2); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
550 | Buttons_Add(255, 200, 60, 40, (char *)"Tools", 3); |
0 | 551 | Buttons_Show(); |
552 | break; | |
553 | ||
554 | case MAIN_MODE_CALIBRATION: | |
555 | Calibration_Init(); | |
556 | break; | |
557 | ||
558 | case MAIN_INFO: | |
39
e5900c9b9a7b
Use PROJECT_VER for version number. Updated README and info screen.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
559 | sprintf(temp_buf, "BrewBoard %s", app_desc->version); |
0 | 560 | TopMessage(temp_buf); |
561 | _fg = TFT_YELLOW; | |
562 | TFT_setFont(UBUNTU16_FONT, NULL); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
563 | TFT_print((char *)"Written by Michiel Broek (C) 2018\r\n\n", 0, 50); |
0 | 564 | // ------------------------------------- |
565 | _fg = TFT_ORANGE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
566 | TFT_print((char *)"Parts are written by Chris Morgan,\r\n", 0, LASTY); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
567 | TFT_print((char *)"Brett Beauregard, Blake Felt, LoBo,\r\n", 0, LASTY); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
568 | TFT_print((char *)"and David Antliff.\r\n", 0, LASTY); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
569 | ShowInteger(1,140, (char *)"Free memory", (char *)" bytes", esp_get_free_heap_size()); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
570 | ShowText(1,158, (char *)"IDF version", (char *)esp_get_idf_version()); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
571 | Buttons_Add(130, 200, 60, 40, (char *)"Ok", 0); |
0 | 572 | Buttons[0].dark = true; |
573 | Buttons_Show(); | |
574 | break; | |
575 | ||
576 | case MAIN_TOOLS: | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
577 | TopMessage((char *)"Tools menu"); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
578 | Buttons_Add( 20, 40,120, 40, (char *)"Setup", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
579 | Buttons_Add( 20,120,120, 40, (char *)"Bestanden", 1); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
580 | Buttons_Add(180, 40,120, 40, (char *)"Recepten", 2); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
581 | Buttons_Add(180,120,120, 40, (char *)"Updates", 3); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
582 | Buttons_Add(130, 200, 60, 40, (char *)"Ok", 4); |
0 | 583 | Buttons[4].dark = true; |
584 | Buttons_Show(); | |
585 | break; | |
586 | ||
587 | case MAIN_TOOLS_SETUP: | |
588 | case MAIN_TOOLS_SETUP_CONFIG: | |
589 | case MAIN_TOOLS_SETUP_CO_EDIT: | |
590 | case MAIN_TOOLS_SETUP_EQUIPMENT: | |
591 | case MAIN_TOOLS_SETUP_EQ_EDIT: | |
592 | case MAIN_TOOLS_SETUP_CALIBRATION: | |
593 | Setup_Init(); | |
594 | break; | |
595 | ||
596 | case MAIN_TOOLS_SETUP_WIFI: | |
597 | case MAIN_TOOLS_SETUP_WIFI_CUR: | |
598 | case MAIN_TOOLS_SETUP_WIFI_CON: | |
599 | case MAIN_TOOLS_SETUP_WIFI_NEW: | |
600 | if (WiFi_Init()) | |
601 | goto startover; | |
602 | break; | |
603 | ||
604 | case MAIN_TOOLS_RECIPE: | |
605 | case MAIN_TOOLS_RECIPE_EDIT: | |
606 | Recipes_Init(); | |
607 | break; | |
608 | ||
609 | case MAIN_TOOLS_FILES: | |
2
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
610 | case MAIN_TOOLS_FILES_DIR: |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
611 | case MAIN_TOOLS_FILES_RESTORE: |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
612 | case MAIN_TOOLS_FILES_BACKUP: |
0 | 613 | Files_Init(); |
614 | break; | |
615 | ||
616 | case MAIN_TOOLS_UPDATES: | |
617 | Updates_Init(); | |
618 | break; | |
619 | ||
42 | 620 | case MAIN_AUTO_INIT1: |
621 | case MAIN_AUTO_INIT2: | |
0 | 622 | case MAIN_AUTO_DELAYSTART: |
623 | case MAIN_AUTO_HEATUP: | |
624 | case MAIN_AUTO_MASH_IN: | |
625 | case MAIN_AUTO_MASH_1: | |
626 | case MAIN_AUTO_MASH_2: | |
627 | case MAIN_AUTO_MASH_3: | |
628 | case MAIN_AUTO_MASH_4: | |
629 | case MAIN_AUTO_MASH_5: | |
630 | case MAIN_AUTO_MASH_6: | |
631 | case MAIN_AUTO_MASH_OUT: | |
632 | case MAIN_AUTO_TOBOIL: | |
633 | case MAIN_AUTO_BOILING: | |
634 | case MAIN_AUTO_COOLING_H: | |
635 | case MAIN_AUTO_COOLING_M: | |
636 | case MAIN_AUTO_COOLING_C: | |
637 | case MAIN_AUTO_WHIRLPOOL9: | |
638 | case MAIN_AUTO_WHIRLPOOL7: | |
639 | case MAIN_AUTO_WHIRLPOOL6: | |
640 | case MAIN_AUTO_WHIRLPOOL2: | |
641 | case MAIN_AUTO_DONE: | |
642 | case MAIN_AUTO_ABORT: | |
643 | if (Automation_Init()) | |
644 | goto startover; | |
645 | break; | |
646 | ||
647 | case MAIN_MANUAL_INIT: | |
648 | case MAIN_MANUAL_MAIN: | |
649 | if (Manual_Init()) | |
650 | goto startover; | |
651 | break; | |
652 | ||
653 | default: | |
654 | break; | |
655 | } | |
656 | } | |
657 | ||
658 | /* | |
659 | * Update screen | |
660 | */ | |
661 | switch (Main_Screen) { | |
662 | case MAIN_MODE_FREE: | |
663 | MLT_info(71, 26, true); | |
664 | if ((equipment.SSR2 == SSR2_HLT_SHARE) || (equipment.SSR2 == SSR2_HLT_IND)) { | |
665 | HLT_info(71, 150, true, false); | |
666 | } | |
667 | switch (Buttons_Scan()) { | |
668 | case 0: Main_Screen = MAIN_MANUAL_INIT; break; | |
42 | 669 | case 1: Main_Screen = MAIN_AUTO_INIT1; break; |
670 | case 2: Main_Screen = MAIN_INFO; break; | |
671 | case 3: Main_Screen = MAIN_TOOLS; break; | |
0 | 672 | default: break; |
673 | } | |
42 | 674 | if (System_TimeOk && (now != last)) { |
675 | last = now; | |
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
|
676 | //strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); |
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
|
677 | strftime(strftime_buf, sizeof(strftime_buf), "%a %e %b %Y %T", &timeinfo); |
25
79ee940410de
Show clock on the main screen, but only if the ntp time has been set.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
678 | _bg = TFT_BLACK; |
79ee940410de
Show clock on the main screen, but only if the ntp time has been set.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
679 | _fg = TFT_ORANGE; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
680 | TFT_setFont(DEJAVU18_FONT, NULL); |
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
|
681 | snprintf(msg, 95, " %s ", strftime_buf); |
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
|
682 | TFT_print(msg, CENTER, 125); |
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
|
683 | snprintf(msg, 95, "{\"timer\":\"%s\"}", strftime_buf); // Fix string termination and only send once/second. |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
684 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
25
79ee940410de
Show clock on the main screen, but only if the ntp time has been set.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
685 | } |
0 | 686 | break; |
687 | ||
688 | case MAIN_MODE_CALIBRATION: | |
689 | Calibration_Loop(); | |
690 | Main_Screen = MAIN_MODE_FREE; | |
691 | break; | |
692 | ||
693 | case MAIN_TOOLS: | |
694 | switch (Buttons_Scan()) { | |
695 | case 0: Main_Screen = MAIN_TOOLS_SETUP; break; | |
696 | case 1: Main_Screen = MAIN_TOOLS_FILES; break; | |
697 | case 2: Main_Screen = MAIN_TOOLS_RECIPE; break; | |
698 | case 3: Main_Screen = MAIN_TOOLS_UPDATES; break; | |
699 | case 4: Main_Screen = MAIN_MODE_FREE; break; | |
700 | default: break; | |
701 | } | |
702 | break; | |
703 | ||
704 | case MAIN_TOOLS_SETUP: | |
705 | case MAIN_TOOLS_SETUP_CONFIG: | |
706 | case MAIN_TOOLS_SETUP_CO_EDIT: | |
707 | case MAIN_TOOLS_SETUP_EQUIPMENT: | |
708 | case MAIN_TOOLS_SETUP_EQ_EDIT: | |
709 | case MAIN_TOOLS_SETUP_CALIBRATION: | |
710 | Setup_Loop(); | |
711 | break; | |
712 | ||
713 | case MAIN_TOOLS_SETUP_WIFI: | |
714 | case MAIN_TOOLS_SETUP_WIFI_CUR: | |
715 | case MAIN_TOOLS_SETUP_WIFI_CON: | |
716 | case MAIN_TOOLS_SETUP_WIFI_NEW: | |
717 | if (WiFi_Loop()) | |
718 | goto startover; | |
719 | break; | |
720 | ||
721 | case MAIN_TOOLS_RECIPE: | |
722 | case MAIN_TOOLS_RECIPE_EDIT: | |
723 | Recipes_Loop(); | |
724 | break; | |
725 | ||
726 | case MAIN_TOOLS_FILES: | |
2
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
727 | case MAIN_TOOLS_FILES_DIR: |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
728 | case MAIN_TOOLS_FILES_RESTORE: |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
729 | case MAIN_TOOLS_FILES_BACKUP: |
0 | 730 | Files_Loop(); |
731 | break; | |
732 | ||
733 | case MAIN_TOOLS_UPDATES: | |
734 | Updates_Loop(); | |
735 | break; | |
736 | ||
737 | case MAIN_INFO: | |
738 | if (Buttons_Scan() == 0) { | |
739 | Main_Screen = MAIN_MODE_FREE; | |
740 | } | |
741 | break; | |
742 | ||
42 | 743 | case MAIN_AUTO_INIT1: |
744 | case MAIN_AUTO_INIT2: | |
0 | 745 | case MAIN_AUTO_DELAYSTART: |
746 | case MAIN_AUTO_HEATUP: | |
747 | case MAIN_AUTO_MASH_IN: | |
748 | case MAIN_AUTO_MASH_1: | |
749 | case MAIN_AUTO_MASH_2: | |
750 | case MAIN_AUTO_MASH_3: | |
751 | case MAIN_AUTO_MASH_4: | |
752 | case MAIN_AUTO_MASH_5: | |
753 | case MAIN_AUTO_MASH_6: | |
754 | case MAIN_AUTO_MASH_OUT: | |
755 | case MAIN_AUTO_TOBOIL: | |
756 | case MAIN_AUTO_BOILING: | |
757 | case MAIN_AUTO_COOLING_H: | |
758 | case MAIN_AUTO_COOLING_M: | |
759 | case MAIN_AUTO_COOLING_C: | |
760 | case MAIN_AUTO_WHIRLPOOL9: | |
761 | case MAIN_AUTO_WHIRLPOOL7: | |
762 | case MAIN_AUTO_WHIRLPOOL6: | |
763 | case MAIN_AUTO_WHIRLPOOL2: | |
764 | case MAIN_AUTO_DONE: | |
765 | case MAIN_AUTO_ABORT: | |
766 | if (Automation_Loop()) | |
767 | goto startover; | |
768 | break; | |
769 | ||
770 | case MAIN_MANUAL_INIT: | |
771 | case MAIN_MANUAL_MAIN: | |
772 | if (Manual_Loop()) | |
773 | goto startover; | |
774 | break; | |
775 | ||
776 | default: | |
777 | break; | |
778 | } | |
779 | ||
780 | if (updateRuntime) { | |
781 | write_runtime(); | |
782 | } | |
783 | ||
784 | /* | |
785 | * Count power average during brewing. | |
786 | */ | |
787 | if ((Main_Screen >= MAIN_AUTO_MASH_IN) && (Main_Screen < MAIN_AUTO_DONE)) { | |
788 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
789 | power_MLT += driver_state->mlt_power; | |
790 | power_HLT += driver_state->hlt_power; | |
791 | counts++; | |
792 | xSemaphoreGive(xSemaphoreDriver); | |
793 | } | |
794 | } | |
795 | ||
796 | if (NewMinute) { | |
797 | /* | |
798 | * Brew logging. | |
799 | */ | |
800 | if ((Main_Screen >= MAIN_AUTO_MASH_IN) && (Main_Screen < MAIN_AUTO_DONE)) { | |
801 | update_json(); | |
802 | log_json(); | |
803 | power_MLT = power_HLT = counts = 0; | |
804 | } | |
805 | } | |
806 | ||
807 | NewMinute = false; | |
808 | vTaskDelay(50 / portTICK_PERIOD_MS); | |
809 | } | |
810 | } | |
811 | ||
812 |