Skip to content

Commit e139a66

Browse files
philmozpfeerick
authored andcommitted
feat(color): show switch colors for customisable switches on diagnostic page (#6124)
1 parent 2ff13a5 commit e139a66

File tree

7 files changed

+82
-24
lines changed

7 files changed

+82
-24
lines changed

radio/src/gui/colorlcd/radio/radio_diagcustswitches.cpp

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,78 @@
2828
#include "libopenui.h"
2929
#include "edgetx.h"
3030

31+
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
32+
#include "color_list.h"
33+
#include "hal/rgbleds.h"
34+
#endif
35+
36+
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
37+
uint16_t getLedColor(int i)
38+
{
39+
// Convert RBG888 to RGB565
40+
uint32_t rgb32 = getFSLedRGBColor(i);
41+
uint8_t r = GET_RED32(rgb32);
42+
uint8_t g = GET_GREEN32(rgb32);
43+
uint8_t b = GET_BLUE32(rgb32);
44+
return RGB(r, g, b);
45+
}
46+
#endif
47+
3148
class RadioCustSwitchesDiagsWindow : public Window
3249
{
33-
static constexpr coord_t FS_1ST_COLUMN = 95;
34-
static constexpr coord_t FS_2ND_COLUMN = 160;
35-
static constexpr coord_t FS_3RD_COLUMN = 260;
50+
static LAYOUT_VAL(FS_1ST_COLUMN, 95, 62, LS(95))
51+
static LAYOUT_VAL(FS_2ND_COLUMN, 160, 107, LS(160))
52+
static LAYOUT_VAL(FS_3RD_COLUMN, 260, 173, LS(260))
53+
static LAYOUT_VAL(FS_LBL_WIDTH, 60, 40, LS(60))
54+
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
55+
static LAYOUT_VAL(FS_COLOR_WIDTH, 30, 30, LS(30))
56+
static LAYOUT_VAL(FS_COLOR_HEIGHT, 15, 15, LS(15))
57+
ColorSwatch* colorBox[NUM_FUNCTIONS_SWITCHES];
58+
#endif
3659

3760
public:
3861
RadioCustSwitchesDiagsWindow(Window *parent, const rect_t &rect) :
3962
Window(parent, rect)
4063
{
41-
new StaticText(this, {FS_1ST_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT},
64+
new StaticText(this, {FS_1ST_COLUMN, PAD_SMALL, FS_LBL_WIDTH, LV_SIZE_CONTENT},
4265
"Phys");
43-
new StaticText(this, {FS_2ND_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT},
66+
new StaticText(this, {FS_2ND_COLUMN, PAD_SMALL, FS_LBL_WIDTH, LV_SIZE_CONTENT},
4467
"Log");
45-
new StaticText(this, {FS_3RD_COLUMN, PAD_SMALL, 60, LV_SIZE_CONTENT},
68+
new StaticText(this, {FS_3RD_COLUMN, PAD_SMALL, FS_LBL_WIDTH, LV_SIZE_CONTENT},
4669
"Led");
4770
for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) {
48-
coord_t y = 2 * EdgeTxStyles::STD_FONT_HEIGHT +
49-
i * EdgeTxStyles::STD_FONT_HEIGHT;
50-
new StaticText(this, {10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT},
51-
STR_CHAR_SWITCH);
52-
new StaticText(this, {25, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT},
53-
switchGetName(i + switchGetMaxSwitches()));
71+
coord_t y = (i + 2) * EdgeTxStyles::STD_FONT_HEIGHT;
72+
std::string s(STR_CHAR_SWITCH);
73+
s += switchGetName(i + switchGetMaxSwitches());
74+
new StaticText(this, {PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT}, s);
5475
new DynamicText(
55-
this, {FS_1ST_COLUMN + 10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT},
76+
this, {FS_1ST_COLUMN + PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT},
5677
[=]() {
5778
return getFSPhysicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP;
5879
});
5980
new DynamicText(
60-
this, {FS_2ND_COLUMN + 10, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT},
81+
this, {FS_2ND_COLUMN + PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT},
6182
[=]() { return getFSLogicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP; });
83+
84+
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
85+
colorBox[i] = new ColorSwatch(this, {FS_3RD_COLUMN, y, FS_COLOR_WIDTH,
86+
FS_COLOR_HEIGHT}, getLedColor(i));
87+
#else
6288
new DynamicText(this,
63-
{FS_3RD_COLUMN + 5, y, LV_SIZE_CONTENT, LV_SIZE_CONTENT},
64-
[=]() { return STR_OFFON[getFSLedState(i)]; });
89+
{FS_3RD_COLUMN, y, FS_LBL_WIDTH, LV_SIZE_CONTENT},
90+
[=]() { return STR_OFFON[getFSLedState(i)]; });
91+
#endif
92+
}
93+
}
94+
95+
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
96+
void checkEvents() {
97+
Window::checkEvents();
98+
for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) {
99+
colorBox[i]->setColor(getLedColor(i));
65100
}
66101
}
102+
#endif
67103

68104
protected:
69105
};
@@ -88,4 +124,4 @@ RadioCustSwitchesDiagsPage::RadioCustSwitchesDiagsPage() :
88124
buildBody(body);
89125
}
90126

91-
#endif
127+
#endif

radio/src/hal/rgbleds.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ void setFSLedON(uint8_t index) {
3434
}
3535

3636
bool getFSLedState(uint8_t index) {
37-
return rgbGetLedColor(index) == g_model.functionSwitchLedONColor[index].getColor();
37+
return fsGetLedRGB(index) == g_model.functionSwitchLedONColor[index].getColor();
38+
}
39+
40+
uint32_t getFSLedRGBColor(uint8_t index)
41+
{
42+
return fsGetLedRGB(index);
3843
}
3944
#else
4045
void setFSLedOFF(uint8_t index) {
@@ -48,4 +53,4 @@ void setFSLedON(uint8_t index) {
4853
bool getFSLedState(uint8_t index) {
4954
return fsLedState(index);
5055
}
51-
#endif
56+
#endif

radio/src/hal/rgbleds.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ constexpr uint32_t colorTable[] = {0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0xFFF
2727

2828
void setFSLedOFF(uint8_t index);
2929
void setFSLedON(uint8_t index);
30-
bool getFSLedState(uint8_t index);
30+
bool getFSLedState(uint8_t index);
31+
uint32_t getFSLedRGBColor(uint8_t index);

radio/src/switches.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,6 @@ void fsLedOff(uint8_t);
108108
void fsLedOn(uint8_t);
109109
bool fsLedState(uint8_t index);
110110
void fsLedRGB(uint8_t, uint32_t color);
111+
uint32_t fsGetLedRGB(uint8_t index);
111112
uint8_t getRGBColorIndex(uint32_t color);
112113
#endif

radio/src/targets/simu/led_driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ uint32_t rgbGetLedColor(uint8_t led)
5757
uint8_t* pixel = &_led_colors[led * WS2812_BYTES_PER_LED];
5858
return (pixel[1] << 16) + (pixel[0] << 8) + pixel[2];
5959
}
60+
61+
uint32_t fsGetLedRGB(uint8_t index)
62+
{
63+
return rgbGetLedColor(index);
64+
}

radio/src/targets/st16/led_driver.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ uint8_t ledMapping[] = {12, 14, 16, 18, 20, 22};
6565

6666
void fsLedRGB(uint8_t index, uint32_t color)
6767
{
68-
rgbSetLedColor(ledMapping[index], GET_RED(color), \
69-
GET_GREEN(color),GET_BLUE(color));
70-
rgbSetLedColor(ledMapping[index]+1, GET_RED(color), \
71-
GET_GREEN(color),GET_BLUE(color));
68+
rgbSetLedColor(ledMapping[index], GET_RED(color), \
69+
GET_GREEN(color),GET_BLUE(color));
70+
rgbSetLedColor(ledMapping[index]+1, GET_RED(color), \
71+
GET_GREEN(color),GET_BLUE(color));
72+
}
73+
74+
uint32_t fsGetLedRGB(uint8_t index)
75+
{
76+
return rgbGetLedColor(ledMapping[index]);
7277
}
7378

7479
uint8_t getRGBColorIndex(uint32_t color)

radio/src/targets/taranis/led_driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ void fsLedRGB(uint8_t index, uint32_t color)
6969
GET_BLUE(color));
7070
}
7171

72+
uint32_t fsGetLedRGB(uint8_t index)
73+
{
74+
return rgbGetLedColor(ledMapping[index]);
75+
}
76+
7277
uint8_t getRGBColorIndex(uint32_t color)
7378
{
7479
for (uint8_t i = 0; i < DIM(colorTable); i++) {

0 commit comments

Comments
 (0)