Skip to content

Commit 62491f1

Browse files
committed
optimize temperature UI styles
1 parent 46cb858 commit 62491f1

File tree

3 files changed

+50
-78
lines changed

3 files changed

+50
-78
lines changed

inc/sp140/lvgl/lvgl_main_screen.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ enum ScreenPage {
3434
#define CELL_VOLTAGE_WARNING 3.2f
3535
#define CELL_VOLTAGE_CRITICAL 2.95f
3636

37+
// LVGL styles for temperature warnings and critical states
38+
extern lv_style_t style_warning;
39+
extern lv_style_t style_critical;
40+
3741
// Main screen objects
3842
extern lv_obj_t* main_screen;
3943
extern lv_obj_t* battery_bar;

src/sp140/lvgl/lvgl_main_screen.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
// External font declaration
1111
extern const lv_font_t roboto_mono_16;
1212

13+
// LVGL styles for temperature warnings and critical states
14+
lv_style_t style_warning;
15+
lv_style_t style_critical;
16+
1317
// Main screen objects - definitions
1418
lv_obj_t* main_screen = NULL;
1519
lv_obj_t* battery_bar = NULL;
@@ -81,6 +85,21 @@ lv_obj_t* createTempBackground(lv_obj_t* parent, int x, int y, int width, int he
8185
return bg;
8286
}
8387

88+
// Function to initialize styles
89+
void init_temp_styles(bool darkMode) {
90+
// Warning style (yellow background, black text)
91+
lv_style_init(&style_warning);
92+
lv_style_set_bg_color(&style_warning, LVGL_YELLOW);
93+
lv_style_set_text_color(&style_warning, LVGL_BLACK);
94+
lv_style_set_bg_opa(&style_warning, LV_OPA_100);
95+
96+
// Critical style (red background, black text)
97+
lv_style_init(&style_critical);
98+
lv_style_set_bg_color(&style_critical, LVGL_RED);
99+
lv_style_set_text_color(&style_critical, LVGL_BLACK);
100+
lv_style_set_bg_opa(&style_critical, LV_OPA_100);
101+
}
102+
84103
// Function to show the loading overlay
85104
void showLoadingOverlay() {
86105
if (spinner_overlay != NULL) {
@@ -614,6 +633,9 @@ void setupMainScreen(bool darkMode) {
614633
// Setup alert counter UI elements (circles, labels, and alert text display)
615634
setupAlertCounterUI(darkMode);
616635

636+
// Initialize custom styles
637+
init_temp_styles(darkMode);
638+
617639
// Load the screen
618640
lv_scr_load(main_screen);
619641
}

src/sp140/lvgl/lvgl_updates.cpp

Lines changed: 24 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -609,124 +609,70 @@ void updateLvglMainScreen(
609609
// Update temperature labels
610610
// -- Battery Temperature --
611611
if (batt_temp_label != NULL && batt_letter_label != NULL) { // Check labels exist
612-
lv_color_t bg_color = LVGL_BLACK; // Default, will be overridden if opaque
613-
lv_color_t text_color = darkMode ? LVGL_WHITE : LVGL_BLACK;
614-
lv_opa_t bg_opacity = LV_OPA_0; // Default transparent
612+
lv_obj_remove_style(batt_temp_bg, &style_warning, 0);
613+
lv_obj_remove_style(batt_temp_bg, &style_critical, 0);
615614

616615
if (bmsTelemetry.bmsState == TelemetryState::CONNECTED) {
617616
lv_label_set_text_fmt(batt_temp_label, "%d", static_cast<int>(batteryTemp));
618617

619618
if (batteryTemp >= BATT_TEMP_CRITICAL) {
620-
bg_color = LVGL_RED;
621-
text_color = LVGL_BLACK;
622-
bg_opacity = LV_OPA_100;
619+
lv_obj_add_style(batt_temp_bg, &style_critical, 0);
620+
lv_obj_clear_flag(batt_temp_bg, LV_OBJ_FLAG_HIDDEN);
623621
} else if (batteryTemp >= BATT_TEMP_WARNING) {
624-
bg_color = LVGL_YELLOW;
625-
text_color = LVGL_BLACK;
626-
bg_opacity = LV_OPA_100;
627-
}
628-
} else {
629-
lv_label_set_text(batt_temp_label, "-");
630-
}
631-
632-
lv_obj_set_style_bg_opa(batt_temp_label, LV_OPA_0, 0); // Keep label background transparent
633-
lv_obj_set_style_bg_opa(batt_letter_label, LV_OPA_0, 0); // Keep letter background transparent
634-
lv_obj_set_style_text_color(batt_temp_label, text_color, 0);
635-
lv_obj_set_style_text_color(batt_letter_label, darkMode ? LVGL_WHITE : LVGL_BLACK, 0); // Keep letter normal color
636-
637-
// Apply highlighting to the full background rectangle
638-
if (batt_temp_bg != NULL) {
639-
if (bg_opacity > 0) {
640-
// Show background and set color when highlighting is needed
622+
lv_obj_add_style(batt_temp_bg, &style_warning, 0);
641623
lv_obj_clear_flag(batt_temp_bg, LV_OBJ_FLAG_HIDDEN);
642-
lv_obj_set_style_bg_opa(batt_temp_bg, bg_opacity, LV_PART_MAIN);
643-
lv_obj_set_style_bg_color(batt_temp_bg, bg_color, LV_PART_MAIN);
644624
} else {
645-
// Hide background when no highlighting is needed
646625
lv_obj_add_flag(batt_temp_bg, LV_OBJ_FLAG_HIDDEN);
647626
}
627+
} else {
628+
lv_label_set_text(batt_temp_label, "-");
629+
lv_obj_add_flag(batt_temp_bg, LV_OBJ_FLAG_HIDDEN);
648630
}
649631
}
650632

651633
// -- ESC Temperature --
652634
if (esc_temp_label != NULL && esc_letter_label != NULL) { // Check labels exist
653-
lv_color_t bg_color = LVGL_BLACK;
654-
lv_color_t text_color = darkMode ? LVGL_WHITE : LVGL_BLACK;
655-
lv_opa_t bg_opacity = LV_OPA_0;
635+
lv_obj_remove_style(esc_temp_bg, &style_warning, 0);
636+
lv_obj_remove_style(esc_temp_bg, &style_critical, 0);
656637

657638
if (escTelemetry.escState == TelemetryState::CONNECTED) {
658639
lv_label_set_text_fmt(esc_temp_label, "%d", static_cast<int>(escTemp));
659640

660641
if (escTemp >= ESC_TEMP_CRITICAL) {
661-
bg_color = LVGL_RED;
662-
text_color = LVGL_BLACK;
663-
bg_opacity = LV_OPA_100;
642+
lv_obj_add_style(esc_temp_bg, &style_critical, 0);
643+
lv_obj_clear_flag(esc_temp_bg, LV_OBJ_FLAG_HIDDEN);
664644
} else if (escTemp >= ESC_TEMP_WARNING) {
665-
bg_color = LVGL_YELLOW;
666-
text_color = LVGL_BLACK;
667-
bg_opacity = LV_OPA_100;
668-
}
669-
} else {
670-
lv_label_set_text(esc_temp_label, "-");
671-
}
672-
673-
lv_obj_set_style_bg_opa(esc_temp_label, LV_OPA_0, 0); // Keep label background transparent
674-
lv_obj_set_style_bg_opa(esc_letter_label, LV_OPA_0, 0); // Keep letter background transparent
675-
lv_obj_set_style_text_color(esc_temp_label, text_color, 0);
676-
lv_obj_set_style_text_color(esc_letter_label, darkMode ? LVGL_WHITE : LVGL_BLACK, 0); // Keep letter normal color
677-
678-
// Apply highlighting to the full background rectangle
679-
if (esc_temp_bg != NULL) {
680-
if (bg_opacity > 0) {
681-
// Show background and set color when highlighting is needed
645+
lv_obj_add_style(esc_temp_bg, &style_warning, 0);
682646
lv_obj_clear_flag(esc_temp_bg, LV_OBJ_FLAG_HIDDEN);
683-
lv_obj_set_style_bg_opa(esc_temp_bg, bg_opacity, LV_PART_MAIN);
684-
lv_obj_set_style_bg_color(esc_temp_bg, bg_color, LV_PART_MAIN);
685647
} else {
686-
// Hide background when no highlighting is needed
687648
lv_obj_add_flag(esc_temp_bg, LV_OBJ_FLAG_HIDDEN);
688649
}
650+
} else {
651+
lv_label_set_text(esc_temp_label, "-");
652+
lv_obj_add_flag(esc_temp_bg, LV_OBJ_FLAG_HIDDEN);
689653
}
690654
}
691655

692656
// -- Motor Temperature --
693657
if (motor_temp_label != NULL && motor_letter_label != NULL) { // Check labels exist
694-
lv_color_t bg_color = LVGL_BLACK;
695-
lv_color_t text_color = darkMode ? LVGL_WHITE : LVGL_BLACK;
696-
lv_opa_t bg_opacity = LV_OPA_0;
658+
lv_obj_remove_style(motor_temp_bg, &style_warning, 0);
659+
lv_obj_remove_style(motor_temp_bg, &style_critical, 0);
697660

698661
if (escTelemetry.escState == TelemetryState::CONNECTED && motorTemp > -20.0f) {
699662
lv_label_set_text_fmt(motor_temp_label, "%d", static_cast<int>(motorTemp));
700663

701664
if (motorTemp >= MOTOR_TEMP_CRITICAL) {
702-
bg_color = LVGL_RED;
703-
text_color = LVGL_BLACK;
704-
bg_opacity = LV_OPA_100;
665+
lv_obj_add_style(motor_temp_bg, &style_critical, 0);
666+
lv_obj_clear_flag(motor_temp_bg, LV_OBJ_FLAG_HIDDEN);
705667
} else if (motorTemp >= MOTOR_TEMP_WARNING) {
706-
bg_color = LVGL_YELLOW;
707-
text_color = LVGL_BLACK;
708-
bg_opacity = LV_OPA_100;
709-
}
710-
} else {
711-
lv_label_set_text(motor_temp_label, "-");
712-
}
713-
714-
lv_obj_set_style_bg_opa(motor_temp_label, LV_OPA_0, 0); // Keep label background transparent
715-
lv_obj_set_style_bg_opa(motor_letter_label, LV_OPA_0, 0); // Keep letter background transparent
716-
lv_obj_set_style_text_color(motor_temp_label, text_color, 0);
717-
lv_obj_set_style_text_color(motor_letter_label, darkMode ? LVGL_WHITE : LVGL_BLACK, 0); // Keep letter normal color
718-
719-
// Apply highlighting to the full background rectangle
720-
if (motor_temp_bg != NULL) {
721-
if (bg_opacity > 0) {
722-
// Show background and set color when highlighting is needed
668+
lv_obj_add_style(motor_temp_bg, &style_warning, 0);
723669
lv_obj_clear_flag(motor_temp_bg, LV_OBJ_FLAG_HIDDEN);
724-
lv_obj_set_style_bg_opa(motor_temp_bg, bg_opacity, LV_PART_MAIN);
725-
lv_obj_set_style_bg_color(motor_temp_bg, bg_color, LV_PART_MAIN);
726670
} else {
727-
// Hide background when no highlighting is needed
728671
lv_obj_add_flag(motor_temp_bg, LV_OBJ_FLAG_HIDDEN);
729672
}
673+
} else {
674+
lv_label_set_text(motor_temp_label, "-");
675+
lv_obj_add_flag(motor_temp_bg, LV_OBJ_FLAG_HIDDEN);
730676
}
731677
}
732678

0 commit comments

Comments
 (0)