@@ -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