From b4099fc1e72b0440682038ceec0e0e9acd842886 Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Mon, 23 Dec 2024 05:02:56 +0100 Subject: [PATCH] Add gauge --- compile-with-docker.sh | 1 + driver/st7565.c | 19 +++++++++++++++++++ driver/st7565.h | 2 ++ ui/main.c | 4 ---- ui/menu.c | 8 ++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/compile-with-docker.sh b/compile-with-docker.sh index eaa6061..1c5cf4f 100755 --- a/compile-with-docker.sh +++ b/compile-with-docker.sh @@ -32,6 +32,7 @@ bandscope() { ENABLE_AIRCOPY=1 \ ENABLE_NOAA=0 \ ENABLE_FEAT_F4HWN_RESCUE_OPS=0 \ + ENABLE_FEAT_F4HWN_CHARGING_C=0 \ EDITION_STRING=Bandscope \ TARGET=f4hwn.bandscope \ && cp f4hwn.bandscope* compiled-firmware/" diff --git a/driver/st7565.c b/driver/st7565.c index fc3723d..5e49e49 100644 --- a/driver/st7565.c +++ b/driver/st7565.c @@ -219,6 +219,25 @@ uint8_t cmds[] = { ST7565_Cmd(i); } } + + int16_t map(int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t out_max) { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + } + + void ST7565_Gauge(uint8_t line, uint8_t min, uint8_t max, uint8_t value) + { + gFrameBuffer[line][54] = 0x0c; + gFrameBuffer[line][55] = 0x12; + + gFrameBuffer[line][121] = 0x12; + gFrameBuffer[line][122] = 0x0c; + + uint8_t filled = map(value, min, max, 56, 120); + + for (uint8_t i = 56; i <= 120; i++) { + gFrameBuffer[line][i] = (i <= filled) ? 0x2d : 0x21; + } + } #endif void ST7565_Init(void) diff --git a/driver/st7565.h b/driver/st7565.h index d7e9e17..42c69e4 100644 --- a/driver/st7565.h +++ b/driver/st7565.h @@ -43,6 +43,8 @@ void ST7565_WriteByte(uint8_t Value); #ifdef ENABLE_FEAT_F4HWN void ST7565_ContrastAndInv(void); + void ST7565_Gauge(uint8_t line, uint8_t min, uint8_t max, uint8_t value); + int16_t map(int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t out_max); #endif #endif diff --git a/ui/main.c b/ui/main.c index 15c3f2d..a38be1b 100644 --- a/ui/main.c +++ b/ui/main.c @@ -53,10 +53,6 @@ center_line_t center_line = CENTER_LINE_NONE; bool isMainOnlyInputDTMF = false; - static int16_t map(int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t out_max) { - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; - } - static bool isMainOnly() { return (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF) && (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF); diff --git a/ui/menu.c b/ui/menu.c index 096d704..0191bea 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -706,6 +706,7 @@ void UI_DisplayMenu(void) else if(gSubMenuSelection < 61) { sprintf(String, "%02dm:%02ds", (((gSubMenuSelection) * 5) / 60), (((gSubMenuSelection) * 5) % 60)); + ST7565_Gauge(4, 1, 60, gSubMenuSelection); } else { @@ -735,7 +736,10 @@ void UI_DisplayMenu(void) if (gSubMenuSelection == 0) strcpy(String, "OFF"); else + { sprintf(String, "%02dm:%02ds", ((gSubMenuSelection * 15) / 60), ((gSubMenuSelection * 15) % 60)); + ST7565_Gauge(4, 1, 40, gSubMenuSelection); + } break; case MENU_COMPAND: @@ -849,6 +853,7 @@ void UI_DisplayMenu(void) case MENU_TOT: sprintf(String, "%02dm:%02ds", (((gSubMenuSelection + 1) * 5) / 60), (((gSubMenuSelection + 1) * 5) % 60)); + ST7565_Gauge(4, 5, 180, gSubMenuSelection); break; #ifdef ENABLE_VOICE @@ -865,10 +870,12 @@ void UI_DisplayMenu(void) else if(gSubMenuSelection < 81) { sprintf(String, "CARRIER\n%02ds:%03dms", ((gSubMenuSelection * 250) / 1000), ((gSubMenuSelection * 250) % 1000)); + ST7565_Gauge(5, 1, 80, gSubMenuSelection); } else { sprintf(String, "TIMEOUT\n%02dm:%02ds", (((gSubMenuSelection - 80) * 5) / 60), (((gSubMenuSelection - 80) * 5) % 60)); + ST7565_Gauge(5, 80, 104, gSubMenuSelection); } break; @@ -1020,6 +1027,7 @@ void UI_DisplayMenu(void) else if(gSubMenuSelection < 121) { sprintf(String, "%dh:%02dm", (gSubMenuSelection / 60), (gSubMenuSelection % 60)); + ST7565_Gauge(4, 1, 120, gSubMenuSelection); } break; #endif