From da706e0c30f0b8d888dc30f65871002213e04662 Mon Sep 17 00:00:00 2001 From: philmoz Date: Sat, 25 Oct 2025 14:13:19 +1100 Subject: [PATCH] feat(bw): preview color on customisable switch LED when editing the color (#6716) --- radio/src/gui/128x64/model_setup.cpp | 30 ++++++++++++++----- .../src/gui/common/stdlcd/radio_hardware.cpp | 12 +++++++- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/radio/src/gui/128x64/model_setup.cpp b/radio/src/gui/128x64/model_setup.cpp index b9e3f2fb9..8517c390c 100644 --- a/radio/src/gui/128x64/model_setup.cpp +++ b/radio/src/gui/128x64/model_setup.cpp @@ -590,7 +590,7 @@ uint8_t viewOptChoice(coord_t y, const char* title, uint8_t value, uint8_t attr, #if defined(FUNCTION_SWITCHES) const char* _fct_sw_start[] = { STR_CHAR_UP, STR_CHAR_DOWN, "=" }; -static int swIndex; +int swIndex; static uint8_t cfsGroup; bool checkCFSTypeAvailable(int val) @@ -614,13 +614,6 @@ static bool checkCFSSwitchAvailable(int sw) return (sw == -1) || (sw == switchGetMaxSwitches()) || (switchIsCustomSwitch(sw) && (g_model.cfsGroup(sw) == cfsGroup)); } -#if defined(FUNCTION_SWITCHES_RGB_LEDS) -static bool checkCFSColorAvailable(int col) -{ - return col > 0; -} -#endif - enum CFSFields { CFS_FIELD_TYPE, CFS_FIELD_NAME, @@ -637,6 +630,13 @@ enum CFSFields { }; #if defined(FUNCTION_SWITCHES_RGB_LEDS) +bool menuCFSpreview; + +static bool checkCFSColorAvailable(int col) +{ + return col > 0; +} + void menuCFSColor(coord_t y, RGBLedColor& color, const char* title, LcdFlags attr, event_t event) { uint8_t selectedColor = getRGBColorIndex(color.getColor()); @@ -658,6 +658,11 @@ void menuCFSColor(coord_t y, RGBLedColor& color, const char* title, LcdFlags att lcdDrawNumber(LCD_W, y, color.b, (menuHorizontalPosition == 3 ? attr : 0) | RIGHT); if (attr && menuHorizontalPosition == 3) color.b = checkIncDec(event, color.b, 0, 255, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL); + + if ((attr & BLINK) && !menuCFSpreview) { + menuCFSpreview = true; + setFSEditOverride(swIndex, color.getColor()); + } } #endif @@ -690,6 +695,10 @@ static void menuModelCFSOne(event_t event) coord_t y = MENU_HEADER_HEIGHT + 1; +#if defined(FUNCTION_SWITCHES_RGB_LEDS) + menuCFSpreview = false; +#endif + for (int k = 0; k < NUM_BODY_LINES; k += 1) { int i = k + menuVerticalOffset; for (int j = 0; j <= i; j += 1) { @@ -776,6 +785,11 @@ static void menuModelCFSOne(event_t event) y += FH; } + +#if defined(FUNCTION_SWITCHES_RGB_LEDS) + if (!menuCFSpreview) + setFSEditOverride(-1, 0); +#endif } #endif diff --git a/radio/src/gui/common/stdlcd/radio_hardware.cpp b/radio/src/gui/common/stdlcd/radio_hardware.cpp index d9de31a32..a7140add7 100644 --- a/radio/src/gui/common/stdlcd/radio_hardware.cpp +++ b/radio/src/gui/common/stdlcd/radio_hardware.cpp @@ -123,7 +123,7 @@ static void onHardwareAntennaSwitchConfirm(const char * result) #if defined(FUNCTION_SWITCHES) #define RADIO_SETUP_2ND_COLUMN (LCD_W-11*FW) extern const char* _fct_sw_start[]; -static int swIndex; +extern int swIndex; extern bool checkCFSTypeAvailable(int val); @@ -142,6 +142,7 @@ enum CFSFields { }; #if defined(FUNCTION_SWITCHES_RGB_LEDS) +extern bool menuCFSpreview; extern void menuCFSColor(coord_t y, RGBLedColor& color, const char* title, LcdFlags attr, event_t event); #endif @@ -173,6 +174,10 @@ static void menuRadioCFSOne(event_t event) coord_t y = MENU_HEADER_HEIGHT + 1; +#if defined(FUNCTION_SWITCHES_RGB_LEDS) + menuCFSpreview = false; +#endif + for (int k = 0; k < NUM_BODY_LINES; k += 1) { int i = k + menuVerticalOffset; for (int j = 0; j <= i; j += 1) { @@ -241,6 +246,11 @@ static void menuRadioCFSOne(event_t event) y += FH; } + +#if defined(FUNCTION_SWITCHES_RGB_LEDS) + if (!menuCFSpreview) + setFSEditOverride(-1, 0); +#endif } #endif