diff --git a/radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp b/radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp index 7c0518914..0335b872c 100644 --- a/radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp +++ b/radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp @@ -28,43 +28,79 @@ #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 12022d8da..fa9ba26f8 100644 --- a/radio/src/hal/rgbleds.cpp +++ b/radio/src/hal/rgbleds.cpp @@ -34,7 +34,12 @@ 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(); +} + +uint32_t getFSLedRGBColor(uint8_t index) +{ + return fsGetLedRGB(index); } #else void setFSLedOFF(uint8_t index) { @@ -48,4 +53,4 @@ void setFSLedON(uint8_t index) { bool getFSLedState(uint8_t index) { return fsLedState(index); } -#endif \ No newline at end of file +#endif diff --git a/radio/src/hal/rgbleds.h b/radio/src/hal/rgbleds.h index d061be14c..92b070f97 100644 --- a/radio/src/hal/rgbleds.h +++ b/radio/src/hal/rgbleds.h @@ -27,4 +27,5 @@ 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); diff --git a/radio/src/switches.h b/radio/src/switches.h index 4f49e65eb..75c441bcb 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/simu/led_driver.cpp b/radio/src/targets/simu/led_driver.cpp index ec1f6f58d..88dbe1d31 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); +} diff --git a/radio/src/targets/st16/led_driver.cpp b/radio/src/targets/st16/led_driver.cpp index c6bc8d598..b37de2da2 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 fa6f9f383..8f98d31e3 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++) {