From ef09fc48144dafde36ad45e7cd28b043d3320a35 Mon Sep 17 00:00:00 2001 From: philmoz Date: Wed, 23 Apr 2025 15:14:28 +1000 Subject: [PATCH 1/3] Fix color display on CFS diagnostic page. --- .../colorlcd/radio/radio_diagcustswitches.cpp | 70 ++++++++++++++----- radio/src/hal/rgbleds.cpp | 24 ++++++- radio/src/hal/rgbleds.h | 5 +- radio/src/switches.h | 1 + radio/src/targets/st16/led_driver.cpp | 13 ++-- radio/src/targets/taranis/led_driver.cpp | 5 ++ 6 files changed, 94 insertions(+), 24 deletions(-) diff --git a/radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp b/radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp index 7c051891457..0335b872c00 100644 --- a/radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp +++ b/radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp @@ -28,42 +28,78 @@ #include "libopenui.h" #include "edgetx.h" +#if defined(FUNCTION_SWITCHES_RGB_LEDS) +#include "color_list.h" +#include "hal/rgbleds.h" +#endif + +#if defined(FUNCTION_SWITCHES_RGB_LEDS) +uint16_t getLedColor(int i) +{ + // Convert RBG888 to RGB565 + uint32_t rgb32 = getFSLedRGBColor(i); + uint8_t r = GET_RED32(rgb32); + uint8_t g = GET_GREEN32(rgb32); + uint8_t b = GET_BLUE32(rgb32); + return RGB(r, g, b); +} +#endif + class RadioCustSwitchesDiagsWindow : public Window { - static constexpr coord_t FS_1ST_COLUMN = 95; - static constexpr coord_t FS_2ND_COLUMN = 160; - static constexpr coord_t FS_3RD_COLUMN = 260; + static LAYOUT_VAL(FS_1ST_COLUMN, 95, 62, LS(95)) + static LAYOUT_VAL(FS_2ND_COLUMN, 160, 107, LS(160)) + static LAYOUT_VAL(FS_3RD_COLUMN, 260, 173, LS(260)) + static LAYOUT_VAL(FS_LBL_WIDTH, 60, 40, LS(60)) +#if defined(FUNCTION_SWITCHES_RGB_LEDS) + static LAYOUT_VAL(FS_COLOR_WIDTH, 30, 30, LS(30)) + static LAYOUT_VAL(FS_COLOR_HEIGHT, 15, 15, LS(15)) + ColorSwatch* colorBox[NUM_FUNCTIONS_SWITCHES]; +#endif public: RadioCustSwitchesDiagsWindow(Window *parent, const rect_t &rect) : Window(parent, rect) { - new StaticText(this, {FS_1ST_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT}, + new StaticText(this, {FS_1ST_COLUMN, PAD_SMALL, FS_LBL_WIDTH, LV_SIZE_CONTENT}, "Phys"); - new StaticText(this, {FS_2ND_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT}, + new StaticText(this, {FS_2ND_COLUMN, PAD_SMALL, FS_LBL_WIDTH, LV_SIZE_CONTENT}, "Log"); - new StaticText(this, {FS_3RD_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT}, + new StaticText(this, {FS_3RD_COLUMN, PAD_SMALL, FS_LBL_WIDTH, LV_SIZE_CONTENT}, "Led"); for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) { - coord_t y = 2 * EdgeTxStyles::STD_FONT_HEIGHT + - i * EdgeTxStyles::STD_FONT_HEIGHT; - new StaticText(this, {10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, - STR_CHAR_SWITCH); - new StaticText(this, {25, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, - switchGetName(i + switchGetMaxSwitches())); + coord_t y = (i + 2) * EdgeTxStyles::STD_FONT_HEIGHT; + std::string s(STR_CHAR_SWITCH); + s += switchGetName(i + switchGetMaxSwitches()); + new StaticText(this, {PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT}, s); new DynamicText( - this, {FS_1ST_COLUMN + 10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, + this, {FS_1ST_COLUMN + PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT}, [=]() { return getFSPhysicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP; }); new DynamicText( - this, {FS_2ND_COLUMN + 10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, + this, {FS_2ND_COLUMN + PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT}, [=]() { return getFSLogicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP; }); + +#if defined(FUNCTION_SWITCHES_RGB_LEDS) + colorBox[i] = new ColorSwatch(this, {FS_3RD_COLUMN, y, FS_COLOR_WIDTH, + FS_COLOR_HEIGHT}, getLedColor(i)); +#else new DynamicText(this, - {FS_3RD_COLUMN + 5, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, - [=]() { return STR_OFFON[getFSLedState(i)]; }); + {FS_3RD_COLUMN, y, FS_LBL_WIDTH, LV_SIZE_CONTENT}, + [=]() { return STR_OFFON[getFSLedState(i)]; }); +#endif + } + } + +#if defined(FUNCTION_SWITCHES_RGB_LEDS) + void checkEvents() { + Window::checkEvents(); + for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) { + colorBox[i]->setColor(getLedColor(i)); } } +#endif protected: }; @@ -88,4 +124,4 @@ RadioCustSwitchesDiagsPage::RadioCustSwitchesDiagsPage() : buildBody(body); } -#endif \ No newline at end of file +#endif diff --git a/radio/src/hal/rgbleds.cpp b/radio/src/hal/rgbleds.cpp index 12022d8dae4..af8ce24b124 100644 --- a/radio/src/hal/rgbleds.cpp +++ b/radio/src/hal/rgbleds.cpp @@ -34,7 +34,17 @@ void setFSLedON(uint8_t index) { } bool getFSLedState(uint8_t index) { - return rgbGetLedColor(index) == g_model.functionSwitchLedONColor[index].getColor(); + return fsGetLedRGB(index) == g_model.functionSwitchLedONColor[index].getColor(); +} + +bool isLedControledByFS(uint8_t index) +{ + return index < NUM_FUNCTIONS_SWITCHES; // TODO: check real usage +} + +uint32_t getFSLedRGBColor(uint8_t index) +{ + return fsGetLedRGB(index); } #else void setFSLedOFF(uint8_t index) { @@ -48,4 +58,14 @@ void setFSLedON(uint8_t index) { bool getFSLedState(uint8_t index) { return fsLedState(index); } -#endif \ No newline at end of file + +bool isLedControledByFS(uint8_t index) +{ + return false; +} +#endif + +void turnOffRGBLeds() +{ + rgbLedClearAll(); +} diff --git a/radio/src/hal/rgbleds.h b/radio/src/hal/rgbleds.h index d061be14c10..6d8f4311766 100644 --- a/radio/src/hal/rgbleds.h +++ b/radio/src/hal/rgbleds.h @@ -27,4 +27,7 @@ constexpr uint32_t colorTable[] = {0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0xFFF void setFSLedOFF(uint8_t index); void setFSLedON(uint8_t index); -bool getFSLedState(uint8_t index); \ No newline at end of file +bool getFSLedState(uint8_t index); +uint32_t getFSLedRGBColor(uint8_t index); +void turnOffRGBLeds(); +bool isLedControledByFS(uint8_t index); diff --git a/radio/src/switches.h b/radio/src/switches.h index 4f49e65ebda..75c441bcb36 100644 --- a/radio/src/switches.h +++ b/radio/src/switches.h @@ -108,5 +108,6 @@ void fsLedOff(uint8_t); void fsLedOn(uint8_t); bool fsLedState(uint8_t index); void fsLedRGB(uint8_t, uint32_t color); +uint32_t fsGetLedRGB(uint8_t index); uint8_t getRGBColorIndex(uint32_t color); #endif diff --git a/radio/src/targets/st16/led_driver.cpp b/radio/src/targets/st16/led_driver.cpp index c6bc8d59851..b37de2da207 100644 --- a/radio/src/targets/st16/led_driver.cpp +++ b/radio/src/targets/st16/led_driver.cpp @@ -65,10 +65,15 @@ uint8_t ledMapping[] = {12, 14, 16, 18, 20, 22}; void fsLedRGB(uint8_t index, uint32_t color) { - rgbSetLedColor(ledMapping[index], GET_RED(color), \ - GET_GREEN(color),GET_BLUE(color)); - rgbSetLedColor(ledMapping[index]+1, GET_RED(color), \ - GET_GREEN(color),GET_BLUE(color)); + rgbSetLedColor(ledMapping[index], GET_RED(color), \ + GET_GREEN(color),GET_BLUE(color)); + rgbSetLedColor(ledMapping[index]+1, GET_RED(color), \ + GET_GREEN(color),GET_BLUE(color)); +} + +uint32_t fsGetLedRGB(uint8_t index) +{ + return rgbGetLedColor(ledMapping[index]); } uint8_t getRGBColorIndex(uint32_t color) diff --git a/radio/src/targets/taranis/led_driver.cpp b/radio/src/targets/taranis/led_driver.cpp index fa6f9f383e2..8f98d31e376 100644 --- a/radio/src/targets/taranis/led_driver.cpp +++ b/radio/src/targets/taranis/led_driver.cpp @@ -69,6 +69,11 @@ void fsLedRGB(uint8_t index, uint32_t color) GET_BLUE(color)); } +uint32_t fsGetLedRGB(uint8_t index) +{ + return rgbGetLedColor(ledMapping[index]); +} + uint8_t getRGBColorIndex(uint32_t color) { for (uint8_t i = 0; i < DIM(colorTable); i++) { From 461489082a995593b7010511f626e8841ad40a3b Mon Sep 17 00:00:00 2001 From: philmoz Date: Wed, 23 Apr 2025 15:43:56 +1000 Subject: [PATCH 2/3] Fix build. --- radio/src/hal/rgbleds.cpp | 15 --------------- radio/src/hal/rgbleds.h | 2 -- 2 files changed, 17 deletions(-) diff --git a/radio/src/hal/rgbleds.cpp b/radio/src/hal/rgbleds.cpp index af8ce24b124..fa9ba26f8d8 100644 --- a/radio/src/hal/rgbleds.cpp +++ b/radio/src/hal/rgbleds.cpp @@ -37,11 +37,6 @@ bool getFSLedState(uint8_t index) { return fsGetLedRGB(index) == g_model.functionSwitchLedONColor[index].getColor(); } -bool isLedControledByFS(uint8_t index) -{ - return index < NUM_FUNCTIONS_SWITCHES; // TODO: check real usage -} - uint32_t getFSLedRGBColor(uint8_t index) { return fsGetLedRGB(index); @@ -58,14 +53,4 @@ void setFSLedON(uint8_t index) { bool getFSLedState(uint8_t index) { return fsLedState(index); } - -bool isLedControledByFS(uint8_t index) -{ - return false; -} #endif - -void turnOffRGBLeds() -{ - rgbLedClearAll(); -} diff --git a/radio/src/hal/rgbleds.h b/radio/src/hal/rgbleds.h index 6d8f4311766..92b070f9741 100644 --- a/radio/src/hal/rgbleds.h +++ b/radio/src/hal/rgbleds.h @@ -29,5 +29,3 @@ void setFSLedOFF(uint8_t index); void setFSLedON(uint8_t index); bool getFSLedState(uint8_t index); uint32_t getFSLedRGBColor(uint8_t index); -void turnOffRGBLeds(); -bool isLedControledByFS(uint8_t index); From 3457d1c10e8d5e785013c804b40bc6a85a6e0834 Mon Sep 17 00:00:00 2001 From: philmoz Date: Wed, 23 Apr 2025 16:54:11 +1000 Subject: [PATCH 3/3] Fix build --- radio/src/targets/simu/led_driver.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/radio/src/targets/simu/led_driver.cpp b/radio/src/targets/simu/led_driver.cpp index ec1f6f58d3a..88dbe1d313d 100644 --- a/radio/src/targets/simu/led_driver.cpp +++ b/radio/src/targets/simu/led_driver.cpp @@ -57,3 +57,8 @@ uint32_t rgbGetLedColor(uint8_t led) uint8_t* pixel = &_led_colors[led * WS2812_BYTES_PER_LED]; return (pixel[1] << 16) + (pixel[0] << 8) + pixel[2]; } + +uint32_t fsGetLedRGB(uint8_t index) +{ + return rgbGetLedColor(index); +}