From 3add35275c548368b532d77f5e72a54f5d801f3c Mon Sep 17 00:00:00 2001 From: romanat Date: Sat, 6 Sep 2025 22:02:44 -0300 Subject: [PATCH] ui: battery: add menu entry to select between icon or percentage --- openrtx/include/core/settings.h | 4 +++- openrtx/include/ui/EnglishStrings.h | 1 + openrtx/include/ui/SpanishStrings.h | 1 + openrtx/include/ui/ui_default.h | 1 + openrtx/include/ui/ui_strings.h | 1 + openrtx/src/ui/default/ui.c | 6 +++++- openrtx/src/ui/default/ui_main.c | 19 +++++++++++++------ openrtx/src/ui/default/ui_menu.c | 6 ++++++ 8 files changed, 31 insertions(+), 8 deletions(-) diff --git a/openrtx/include/core/settings.h b/openrtx/include/core/settings.h index 84a2a5e9..fc74facc 100644 --- a/openrtx/include/core/settings.h +++ b/openrtx/include/core/settings.h @@ -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 */ diff --git a/openrtx/include/ui/EnglishStrings.h b/openrtx/include/ui/EnglishStrings.h index 26df3fcb..4fa85b3e 100644 --- a/openrtx/include/ui/EnglishStrings.h +++ b/openrtx/include/ui/EnglishStrings.h @@ -96,5 +96,6 @@ const stringsTable_t englishStrings = .frequencyOffset = "Frequency Offset", .macroLatching = "Macro Latching", .noGps = "No GPS", + .batteryIcon = "Battery Icon", }; #endif // ENGLISHSTRINGS_H diff --git a/openrtx/include/ui/SpanishStrings.h b/openrtx/include/ui/SpanishStrings.h index 22fe17bf..d244c9b9 100644 --- a/openrtx/include/ui/SpanishStrings.h +++ b/openrtx/include/ui/SpanishStrings.h @@ -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 diff --git a/openrtx/include/ui/ui_default.h b/openrtx/include/ui/ui_default.h index 49290b96..53bfbfd1 100644 --- a/openrtx/include/ui/ui_default.h +++ b/openrtx/include/ui/ui_default.h @@ -120,6 +120,7 @@ enum displayItems D_CONTRAST, #endif D_TIMER, + D_BATTERY }; #ifdef CONFIG_GPS diff --git a/openrtx/include/ui/ui_strings.h b/openrtx/include/ui/ui_strings.h index 9389bcbb..9d77942e 100644 --- a/openrtx/include/ui/ui_strings.h +++ b/openrtx/include/ui/ui_strings.h @@ -100,6 +100,7 @@ typedef struct const char* frequencyOffset; const char* macroLatching; const char* noGps; + const char* batteryIcon; } stringsTable_t; diff --git a/openrtx/src/ui/default/ui.c b/openrtx/src/ui/default/ui.c index 79903fdc..1733b8ed 100644 --- a/openrtx/src/ui/default/ui.c +++ b/openrtx/src/ui/default/ui.c @@ -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; } diff --git a/openrtx/src/ui/default/ui_main.c b/openrtx/src/ui/default/ui_main.c index 2289d150..22e9d122 100644 --- a/openrtx/src/ui/default/ui_main.c +++ b/openrtx/src/ui/default/ui_main.c @@ -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, diff --git a/openrtx/src/ui/default/ui_menu.c b/openrtx/src/ui/default/ui_menu.c index 973f5dcd..56d24377 100644 --- a/openrtx/src/ui/default/ui_menu.c +++ b/openrtx/src/ui/default/ui_menu.c @@ -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;