Mon, 17 May 2021 20:44:35 +0200
Added 7 sgemnt fonts for the web client. Log messages in the components more compact. Added fonts mime-types to the webserver. Switched to stable esp-idf 4.2.1. Upgraded the SD-mmc card API.
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 | ||
88
7f02dbee58d0
Fix missing log entries. More code space saving.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
90 | ESP_LOGD(TAG, "Initialize TFT"); |
0 | 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 | ||
88
7f02dbee58d0
Fix missing log entries. More code space saving.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
129 | ESP_LOGD(TAG, "SPI: attached display, spi bus: %d, speed: %u, bus uses native pins: %s", |
0 | 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 | ||
88
7f02dbee58d0
Fix missing log entries. More code space saving.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
144 | ESP_LOGD(TAG, "SPI: attached TS device, spi bus: %d, speed: %u", SPI_BUS, spi_lobo_get_speed(tsspi)); |
0 | 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); | |
88
7f02dbee58d0
Fix missing log entries. More code space saving.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
154 | ESP_LOGD(TAG, "SPI: Max rd speed: %u, changed speed to %u", max_rdclock, spi_lobo_get_speed(spi)); |
0 | 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) { | |
57
6c5211c0120b
Version 0.3.3. Added favicon.ico to the web server. Fixed text position in the http client for the power percentage. Silenced a lot of log messages. Moved the pump led on the display to the left just as on the web page.
Michiel Broek <mbroek@mbse.eu>
parents:
56
diff
changeset
|
300 | TFT_fillCircle(x + 11, y + 11, 8, _pump); |
0 | 301 | } else { |
57
6c5211c0120b
Version 0.3.3. Added favicon.ico to the web server. Fixed text position in the http client for the power percentage. Silenced a lot of log messages. Moved the pump led on the display to the left just as on the web page.
Michiel Broek <mbroek@mbse.eu>
parents:
56
diff
changeset
|
302 | TFT_fillCircle(x + 11, y + 11, 8, _bg); |
0 | 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 | |
88
7f02dbee58d0
Fix missing log entries. More code space saving.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
495 | ESP_LOGI(TAG, "Start TFT/Touch"); |
0 | 496 | |
497 | /* | |
498 | * Task loop. Read touchscreen events. | |
499 | */ | |
500 | while (1) { | |
501 | /* | |
502 | * Build new screen. | |
503 | */ | |
504 | updateRuntime = false; | |
505 | if (_NewMinute) { | |
506 | _NewMinute = false; | |
507 | NewMinute = true; | |
508 | } | |
88
7f02dbee58d0
Fix missing log entries. More code space saving.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
509 | startover: |
0 | 510 | |
511 | /* | |
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
|
512 | * 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
|
513 | * 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
|
514 | * clock is synced once. |
0 | 515 | */ |
516 | time(&now); | |
517 | localtime_r(&now, &timeinfo); | |
518 | ||
519 | if (Old_Screen != Main_Screen) { | |
520 | ||
521 | if ((Main_Screen == MAIN_MODE_FREE) && ((config.ts_xleft == 0) || (config.ts_ybottom == 0))) { | |
522 | Main_Screen = MAIN_MODE_CALIBRATION; | |
523 | } | |
524 | ||
525 | /* | |
526 | * With each screenchange, remove the timer too. | |
527 | */ | |
42 | 528 | 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
|
529 | 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
|
530 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 531 | |
57
6c5211c0120b
Version 0.3.3. Added favicon.ico to the web server. Fixed text position in the http client for the power percentage. Silenced a lot of log messages. Moved the pump led on the display to the left just as on the web page.
Michiel Broek <mbroek@mbse.eu>
parents:
56
diff
changeset
|
532 | ESP_LOGD(TAG, "Change screen %d to %d", Old_Screen, Main_Screen); |
0 | 533 | _bg = TFT_BLACK; |
534 | TFT_fillScreen(_bg); | |
535 | TFT_resetclipwin(); | |
536 | Buttons_Clear(); | |
537 | Old_Screen = Main_Screen; | |
538 | ||
539 | switch (Main_Screen) { | |
540 | 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
|
541 | TopMessage((char *)"Hoofdmenu"); |
0 | 542 | MLT_info(71, 26, false); |
543 | if ((equipment.SSR2 == SSR2_HLT_SHARE) || (equipment.SSR2 == SSR2_HLT_IND)) { | |
544 | HLT_info(71,150, false, false); | |
545 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
546 | 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
|
547 | 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
|
548 | 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
|
549 | Buttons_Add(255, 200, 60, 40, (char *)"Tools", 3); |
0 | 550 | Buttons_Show(); |
551 | break; | |
552 | ||
553 | case MAIN_MODE_CALIBRATION: | |
554 | Calibration_Init(); | |
555 | break; | |
556 | ||
557 | 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
|
558 | sprintf(temp_buf, "BrewBoard %s", app_desc->version); |
0 | 559 | TopMessage(temp_buf); |
560 | _fg = TFT_YELLOW; | |
561 | TFT_setFont(UBUNTU16_FONT, NULL); | |
91
255a75322212
Added 7 sgemnt fonts for the web client. Log messages in the components more compact. Added fonts mime-types to the webserver. Switched to stable esp-idf 4.2.1. Upgraded the SD-mmc card API.
Michiel Broek <mbroek@mbse.eu>
parents:
88
diff
changeset
|
562 | TFT_print((char *)"Written by Michiel Broek (C) 2018-2021\r\n\n", 0, 50); |
0 | 563 | // ------------------------------------- |
564 | _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
|
565 | 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
|
566 | 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
|
567 | 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
|
568 | 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
|
569 | 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
|
570 | Buttons_Add(130, 200, 60, 40, (char *)"Ok", 0); |
0 | 571 | Buttons[0].dark = true; |
572 | Buttons_Show(); | |
573 | break; | |
574 | ||
575 | 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
|
576 | 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
|
577 | 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
|
578 | 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
|
579 | 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
|
580 | 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
|
581 | Buttons_Add(130, 200, 60, 40, (char *)"Ok", 4); |
0 | 582 | Buttons[4].dark = true; |
583 | Buttons_Show(); | |
584 | break; | |
585 | ||
586 | case MAIN_TOOLS_SETUP: | |
587 | case MAIN_TOOLS_SETUP_CONFIG: | |
588 | case MAIN_TOOLS_SETUP_CO_EDIT: | |
589 | case MAIN_TOOLS_SETUP_EQUIPMENT: | |
590 | case MAIN_TOOLS_SETUP_EQ_EDIT: | |
591 | case MAIN_TOOLS_SETUP_CALIBRATION: | |
592 | Setup_Init(); | |
593 | break; | |
594 | ||
595 | case MAIN_TOOLS_SETUP_WIFI: | |
596 | case MAIN_TOOLS_SETUP_WIFI_CUR: | |
597 | case MAIN_TOOLS_SETUP_WIFI_CON: | |
598 | case MAIN_TOOLS_SETUP_WIFI_NEW: | |
599 | if (WiFi_Init()) | |
600 | goto startover; | |
601 | break; | |
602 | ||
603 | case MAIN_TOOLS_RECIPE: | |
604 | case MAIN_TOOLS_RECIPE_EDIT: | |
605 | Recipes_Init(); | |
606 | break; | |
607 | ||
608 | case MAIN_TOOLS_FILES: | |
2
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
609 | case MAIN_TOOLS_FILES_DIR: |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
610 | case MAIN_TOOLS_FILES_RESTORE: |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
611 | case MAIN_TOOLS_FILES_BACKUP: |
0 | 612 | Files_Init(); |
613 | break; | |
614 | ||
615 | case MAIN_TOOLS_UPDATES: | |
616 | Updates_Init(); | |
617 | break; | |
618 | ||
42 | 619 | case MAIN_AUTO_INIT1: |
620 | case MAIN_AUTO_INIT2: | |
0 | 621 | case MAIN_AUTO_DELAYSTART: |
622 | case MAIN_AUTO_HEATUP: | |
77
66c77497d86d
Changed the recipe database so that it is expandable, version 2. More mash fields and allow 16 steps. Allow 20 Additions. Removed separate mash steps from the state machine, the steps are moved to the runtime data. There is no fixed step number for mashout anymore. There is no fixed step for mash-in anymore, just use the first step and heat to the infusion temperature. After malt add, switch to the normal step temperature. Implemented decoction steps.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
623 | case MAIN_AUTO_MASH: |
0 | 624 | case MAIN_AUTO_TOBOIL: |
625 | case MAIN_AUTO_BOILING: | |
626 | case MAIN_AUTO_COOLING_H: | |
627 | case MAIN_AUTO_COOLING_M: | |
628 | case MAIN_AUTO_COOLING_C: | |
629 | case MAIN_AUTO_WHIRLPOOL9: | |
630 | case MAIN_AUTO_WHIRLPOOL7: | |
631 | case MAIN_AUTO_WHIRLPOOL6: | |
632 | case MAIN_AUTO_WHIRLPOOL2: | |
633 | case MAIN_AUTO_DONE: | |
634 | case MAIN_AUTO_ABORT: | |
635 | if (Automation_Init()) | |
636 | goto startover; | |
637 | break; | |
638 | ||
639 | case MAIN_MANUAL_INIT: | |
640 | case MAIN_MANUAL_MAIN: | |
641 | if (Manual_Init()) | |
642 | goto startover; | |
643 | break; | |
644 | ||
645 | default: | |
646 | break; | |
647 | } | |
648 | } | |
649 | ||
650 | /* | |
651 | * Update screen | |
652 | */ | |
653 | switch (Main_Screen) { | |
654 | case MAIN_MODE_FREE: | |
655 | MLT_info(71, 26, true); | |
656 | if ((equipment.SSR2 == SSR2_HLT_SHARE) || (equipment.SSR2 == SSR2_HLT_IND)) { | |
657 | HLT_info(71, 150, true, false); | |
658 | } | |
659 | switch (Buttons_Scan()) { | |
660 | case 0: Main_Screen = MAIN_MANUAL_INIT; break; | |
42 | 661 | case 1: Main_Screen = MAIN_AUTO_INIT1; break; |
662 | case 2: Main_Screen = MAIN_INFO; break; | |
663 | case 3: Main_Screen = MAIN_TOOLS; break; | |
0 | 664 | default: break; |
665 | } | |
42 | 666 | if (System_TimeOk && (now != last)) { |
667 | 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
|
668 | //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
|
669 | 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
|
670 | _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
|
671 | _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
|
672 | 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
|
673 | 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
|
674 | 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
|
675 | 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
|
676 | 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
|
677 | } |
0 | 678 | break; |
679 | ||
680 | case MAIN_MODE_CALIBRATION: | |
681 | Calibration_Loop(); | |
682 | Main_Screen = MAIN_MODE_FREE; | |
683 | break; | |
684 | ||
685 | case MAIN_TOOLS: | |
686 | switch (Buttons_Scan()) { | |
687 | case 0: Main_Screen = MAIN_TOOLS_SETUP; break; | |
688 | case 1: Main_Screen = MAIN_TOOLS_FILES; break; | |
689 | case 2: Main_Screen = MAIN_TOOLS_RECIPE; break; | |
690 | case 3: Main_Screen = MAIN_TOOLS_UPDATES; break; | |
691 | case 4: Main_Screen = MAIN_MODE_FREE; break; | |
692 | default: break; | |
693 | } | |
694 | break; | |
695 | ||
696 | case MAIN_TOOLS_SETUP: | |
697 | case MAIN_TOOLS_SETUP_CONFIG: | |
698 | case MAIN_TOOLS_SETUP_CO_EDIT: | |
699 | case MAIN_TOOLS_SETUP_EQUIPMENT: | |
700 | case MAIN_TOOLS_SETUP_EQ_EDIT: | |
701 | case MAIN_TOOLS_SETUP_CALIBRATION: | |
702 | Setup_Loop(); | |
703 | break; | |
704 | ||
705 | case MAIN_TOOLS_SETUP_WIFI: | |
706 | case MAIN_TOOLS_SETUP_WIFI_CUR: | |
707 | case MAIN_TOOLS_SETUP_WIFI_CON: | |
708 | case MAIN_TOOLS_SETUP_WIFI_NEW: | |
709 | if (WiFi_Loop()) | |
710 | goto startover; | |
711 | break; | |
712 | ||
713 | case MAIN_TOOLS_RECIPE: | |
714 | case MAIN_TOOLS_RECIPE_EDIT: | |
715 | Recipes_Loop(); | |
716 | break; | |
717 | ||
718 | case MAIN_TOOLS_FILES: | |
2
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
719 | case MAIN_TOOLS_FILES_DIR: |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
720 | case MAIN_TOOLS_FILES_RESTORE: |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
721 | case MAIN_TOOLS_FILES_BACKUP: |
0 | 722 | Files_Loop(); |
723 | break; | |
724 | ||
725 | case MAIN_TOOLS_UPDATES: | |
726 | Updates_Loop(); | |
727 | break; | |
728 | ||
729 | case MAIN_INFO: | |
730 | if (Buttons_Scan() == 0) { | |
731 | Main_Screen = MAIN_MODE_FREE; | |
732 | } | |
733 | break; | |
734 | ||
42 | 735 | case MAIN_AUTO_INIT1: |
736 | case MAIN_AUTO_INIT2: | |
0 | 737 | case MAIN_AUTO_DELAYSTART: |
738 | case MAIN_AUTO_HEATUP: | |
77
66c77497d86d
Changed the recipe database so that it is expandable, version 2. More mash fields and allow 16 steps. Allow 20 Additions. Removed separate mash steps from the state machine, the steps are moved to the runtime data. There is no fixed step number for mashout anymore. There is no fixed step for mash-in anymore, just use the first step and heat to the infusion temperature. After malt add, switch to the normal step temperature. Implemented decoction steps.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
739 | case MAIN_AUTO_MASH: |
0 | 740 | case MAIN_AUTO_TOBOIL: |
741 | case MAIN_AUTO_BOILING: | |
742 | case MAIN_AUTO_COOLING_H: | |
743 | case MAIN_AUTO_COOLING_M: | |
744 | case MAIN_AUTO_COOLING_C: | |
745 | case MAIN_AUTO_WHIRLPOOL9: | |
746 | case MAIN_AUTO_WHIRLPOOL7: | |
747 | case MAIN_AUTO_WHIRLPOOL6: | |
748 | case MAIN_AUTO_WHIRLPOOL2: | |
749 | case MAIN_AUTO_DONE: | |
750 | case MAIN_AUTO_ABORT: | |
751 | if (Automation_Loop()) | |
752 | goto startover; | |
753 | break; | |
754 | ||
755 | case MAIN_MANUAL_INIT: | |
756 | case MAIN_MANUAL_MAIN: | |
757 | if (Manual_Loop()) | |
758 | goto startover; | |
759 | break; | |
760 | ||
761 | default: | |
762 | break; | |
763 | } | |
764 | ||
765 | if (updateRuntime) { | |
766 | write_runtime(); | |
767 | } | |
768 | ||
769 | /* | |
770 | * Count power average during brewing. | |
771 | */ | |
77
66c77497d86d
Changed the recipe database so that it is expandable, version 2. More mash fields and allow 16 steps. Allow 20 Additions. Removed separate mash steps from the state machine, the steps are moved to the runtime data. There is no fixed step number for mashout anymore. There is no fixed step for mash-in anymore, just use the first step and heat to the infusion temperature. After malt add, switch to the normal step temperature. Implemented decoction steps.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
772 | if ((Main_Screen >= MAIN_AUTO_MASH) && (Main_Screen < MAIN_AUTO_DONE)) { |
0 | 773 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { |
774 | power_MLT += driver_state->mlt_power; | |
775 | power_HLT += driver_state->hlt_power; | |
776 | counts++; | |
777 | xSemaphoreGive(xSemaphoreDriver); | |
778 | } | |
779 | } | |
780 | ||
781 | if (NewMinute) { | |
782 | /* | |
783 | * Brew logging. | |
784 | */ | |
77
66c77497d86d
Changed the recipe database so that it is expandable, version 2. More mash fields and allow 16 steps. Allow 20 Additions. Removed separate mash steps from the state machine, the steps are moved to the runtime data. There is no fixed step number for mashout anymore. There is no fixed step for mash-in anymore, just use the first step and heat to the infusion temperature. After malt add, switch to the normal step temperature. Implemented decoction steps.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
785 | if ((Main_Screen >= MAIN_AUTO_MASH) && (Main_Screen < MAIN_AUTO_DONE)) { |
0 | 786 | update_json(); |
787 | log_json(); | |
788 | power_MLT = power_HLT = counts = 0; | |
789 | } | |
790 | } | |
791 | ||
792 | NewMinute = false; | |
793 | vTaskDelay(50 / portTICK_PERIOD_MS); | |
794 | } | |
795 | } | |
796 | ||
797 |