-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayManager.cpp
More file actions
576 lines (466 loc) · 22.3 KB
/
DisplayManager.cpp
File metadata and controls
576 lines (466 loc) · 22.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
#include "HardwareSerial.h"
#include "misc/lv_types.h"
#include "widgets/label/lv_label.h"
#include "core/lv_obj.h"
#include "DisplayManager.h"
#include "src/ui/ui.h"
DisplayManager::DisplayManager() : tft(TFT_eSPI()), lastTickMillis(0) {}
void DisplayManager::init() {
tft.init();
tft.setRotation(1);
// touch calibration
uint16_t calData[5] = { 248, 3501, 346, 3358, 1 };
tft.setTouch(calData);
lv_init();
disp = lv_display_create(screenWidth, screenHeight);
lv_display_set_flush_cb(disp, my_disp_flush);
uint32_t bufferSize = screenWidth * screenHeight / 10 * 2;
draw_buf_1 = (uint8_t *)malloc(bufferSize);
draw_buf_2 = (uint8_t *)malloc(bufferSize);
if (draw_buf_1 == NULL || draw_buf_2 == NULL) {
Serial.println("FATAL: Out of RAM!");
return;
}
lv_display_set_buffers(disp, draw_buf_1, draw_buf_2, bufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);
lv_display_set_user_data(disp, this);
indev_touchpad = lv_indev_create();
lv_indev_set_type(indev_touchpad, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev_touchpad, my_touchpad_read);
lv_indev_set_user_data(indev_touchpad, this);
// BOOT THE SQUARELINE UI
ui_init();
brew_ser = lv_chart_add_series(ui_BrewChart, lv_color_hex(0xFF0000), LV_CHART_AXIS_PRIMARY_Y);
done_ser = lv_chart_add_series(ui_DoneChart, lv_color_hex(0xFF0000), LV_CHART_AXIS_PRIMARY_Y);
lv_label_set_text(ui_WarmupLabelSD, LV_SYMBOL_SD_CARD);
lv_label_set_text(ui_WarmupLabelWiFi, LV_SYMBOL_WIFI);
lv_label_set_text(ui_ReadyLabelSD, LV_SYMBOL_SD_CARD);
lv_label_set_text(ui_ReadyLabelWiFi, LV_SYMBOL_WIFI);
lv_label_set_text(ui_BrewLabelSD, LV_SYMBOL_SD_CARD);
lv_label_set_text(ui_BrewLabelWiFi, LV_SYMBOL_WIFI);
lv_label_set_text(ui_DoneLabelSD, LV_SYMBOL_SD_CARD);
lv_label_set_text(ui_DoneLabelWiFi, LV_SYMBOL_WIFI);
animateWarmupWave();
// Ready screen temp toggle button init
lv_obj_add_event_cb(ui_ReadyButtonTemp, temp_btn_event_cb, LV_EVENT_CLICKED, this);
lv_obj_add_flag(ui_ReadyLabelFlush, LV_OBJ_FLAG_HIDDEN); // No flush recommendation at startup on Ready screen (to avoid 1st frame flicker)
// Done screen
lv_obj_add_flag(ui_DoneLabelUploading, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_event_cb(ui_DoneSliderRate, done_rating_slider_cb, LV_EVENT_RELEASED, this);
// Settings button on Warmup and Ready only
lv_obj_add_event_cb(ui_WarmupBtnSettings, settings_btn_event_cb, LV_EVENT_CLICKED, this);
lv_obj_add_event_cb(ui_ReadyBtnSettings, settings_btn_event_cb, LV_EVENT_CLICKED, this);
lv_obj_add_flag(ui_BrewBtnSettings, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(ui_DoneBtnSettings, LV_OBJ_FLAG_HIDDEN);
// Settings screen buttons
lv_obj_add_event_cb(ui_SettingsButtonExit, settings_exit_btn_event_cb, LV_EVENT_CLICKED, this);
lv_obj_add_event_cb(ui_SettingsButtonClearLogs, settings_clear_logs_btn_event_cb, LV_EVENT_CLICKED, this);
lv_obj_add_event_cb(ui_SettingsDropdownMusicSelect, settings_music_cb, LV_EVENT_VALUE_CHANGED, this);
lv_obj_add_event_cb(ui_SettingsDropdownBoilerTemp, settings_boiler_temp_cb, LV_EVENT_VALUE_CHANGED, this);
lv_obj_add_event_cb(ui_SettingsDropdownGHTemp, settings_gh_temp_cb, LV_EVENT_VALUE_CHANGED, this);
// Heatsoak calibration spinbox — range 40–70°C, integer display
lv_spinbox_set_range(ui_SettingsSpinboxHeatsoak, 40, 70);
lv_spinbox_set_digit_format(ui_SettingsSpinboxHeatsoak, 2, 0);
lv_spinbox_set_value(ui_SettingsSpinboxHeatsoak, 50);
lv_obj_set_width(ui_SettingsSpinboxHeatsoak, 170);
lv_obj_add_flag(ui_SettingsSpinboxHeatsoak, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_event_cb(ui_SettingsSpinboxHeatsoak, settings_spinbox_calib_cb, LV_EVENT_VALUE_CHANGED, this);
lv_obj_t* parent = lv_obj_get_parent(ui_SettingsSpinboxHeatsoak);
_spbMinus = lv_button_create(parent);
_spbPlus = lv_button_create(parent);
lv_obj_set_size(_spbMinus, 35, 35);
lv_obj_set_size(_spbPlus, 35, 35);
lv_obj_align_to(_spbMinus, ui_SettingsSpinboxHeatsoak, LV_ALIGN_OUT_LEFT_MID, -5, 0);
lv_obj_align_to(_spbPlus, ui_SettingsSpinboxHeatsoak, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
lv_obj_center(lv_label_create(_spbMinus)); lv_label_set_text(lv_obj_get_child(_spbMinus, 0), "-");
lv_obj_center(lv_label_create(_spbPlus)); lv_label_set_text(lv_obj_get_child(_spbPlus, 0), "+");
lv_obj_add_flag(_spbMinus, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(_spbPlus, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_event_cb(_spbMinus, settings_spinbox_dec_cb, LV_EVENT_CLICKED, this);
lv_obj_add_event_cb(_spbPlus, settings_spinbox_inc_cb, LV_EVENT_CLICKED, this);
Serial.println("LVGL v9 Display Manager Initialized.");
}
// The static bridge function (v9 signature)
void DisplayManager::my_disp_flush(lv_display_t * disp, const lv_area_t * area, uint8_t * px_map) {
DisplayManager* manager = (DisplayManager*)lv_display_get_user_data(disp);
manager->flush_impl(disp, area, px_map);
}
// The actual drawing function
void DisplayManager::flush_impl(lv_display_t * disp, const lv_area_t * area, uint8_t * px_map) {
uint32_t w = lv_area_get_width(area);
uint32_t h = lv_area_get_height(area);
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
tft.pushColors((uint16_t *)px_map, w * h, true);
tft.endWrite();
lv_display_flush_ready(disp); // Tell LVGL v9 we are done
}
void DisplayManager::update() {
uint32_t currentMillis = millis();
lv_tick_inc(currentMillis - lastTickMillis);
lastTickMillis = currentMillis;
lv_timer_handler();
}
void DisplayManager::showStartupScreen() {
lv_obj_t * screen_main = lv_obj_create(NULL);
lv_obj_set_style_bg_color(screen_main, lv_color_black(), 0);
lv_obj_t * label_top = lv_label_create(screen_main);
lv_obj_set_style_text_color(label_top, lv_color_white(), 0);
lv_obj_set_style_text_font(label_top, &lv_font_montserrat_24, 0); // Big font
static lv_point_precise_t line_points[] = { {20, 90}, {300, 90} };
lv_obj_t * line_div = lv_line_create(screen_main);
lv_line_set_points(line_div, line_points, 2);
lv_obj_set_style_line_color(line_div, lv_color_white(), 0);
lv_obj_set_style_line_width(line_div, 2, 0);
lv_obj_t * label_main = lv_label_create(screen_main);
lv_obj_set_style_text_color(label_main, lv_color_white(), 0);
lv_obj_set_style_text_font(label_main, &lv_font_montserrat_48, 0); // Massive font
lv_screen_load(screen_main);
// Temporarily hide the dividing line
lv_obj_add_flag(line_div, LV_OBJ_FLAG_HIDDEN);
// Center the text for the splash screen
lv_label_set_text(label_top, "ESPRESSO");
lv_obj_align(label_top, LV_ALIGN_CENTER, 0, -30);
lv_label_set_text(label_main, "MONITOR");
lv_obj_align(label_main, LV_ALIGN_CENTER, 0, 30);
// Run the LVGL engine to draw the splash screen for 2 seconds
for(int i = 0; i < 200; i++) {
update();
delay(10);
}
// Unhide the line and move the labels back to their normal positions!
lv_obj_remove_flag(line_div, LV_OBJ_FLAG_HIDDEN);
lv_obj_align(label_top, LV_ALIGN_TOP_MID, 0, 20);
lv_obj_align(label_main, LV_ALIGN_TOP_MID, 0, 110);
// Clear the text so it's ready for the sensor loop
lv_label_set_text(label_top, "");
lv_label_set_text(label_main, "");
}
void DisplayManager::my_touchpad_read(lv_indev_t * indev, lv_indev_data_t * data) {
// Cast the user_data back to DisplayManager instance
DisplayManager* manager = (DisplayManager*)lv_indev_get_user_data(indev);
uint16_t touchX, touchY;
bool touched = manager->tft.getTouch(&touchX, &touchY);
if (!touched) {
data->state = LV_INDEV_STATE_RELEASED;
} else {
data->state = LV_INDEV_STATE_PRESSED;
// Feed the coordinates to LVGL
data->point.x = touchX;
data->point.y = touchY;
}
}
void DisplayManager::loadScreen(SystemState state) {
switch(state) {
case WARMUP:
lv_screen_load(ui_ScreenWarmup);
_warmupArcMin = -1;
break;
case READY: lv_screen_load(ui_ScreenReady); break;
case BREWING:{
lv_screen_load(ui_ScreenBrew);
// Start a fresh recording in the shared session.
if (session != nullptr) {
portENTER_CRITICAL(sessionMux);
session->pointCount = 0;
session->isComplete = false;
portEXIT_CRITICAL(sessionMux);
}
lastChartUpdate = millis();
lv_chart_set_point_count(ui_BrewChart, 2); // grows each second with actual data
lv_chart_set_all_value(ui_BrewChart, brew_ser, LV_CHART_POINT_NONE);
break;
}
case SETTINGS:{
lv_screen_load(ui_ScreenSettings);
lv_label_set_text(ui_SettingsLabelFWVerNum, "1.0");
if (_calibTemp) lv_spinbox_set_value(ui_SettingsSpinboxHeatsoak, _calibTemp->load());
// Reset cache so labels refresh with new SD stats from Core 0
_lastSettingsFreeMB = UINT32_MAX;
_lastSettingsBrewCount = -1;
break;
}
case DONE:{
lv_screen_load(ui_ScreenDone);
lv_slider_set_value(ui_DoneSliderRate, 4, LV_ANIM_OFF);
_doneRatingDirty = false;
lv_obj_add_flag(ui_DoneLabelUploading, LV_OBJ_FLAG_HIDDEN);
// Grab the point count once; the array is no longer being written
// (brewing has stopped) so we can copy it without holding the lock.
int count = 0;
if (session != nullptr) {
portENTER_CRITICAL(sessionMux);
count = session->pointCount;
portEXIT_CRITICAL(sessionMux);
}
int displayPoints = (count < 2) ? 2 : count;
lv_chart_set_point_count(ui_DoneChart, displayPoints);
// Crash Protection
if (done_ser != NULL && session != nullptr) {
// Wipe the chart clean of junk memory
lv_chart_set_all_value(ui_DoneChart, done_ser, LV_CHART_POINT_NONE);
// Safely shift the entire history into the chart
for(int i = 0; i < count; i++) {
lv_chart_set_next_value(ui_DoneChart, done_ser, (int)session->temperatures[i]);
}
}
break;
}
}
}
int DisplayManager::getDoneRating() {
return _doneRatingDirty ? (int)lv_slider_get_value(ui_DoneSliderRate) : -1;
}
void DisplayManager::done_rating_slider_cb(lv_event_t* e) {
DisplayManager* dm = (DisplayManager*)lv_event_get_user_data(e);
dm->_doneRatingDirty = true;
}
void DisplayManager::updateWarmupData(float boilerTemp, float estGroupheadTemp) {
char boilerStr[16];
snprintf(boilerStr, sizeof(boilerStr), "%.1f C", boilerTemp);
lv_label_set_text(ui_WarmupLabelBoilerTemp, boilerStr);
if (estGroupheadTemp == 0.0) {
lv_obj_set_y(ui_WarmupPanelTemp, 20);
lv_obj_add_flag(ui_WarmupBarWater, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(ui_WarmupPanelGrouphead, LV_OBJ_FLAG_HIDDEN);
lv_obj_remove_flag(ui_WarmupArcBoiler, LV_OBJ_FLAG_HIDDEN);
lv_arc_set_value(ui_WarmupArcBoiler, (int)boilerTemp);
} else {
lv_obj_set_y(ui_WarmupPanelTemp, -30);
lv_obj_remove_flag(ui_WarmupPanelGrouphead, LV_OBJ_FLAG_HIDDEN);
lv_obj_remove_flag(ui_WarmupBarWater, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(ui_WarmupArcBoiler, LV_OBJ_FLAG_HIDDEN);
char ghStr[16];
snprintf(ghStr, sizeof(boilerStr), "%.1f C", estGroupheadTemp);
lv_label_set_text(ui_WarmupLabelGroupheadTemp, ghStr);
}
// Thermodynamics Math (Clamp the temperature)
const float maxBoilerTemp = _boilerTarget ? (float)_boilerTarget->load() : 117.0f;
const float minTemp = 40.0;
const float maxTemp = _ghTarget ? (float)_ghTarget->load() : 90.0f;
if (_warmupArcMin < 0) _warmupArcMin = (int32_t)boilerTemp;
lv_arc_set_range(ui_WarmupArcBoiler, _warmupArcMin, (int32_t)maxBoilerTemp);
float clampedTemp = estGroupheadTemp;
if (clampedTemp < minTemp) clampedTemp = minTemp;
if (clampedTemp > maxTemp) clampedTemp = maxTemp;
// Calculate how "full" the tank should be (0.0 to 1.0)
float heatPercentage = (clampedTemp - minTemp) / (maxTemp - minTemp);
float boilerHeatPercentage = (boilerTemp - _warmupArcMin) / (maxBoilerTemp - _warmupArcMin);
int waveHeight = (screenHeight + 18) / 2; // (screen height + wave height) / 2
// The solid water box grows from the bottom up based on temperature
int waterHeight = (int)(heatPercentage * screenHeight);
lv_bar_set_value(ui_WarmupBarWater, waterHeight, LV_ANIM_OFF);
// Calculate where the top of that water box is
// down by subtracting the water height and its own height from the total.
int waveY = screenHeight - waterHeight - waveHeight;
// Prevent the wave from clipping through the bottom of the screen when totally cold
if (waveY > (screenHeight - waveHeight)) {
waveY = screenHeight - waveHeight;
}
// lv_obj_set_height(ui_WarmupPanelWater, waterHeight);
lv_obj_set_y(ui_WarmupImgWave, waveY);
// Color Blending (Blue to Red)
uint8_t mixRatio = (uint8_t)(heatPercentage * 255.0);
lv_color_t fluidColor = lv_color_mix(lv_color_hex(0xFF0000), lv_color_hex(0x0000FF), mixRatio);
mixRatio = (uint8_t)(boilerHeatPercentage * 255.0);
lv_color_t arcColor = lv_color_mix(lv_color_hex(0xFF0000), lv_color_hex(0x0000FF), mixRatio);
lv_obj_set_style_arc_color(ui_WarmupArcBoiler, arcColor, LV_PART_INDICATOR);
// Apply the exact same tint to both the solid box and the white wave cap
lv_obj_set_style_bg_color(ui_WarmupBarWater, fluidColor, LV_PART_INDICATOR);
lv_obj_set_style_image_recolor(ui_WarmupImgWave, fluidColor, 0);
}
void DisplayManager::updateReadyData(float boilerTemp, float estGroupheadTemp, const char* minutes, const char* seconds) {
char tempStr[16];
if (showingBoilerTemp) {
snprintf(tempStr, sizeof(tempStr), "%.1f C", boilerTemp);
} else {
snprintf(tempStr, sizeof(tempStr), "%.1f C", estGroupheadTemp);
}
// recommend a hot flush at 1.03 * target GH temp
int maxWantedGHTemp = (int)((_ghTarget ? _ghTarget->load() : 91) * 1.03f);
if (estGroupheadTemp <= maxWantedGHTemp){
lv_obj_add_flag(ui_ReadyLabelFlush, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_remove_flag(ui_ReadyLabelFlush, LV_OBJ_FLAG_HIDDEN);
}
lv_label_set_text(ui_ReadyLabelTimeSeconds, seconds);
lv_label_set_text(ui_ReadyLabelTimeMinutes, minutes);
lv_label_set_text(ui_ReadyLabelTemp, tempStr);
}
void DisplayManager::updateBrewData(const char* seconds, const char* tenths, float temp) {
lv_label_set_text(ui_BrewLabelTimeTenths, tenths);
lv_label_set_text(ui_BrewLabelTimeSeconds, seconds);
char boilerStr[16];
snprintf(boilerStr, sizeof(boilerStr), "%.1f C", temp);
lv_label_set_text(ui_BrewLabelTemp, boilerStr);
// SYNCHRONIZED LOGGING: Only fire when the 'seconds' timer rolls over
static char lastSecond = 'X';
if (seconds[1] != lastSecond) {
lastSecond = seconds[1];
// Save to the shared session (guarded; Core 0 may read it).
if (session != nullptr) {
portENTER_CRITICAL(sessionMux);
if (session->pointCount < BREW_MAX_POINTS) {
session->temperatures[session->pointCount] = temp;
session->pointCount++;
}
portEXIT_CRITICAL(sessionMux);
}
// Resize chart to actual sample count so X axis matches brew duration
if (brew_ser != nullptr && session != nullptr) {
int n = session->pointCount;
int displayN = (n < 2) ? 2 : n;
lv_chart_set_point_count(ui_BrewChart, displayN);
lv_chart_set_all_value(ui_BrewChart, brew_ser, LV_CHART_POINT_NONE);
for (int i = 0; i < n; i++) {
lv_chart_set_next_value(ui_BrewChart, brew_ser, (int)session->temperatures[i]);
}
}
}
}
void DisplayManager::setBrewSession(BrewSession * s, portMUX_TYPE * mux) {
session = s;
sessionMux = mux;
}
void DisplayManager::setSettingsPointers(SystemState* cur, SystemState* prev, std::atomic<bool>* clearFlag) {
_currentState = cur;
_previousState = prev;
_requestLogClear = clearFlag;
}
void DisplayManager::updateSettingsData(uint32_t freeMB, int brewCount) {
bool calib = _calibAvailable && _calibAvailable->load();
auto setHidden = [](lv_obj_t* o, bool hide) {
if (!o) return;
hide ? lv_obj_add_flag(o, LV_OBJ_FLAG_HIDDEN) : lv_obj_remove_flag(o, LV_OBJ_FLAG_HIDDEN);
};
setHidden(ui_SettingsSpinboxHeatsoak, !calib);
setHidden(_spbPlus, !calib);
setHidden(_spbMinus, !calib);
if (freeMB != _lastSettingsFreeMB) {
char buf[16];
snprintf(buf, sizeof(buf), "%lu MB", freeMB);
lv_label_set_text(ui_SettingsLabelSDFree, buf);
_lastSettingsFreeMB = freeMB;
}
if (brewCount != _lastSettingsBrewCount) {
char buf[8];
snprintf(buf, sizeof(buf), "%d", brewCount);
lv_label_set_text(ui_SettingsLabelBrewCountNum, buf);
_lastSettingsBrewCount = brewCount;
}
}
void DisplayManager::settings_btn_event_cb(lv_event_t* e) {
DisplayManager* dm = (DisplayManager*)lv_event_get_user_data(e);
if (!dm->_currentState || !dm->_previousState) return;
*dm->_previousState = *dm->_currentState;
*dm->_currentState = SETTINGS;
dm->loadScreen(SETTINGS);
}
void DisplayManager::settings_exit_btn_event_cb(lv_event_t* e) {
DisplayManager* dm = (DisplayManager*)lv_event_get_user_data(e);
if (!dm->_currentState || !dm->_previousState) return;
SystemState ret = *dm->_previousState;
*dm->_currentState = ret;
dm->loadScreen(ret);
}
void DisplayManager::settings_clear_logs_btn_event_cb(lv_event_t* e) {
DisplayManager* dm = (DisplayManager*)lv_event_get_user_data(e);
if (dm->_requestLogClear) *dm->_requestLogClear = true;
}
void DisplayManager::settings_music_cb(lv_event_t* e) {
DisplayManager* dm = (DisplayManager*)lv_event_get_user_data(e);
if (dm->_musicSelect) {
dm->_musicSelect->store((int)lv_dropdown_get_selected((lv_obj_t*)lv_event_get_target(e)));
}
}
void DisplayManager::setMusicSelectPointer(std::atomic<int>* sel) {
_musicSelect = sel;
}
void DisplayManager::setMusicDropdown(int index) {
lv_dropdown_set_selected(ui_SettingsDropdownMusicSelect, (uint16_t)index);
}
void DisplayManager::setTempTargetPointers(std::atomic<int>* boiler, std::atomic<int>* gh) {
_boilerTarget = boiler;
_ghTarget = gh;
}
void DisplayManager::setBoilerTargetDropdown(int temp) {
lv_dropdown_set_selected(ui_SettingsDropdownBoilerTemp, (uint16_t)(temp - 115));
}
void DisplayManager::setGHTargetDropdown(int temp) {
lv_dropdown_set_selected(ui_SettingsDropdownGHTemp, (uint16_t)(temp - 85));
}
void DisplayManager::settings_boiler_temp_cb(lv_event_t* e) {
DisplayManager* dm = (DisplayManager*)lv_event_get_user_data(e);
if (dm->_boilerTarget)
dm->_boilerTarget->store(115 + (int)lv_dropdown_get_selected((lv_obj_t*)lv_event_get_target(e)));
Serial.print("new boiler temp target: ");
Serial.println(115 + (int)lv_dropdown_get_selected((lv_obj_t*)lv_event_get_target(e)));
}
void DisplayManager::settings_gh_temp_cb(lv_event_t* e) {
DisplayManager* dm = (DisplayManager*)lv_event_get_user_data(e);
if (dm->_ghTarget)
dm->_ghTarget->store(85 + (int)lv_dropdown_get_selected((lv_obj_t*)lv_event_get_target(e)));
Serial.print("new grouphead temp target: ");
Serial.println(85 + (int)lv_dropdown_get_selected((lv_obj_t*)lv_event_get_target(e)));
}
void DisplayManager::settings_spinbox_inc_cb(lv_event_t* e) {
lv_spinbox_increment(ui_SettingsSpinboxHeatsoak);
}
void DisplayManager::settings_spinbox_dec_cb(lv_event_t* e) {
lv_spinbox_decrement(ui_SettingsSpinboxHeatsoak);
}
void DisplayManager::settings_spinbox_calib_cb(lv_event_t* e) {
DisplayManager* dm = (DisplayManager*)lv_event_get_user_data(e);
if (dm->_calibTemp)
dm->_calibTemp->store((int)lv_spinbox_get_value(ui_SettingsSpinboxHeatsoak));
}
void DisplayManager::setCalibPointers(std::atomic<int>* temp, std::atomic<bool>* available) {
_calibTemp = temp;
_calibAvailable = available;
}
void DisplayManager::updateDoneData(const char* seconds, const char* tenths) {
lv_label_set_text(ui_DoneLabelTimeTenths, tenths);
lv_label_set_text(ui_DoneLabelTimeSeconds, seconds);
}
void DisplayManager::showDoneUploading(bool show) {
if (show) {
lv_obj_remove_flag(ui_DoneLabelUploading, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_add_flag(ui_DoneLabelUploading, LV_OBJ_FLAG_HIDDEN);
}
}
void DisplayManager::animateWarmupWave() {
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, ui_WarmupImgWave);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x);
lv_anim_set_values(&a, 80, -80);
lv_anim_set_duration(&a, 4000);
// constant speed
lv_anim_set_path_cb(&a, lv_anim_path_linear);
// loop infinitely
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
// Start the engine
lv_anim_start(&a);
}
void DisplayManager::temp_btn_event_cb(lv_event_t * e) {
// Retrieve the DisplayManager instance
DisplayManager* manager = (DisplayManager*)lv_event_get_user_data(e);
// Toggle the state
manager->showingBoilerTemp = !manager->showingBoilerTemp;
}
void DisplayManager::setSDState(bool isConnected) {
this->SDStatus = isConnected;
lv_color_t color = isConnected ? lv_color_hex(0xFFFFFF) : lv_color_hex(0xFF0000);
lv_obj_set_style_text_color(ui_WarmupLabelSD, color, 0);
lv_obj_set_style_text_color(ui_ReadyLabelSD, color, 0);
lv_obj_set_style_text_color(ui_BrewLabelSD, color, 0);
lv_obj_set_style_text_color(ui_DoneLabelSD, color, 0);
}
void DisplayManager::setWifiState(bool isConnected) {
this->WifiStatus = isConnected;
lv_color_t color = isConnected ? lv_color_hex(0xFFFFFF) : lv_color_hex(0xFF0000);
lv_obj_set_style_text_color(ui_WarmupLabelWiFi, color, 0);
lv_obj_set_style_text_color(ui_ReadyLabelWiFi, color, 0);
lv_obj_set_style_text_color(ui_BrewLabelWiFi, color, 0);
lv_obj_set_style_text_color(ui_DoneLabelWiFi, color, 0);
}