Skip to content

Commit 889b2f9

Browse files
committed
cleanup
1 parent fed2804 commit 889b2f9

File tree

1 file changed

+39
-57
lines changed

1 file changed

+39
-57
lines changed

src/sp140/lvgl/lvgl_display.cpp

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,39 @@ static lv_timer_t* alert_cycle_timer = NULL;
118118
static AlertSnapshot currentSnap{};
119119
static uint8_t currentIdx = 0;
120120

121+
// Helper function to hide/show all altitude character labels
122+
void setAltitudeVisibility(bool visible) {
123+
for (int i = 0; i < 7; i++) {
124+
if (altitude_char_labels[i]) {
125+
if (visible) {
126+
lv_obj_clear_flag(altitude_char_labels[i], LV_OBJ_FLAG_HIDDEN);
127+
} else {
128+
lv_obj_add_flag(altitude_char_labels[i], LV_OBJ_FLAG_HIDDEN);
129+
}
130+
}
131+
}
132+
}
133+
134+
// Helper function to create temperature background rectangles
135+
lv_obj_t* createTempBackground(lv_obj_t* parent, int x, int y, int width, int height) {
136+
lv_obj_t* bg = lv_obj_create(parent);
137+
lv_obj_set_size(bg, width, height);
138+
lv_obj_set_pos(bg, x, y);
139+
lv_obj_set_style_border_width(bg, 0, LV_PART_MAIN);
140+
lv_obj_set_style_radius(bg, 0, LV_PART_MAIN);
141+
lv_obj_set_style_bg_opa(bg, LV_OPA_0, LV_PART_MAIN);
142+
lv_obj_set_style_shadow_width(bg, 0, LV_PART_MAIN);
143+
lv_obj_set_style_outline_width(bg, 0, LV_PART_MAIN);
144+
lv_obj_set_style_pad_all(bg, 0, LV_PART_MAIN);
145+
lv_obj_set_style_border_opa(bg, LV_OPA_0, LV_PART_MAIN);
146+
lv_obj_set_style_outline_opa(bg, LV_OPA_0, LV_PART_MAIN);
147+
lv_obj_set_style_shadow_opa(bg, LV_OPA_0, LV_PART_MAIN);
148+
lv_obj_move_background(bg);
149+
lv_obj_add_flag(bg, LV_OBJ_FLAG_HIDDEN);
150+
return bg;
151+
}
152+
153+
121154
void loadAlertSnapshot(const AlertSnapshot& snap) {
122155
currentSnap = snap;
123156
currentIdx = 0;
@@ -566,52 +599,13 @@ void setupMainScreen(bool darkMode) {
566599

567600
// Create temperature background rectangles first (behind text)
568601
// Battery temperature background (top section: Y=70 to Y=89, X=117 to X=148)
569-
batt_temp_bg = lv_obj_create(main_screen);
570-
lv_obj_set_size(batt_temp_bg, 31, 19); // Width: 148-117=31, Height: 89-70=19
571-
lv_obj_set_pos(batt_temp_bg, 117, 70);
572-
lv_obj_set_style_border_width(batt_temp_bg, 0, LV_PART_MAIN);
573-
lv_obj_set_style_radius(batt_temp_bg, 0, LV_PART_MAIN);
574-
lv_obj_set_style_bg_opa(batt_temp_bg, LV_OPA_0, LV_PART_MAIN); // Initially transparent
575-
lv_obj_set_style_shadow_width(batt_temp_bg, 0, LV_PART_MAIN); // No shadow
576-
lv_obj_set_style_outline_width(batt_temp_bg, 0, LV_PART_MAIN); // No outline
577-
lv_obj_set_style_pad_all(batt_temp_bg, 0, LV_PART_MAIN); // No padding
578-
lv_obj_set_style_border_opa(batt_temp_bg, LV_OPA_0, LV_PART_MAIN); // Transparent border
579-
lv_obj_set_style_outline_opa(batt_temp_bg, LV_OPA_0, LV_PART_MAIN); // Transparent outline
580-
lv_obj_set_style_shadow_opa(batt_temp_bg, LV_OPA_0, LV_PART_MAIN); // Transparent shadow
581-
lv_obj_move_background(batt_temp_bg); // Move to background layer
582-
lv_obj_add_flag(batt_temp_bg, LV_OBJ_FLAG_HIDDEN); // Hide by default, show only when highlighting
602+
batt_temp_bg = createTempBackground(main_screen, 117, 70, 31, 19);
583603

584604
// ESC temperature background (middle section: Y=89 to Y=109, X=117 to X=148)
585-
esc_temp_bg = lv_obj_create(main_screen);
586-
lv_obj_set_size(esc_temp_bg, 31, 20); // Width: 148-117=31, Height: 109-89=20
587-
lv_obj_set_pos(esc_temp_bg, 117, 89);
588-
lv_obj_set_style_border_width(esc_temp_bg, 0, LV_PART_MAIN);
589-
lv_obj_set_style_radius(esc_temp_bg, 0, LV_PART_MAIN);
590-
lv_obj_set_style_bg_opa(esc_temp_bg, LV_OPA_0, LV_PART_MAIN); // Initially transparent
591-
lv_obj_set_style_shadow_width(esc_temp_bg, 0, LV_PART_MAIN); // No shadow
592-
lv_obj_set_style_outline_width(esc_temp_bg, 0, LV_PART_MAIN); // No outline
593-
lv_obj_set_style_pad_all(esc_temp_bg, 0, LV_PART_MAIN); // No padding
594-
lv_obj_set_style_border_opa(esc_temp_bg, LV_OPA_0, LV_PART_MAIN); // Transparent border
595-
lv_obj_set_style_outline_opa(esc_temp_bg, LV_OPA_0, LV_PART_MAIN); // Transparent outline
596-
lv_obj_set_style_shadow_opa(esc_temp_bg, LV_OPA_0, LV_PART_MAIN); // Transparent shadow
597-
lv_obj_move_background(esc_temp_bg); // Move to background layer
598-
lv_obj_add_flag(esc_temp_bg, LV_OBJ_FLAG_HIDDEN); // Hide by default, show only when highlighting
605+
esc_temp_bg = createTempBackground(main_screen, 117, 89, 31, 20);
599606

600607
// Motor temperature background (bottom section: Y=109 to Y=128, X=117 to X=148)
601-
motor_temp_bg = lv_obj_create(main_screen);
602-
lv_obj_set_size(motor_temp_bg, 31, 19); // Width: 148-117=31, Height: 128-109=19
603-
lv_obj_set_pos(motor_temp_bg, 117, 109);
604-
lv_obj_set_style_border_width(motor_temp_bg, 0, LV_PART_MAIN);
605-
lv_obj_set_style_radius(motor_temp_bg, 0, LV_PART_MAIN);
606-
lv_obj_set_style_bg_opa(motor_temp_bg, LV_OPA_0, LV_PART_MAIN); // Initially transparent
607-
lv_obj_set_style_shadow_width(motor_temp_bg, 0, LV_PART_MAIN); // No shadow
608-
lv_obj_set_style_outline_width(motor_temp_bg, 0, LV_PART_MAIN); // No outline
609-
lv_obj_set_style_pad_all(motor_temp_bg, 0, LV_PART_MAIN); // No padding
610-
lv_obj_set_style_border_opa(motor_temp_bg, LV_OPA_0, LV_PART_MAIN); // Transparent border
611-
lv_obj_set_style_outline_opa(motor_temp_bg, LV_OPA_0, LV_PART_MAIN); // Transparent outline
612-
lv_obj_set_style_shadow_opa(motor_temp_bg, LV_OPA_0, LV_PART_MAIN); // Transparent shadow
613-
lv_obj_move_background(motor_temp_bg); // Move to background layer
614-
lv_obj_add_flag(motor_temp_bg, LV_OBJ_FLAG_HIDDEN); // Hide by default, show only when highlighting
608+
motor_temp_bg = createTempBackground(main_screen, 117, 109, 31, 19);
615609

616610
// Create temperature labels - adjust positions to align with divider lines
617611
batt_temp_label = lv_label_create(main_screen);
@@ -1388,23 +1382,15 @@ void lv_showAlertTextWithLevel(SensorID id, AlertLevel level, bool critical) {
13881382
if (critical) {
13891383
lv_obj_set_style_text_font(alert_text_label, &lv_font_montserrat_18, 0);
13901384
// Hide altitude while showing critical alert
1391-
for (int i = 0; i < 7; i++) {
1392-
if (altitude_char_labels[i]) {
1393-
lv_obj_add_flag(altitude_char_labels[i], LV_OBJ_FLAG_HIDDEN);
1394-
}
1395-
}
1385+
setAltitudeVisibility(false);
13961386
// Move alert label to altitude position (using first altitude character as reference)
13971387
if (altitude_char_labels[0]) {
13981388
lv_obj_set_pos(alert_text_label, lv_obj_get_x(altitude_char_labels[0]), lv_obj_get_y(altitude_char_labels[0]));
13991389
}
14001390
} else {
14011391
lv_obj_set_style_text_font(alert_text_label, &lv_font_montserrat_14, 0);
14021392
// Ensure altitude visible during warnings
1403-
for (int i = 0; i < 7; i++) {
1404-
if (altitude_char_labels[i]) {
1405-
lv_obj_clear_flag(altitude_char_labels[i], LV_OBJ_FLAG_HIDDEN);
1406-
}
1407-
}
1393+
setAltitudeVisibility(true);
14081394
// Re-align warning text next to circles
14091395
if (warning_counter_circle) {
14101396
lv_obj_align_to(alert_text_label, warning_counter_circle, LV_ALIGN_OUT_RIGHT_MID, 4, 0);
@@ -1424,11 +1410,7 @@ void lv_hideAlertText() {
14241410
if (alert_text_label == NULL) return;
14251411
lv_obj_add_flag(alert_text_label, LV_OBJ_FLAG_HIDDEN);
14261412
// Restore altitude visibility when no critical alert
1427-
for (int i = 0; i < 7; i++) {
1428-
if (altitude_char_labels[i]) {
1429-
lv_obj_clear_flag(altitude_char_labels[i], LV_OBJ_FLAG_HIDDEN);
1430-
}
1431-
}
1413+
setAltitudeVisibility(true);
14321414
}
14331415

14341416
void updateLvglMainScreen(

0 commit comments

Comments
 (0)