ui: battery: add menu entry to select between icon or percentage

This commit is contained in:
romanat 2025-09-06 22:02:44 -03:00 committed by Silvano Seva
parent 6aecd2b727
commit 3add35275c
8 changed files with 31 additions and 8 deletions

View File

@ -62,6 +62,7 @@ typedef struct
_reserved : 3;
bool m17_can_rx; // Check M17 CAN on RX
char m17_dest[10]; // M17 destination
bool showBatteryIcon; // Battery display true: icon, false: percentage
}
__attribute__((packed)) settings_t;
@ -86,7 +87,8 @@ static const settings_t default_settings =
1, // Automatic latch of macro menu enabled
0, // not used
false, // Check M17 CAN on RX
"" // Empty M17 destination
"", // Empty M17 destination
false, // Display battery icon
};
#endif /* SETTINGS_H */

View File

@ -96,5 +96,6 @@ const stringsTable_t englishStrings =
.frequencyOffset = "Frequency Offset",
.macroLatching = "Macro Latching",
.noGps = "No GPS",
.batteryIcon = "Battery Icon",
};
#endif // ENGLISHSTRINGS_H

View File

@ -97,5 +97,6 @@ const stringsTable_t spanishStrings =
.frequencyOffset = "Offset de frecuencia",
.macroLatching = "Macro Latching",
.noGps = "Ningún GPS",
.batteryIcon = "Icon de batteria",
};
#endif // SPANISHSTRINGS_H

View File

@ -120,6 +120,7 @@ enum displayItems
D_CONTRAST,
#endif
D_TIMER,
D_BATTERY
};
#ifdef CONFIG_GPS

View File

@ -100,6 +100,7 @@ typedef struct
const char* frequencyOffset;
const char* macroLatching;
const char* noGps;
const char* batteryIcon;
}
stringsTable_t;

View File

@ -157,7 +157,8 @@ const char *display_items[] =
#ifdef CONFIG_SCREEN_CONTRAST
"Contrast",
#endif
"Timer"
"Timer",
"Battery Icon"
};
#ifdef CONFIG_GPS
@ -2069,6 +2070,9 @@ void ui_updateFSM(bool *sync_rtx)
_ui_changeTimer(-1);
vp_announceDisplayTimer();
break;
case D_BATTERY:
state.settings.showBatteryIcon = !state.settings.showBatteryIcon;
break;
default:
state.ui_screen = SETTINGS_DISPLAY;
}

View File

@ -50,12 +50,19 @@ void _ui_drawMainTop(ui_state_t * ui_state)
gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_RIGHT,
color_white,"%.1fV", last_state.v_bat);
#else
// Otherwise print battery icon on top bar, use 4 px padding
uint16_t bat_width = CONFIG_SCREEN_WIDTH / 9;
uint16_t bat_height = layout.top_h - (layout.status_v_pad * 2);
point_t bat_pos = {CONFIG_SCREEN_WIDTH - bat_width - layout.horizontal_pad,
layout.status_v_pad};
gfx_drawBattery(bat_pos, bat_width, bat_height, last_state.charge);
if(last_state.settings.showBatteryIcon) {
// print battery icon on top bar, use 4 px padding
uint16_t bat_width = CONFIG_SCREEN_WIDTH / 9;
uint16_t bat_height = layout.top_h - (layout.status_v_pad * 2);
point_t bat_pos = {CONFIG_SCREEN_WIDTH - bat_width - layout.horizontal_pad,
layout.status_v_pad};
gfx_drawBattery(bat_pos, bat_width, bat_height, last_state.charge);
} else {
// print the battery percentage
point_t bat_pos = {layout.top_pos.x, layout.top_pos.y - 2};
gfx_print(bat_pos , FONT_SIZE_6PT, TEXT_ALIGN_RIGHT,
color_white,"%d%%", last_state.charge);
}
#endif
if (ui_state->input_locked == true)
gfx_drawSymbol(layout.top_pos, layout.top_symbol_size, TEXT_ALIGN_LEFT,

View File

@ -284,6 +284,12 @@ int _ui_getDisplayValueName(char *buf, uint8_t max_len, uint8_t index)
sniprintf(buf, max_len, "%s",
display_timer_values[last_state.settings.display_timer]);
return 0;
case D_BATTERY:
sniprintf(buf, max_len, "%s",
(last_state.settings.showBatteryIcon) ?
currentLanguage->on :
currentLanguage->off);
return 0;
}
sniprintf(buf, max_len, "%d", value);
return 0;