From a3decb8d85ee598fbc8ef77b904dfd77c8bef84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Fri, 11 Dec 2020 14:40:56 +0100 Subject: [PATCH] Improved low battery screen rendering on smaller screens --- openrtx/src/main.c | 20 +------------------- openrtx/src/ui.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/openrtx/src/main.c b/openrtx/src/main.c index 5b052835..accd6322 100644 --- a/openrtx/src/main.c +++ b/openrtx/src/main.c @@ -38,25 +38,7 @@ void check_battery() { // Draw low battery screen if (charge <= 0) { - gfx_clearScreen(); - uint16_t bat_width = SCREEN_WIDTH / 2; - uint16_t bat_height = SCREEN_HEIGHT / 3; - point_t bat_pos = {SCREEN_WIDTH / 4, SCREEN_HEIGHT / 6}; - gfx_drawBattery(bat_pos, bat_width, bat_height, 0.1f); - point_t text_pos_1 = {0, SCREEN_HEIGHT * 3 / 4}; - point_t text_pos_2 = {0, SCREEN_HEIGHT * 3 / 4 + 16}; - const color_t color_white = {255, 255, 255}; - - gfx_print(text_pos_1, - "For emergency operation", - FONT_SIZE_6PT, - TEXT_ALIGN_CENTER, - color_white); - gfx_print(text_pos_2, - "press any button.", - FONT_SIZE_6PT, - TEXT_ALIGN_CENTER, - color_white); + ui_drawLowBatteryScreen(); gfx_render(); // Wait 5 seconds diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index 08c6e6e2..c1a8f097 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -19,9 +19,9 @@ ***************************************************************************/ /* - * The graphical user interface (GUI) works by splitting the screen in + * The graphical user interface (GUI) works by splitting the screen in * horizontal rows, with row height depending on vertical resolution. - * + * * The general screen layout is composed by an upper status bar at the * top of the screen and a lower status bar at the bottom. * The central portion of the screen is filled by two big text/number rows @@ -158,7 +158,7 @@ layout_t _ui_calculateLayout() const fontSize_t line3_font = FONT_SIZE_5PT; // Bottom bar font: 8 pt const fontSize_t bottom_font = FONT_SIZE_6PT; - + #elif SCREEN_HEIGHT > 47 // Height and padding shown in diagram at beginning of file @@ -224,7 +224,7 @@ void _ui_drawTopBar(state_t* last_state) { // Print clock on top bar char clock_buf[9] = ""; - snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d:%02d", last_state->time.hour, + snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d:%02d", last_state->time.hour, last_state->time.minute, last_state->time.second); gfx_print(layout.top_pos, clock_buf, layout.top_font, TEXT_ALIGN_CENTER, color_white); @@ -323,7 +323,7 @@ bool _ui_drawMenuTop() for(int item=0; (item < MENU_NUM) && (pos.y < SCREEN_HEIGHT); item++) { snprintf(entry_buf, sizeof(entry_buf), "%s", menuItems[item]); - gfx_print(pos, entry_buf, layout.top_font, + gfx_print(pos, entry_buf, layout.top_font, TEXT_ALIGN_LEFT, color_white); pos.y += layout.top_h; } @@ -354,6 +354,29 @@ void ui_drawSplashScreen() #endif } +void ui_drawLowBatteryScreen() +{ + gfx_clearScreen(); + uint16_t bat_width = SCREEN_WIDTH / 2; + uint16_t bat_height = SCREEN_HEIGHT / 3; + point_t bat_pos = {SCREEN_WIDTH / 4, SCREEN_HEIGHT / 8}; + gfx_drawBattery(bat_pos, bat_width, bat_height, 0.1f); + point_t text_pos_1 = {0, SCREEN_HEIGHT * 2 / 3}; + point_t text_pos_2 = {0, SCREEN_HEIGHT * 2 / 3 + 16}; + const color_t color_white = {255, 255, 255}; + + gfx_print(text_pos_1, + "For emergency use", + FONT_SIZE_6PT, + TEXT_ALIGN_CENTER, + color_white); + gfx_print(text_pos_2, + "press any button.", + FONT_SIZE_6PT, + TEXT_ALIGN_CENTER, + color_white); +} + void ui_updateFSM(event_t event) { // Process pressed keys