Skip to content

feat(color): show switch colors for customisable switches on diagnostic page #6124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 53 additions & 17 deletions radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
};
Expand All @@ -88,4 +124,4 @@ RadioCustSwitchesDiagsPage::RadioCustSwitchesDiagsPage() :
buildBody(body);
}

#endif
#endif
9 changes: 7 additions & 2 deletions radio/src/hal/rgbleds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -48,4 +53,4 @@ void setFSLedON(uint8_t index) {
bool getFSLedState(uint8_t index) {
return fsLedState(index);
}
#endif
#endif
3 changes: 2 additions & 1 deletion radio/src/hal/rgbleds.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
bool getFSLedState(uint8_t index);
uint32_t getFSLedRGBColor(uint8_t index);
1 change: 1 addition & 0 deletions radio/src/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions radio/src/targets/simu/led_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
13 changes: 9 additions & 4 deletions radio/src/targets/st16/led_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions radio/src/targets/taranis/led_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down