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+
3148class 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
0 commit comments