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

This commit is contained in:
philmoz
2025-04-28 21:37:07 +10:00
committed by GitHub
parent 522474cf62
commit 5a7a50f2cc
7 changed files with 82 additions and 24 deletions
@@ -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
#endif
+7 -2
View File
@@ -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
#endif
+2 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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);
}
+9 -4
View File
@@ -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)
+5
View File
@@ -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++) {