From b27ef43b4fd18fa6048fa5c184fdfc6fd9959f25 Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Mon, 9 Oct 2023 14:17:14 +0200 Subject: [PATCH] BUG FIX #139: always 4 battery bars --- ui/battery.c | 15 ++++++++++----- ui/battery.h | 2 +- ui/status.c | 29 +++-------------------------- 3 files changed, 14 insertions(+), 32 deletions(-) diff --git a/ui/battery.c b/ui/battery.c index 977ef92..546ec74 100644 --- a/ui/battery.c +++ b/ui/battery.c @@ -22,16 +22,15 @@ #include "functions.h" #include "ui/battery.h" -void UI_DisplayBattery(const unsigned int level, const unsigned int blink) +void UI_DrawBattery(uint8_t* bitmap, const unsigned int level, const unsigned int blink) { - uint8_t bitmap[sizeof(BITMAP_BATTERY_LEVEL)]; - memmove(bitmap, BITMAP_BATTERY_LEVEL, sizeof(BITMAP_BATTERY_LEVEL)); if (level >= 1) { unsigned int i; - const uint8_t bars = (level <= 5) - 1 ? level - 1 : 5 - 1; + uint8_t bars = level > 0 ? level - 1 : 0; + if(bars>4) bars = 4; for (i = 0; i < bars; i++) { #ifndef ENABLE_REVERSE_BAT_SYMBOL @@ -46,7 +45,13 @@ void UI_DisplayBattery(const unsigned int level, const unsigned int blink) else if (blink == 0) memset(bitmap, 0, sizeof(bitmap)); +} - // col lne, siz, bm +void UI_DisplayBattery(const unsigned int level, const unsigned int blink) +{ + uint8_t bitmap[sizeof(BITMAP_BATTERY_LEVEL)]; + + UI_DrawBattery(bitmap, level, blink); + memmove(bitmap, BITMAP_BATTERY_LEVEL, sizeof(BITMAP_BATTERY_LEVEL)); ST7565_DrawLine(LCD_WIDTH - sizeof(bitmap), 0, sizeof(bitmap), bitmap); } diff --git a/ui/battery.h b/ui/battery.h index 1105876..f2ea40e 100644 --- a/ui/battery.h +++ b/ui/battery.h @@ -18,7 +18,7 @@ #define UI_BATTERY_H #include - +void UI_DrawBattery(uint8_t* bitmap, const unsigned int level, const unsigned int blink); void UI_DisplayBattery(const unsigned int Level, const unsigned int blink); #endif diff --git a/ui/status.c b/ui/status.c index f32c9f2..2dcc729 100644 --- a/ui/status.c +++ b/ui/status.c @@ -28,6 +28,7 @@ #include "helper/battery.h" #include "misc.h" #include "settings.h" +#include "ui/battery.h" #include "ui/helper.h" #include "ui/ui.h" #include "ui/status.h" @@ -216,33 +217,9 @@ void UI_DisplayStatus(const bool test_display) memmove(line + x, BITMAP_USB_C, sizeof(BITMAP_USB_C)); x += sizeof(BITMAP_USB_C); - { // BATTERY LEVEL indicator - uint8_t bitmap[sizeof(BITMAP_BATTERY_LEVEL)]; - unsigned int i = g_battery_display_level; + // BATTERY LEVEL indicator + UI_DrawBattery(line + x, g_battery_display_level, g_low_battery); - memmove(bitmap, BITMAP_BATTERY_LEVEL, sizeof(BITMAP_BATTERY_LEVEL)); - - if (i >= 1) - { - const uint8_t bars = (i <= 5) - 1 ? i - 1 : 5 - 1; - for (i = 0; i < bars; i++) - { - #ifndef ENABLE_REVERSE_BAT_SYMBOL - bitmap[sizeof(bitmap) - 3 - (i * 3) - 0] = 0b01011101; - bitmap[sizeof(bitmap) - 3 - (i * 3) - 1] = 0b01011101; - #else - bitmap[3 + (i * 3) + 0] = 0b01011101; - bitmap[3 + (i * 3) + 1] = 0b01011101; - #endif - } - } - else - if (g_low_battery) - memset(bitmap, 0, sizeof(bitmap)); - - memmove(line + x, bitmap, sizeof(bitmap)); - } - // ************** ST7565_BlitStatusLine();