Add friendly color names to color class for system page display

This commit is contained in:
Thomas Hooge 2025-07-31 14:23:11 +02:00
parent 7edd201daa
commit 32ba4a64ed
3 changed files with 28 additions and 2 deletions

View File

@ -14,6 +14,30 @@ https://controllerstech.com/ws2812-leds-using-spi/
*/ */
String Color::toHex() {
char hexColor[8];
sprintf(hexColor, "#%02X%02X%02X", r, g, b);
return String(hexColor);
}
String Color::toName() {
static std::map<int, String> const names = {
{0xff0000, "Red"},
{0x00ff00, "Green"},
{0x0000ff, "Blue",},
{0xff9900, "Orange"},
{0xffff00, "Yellow"},
{0x3366ff, "Aqua"},
{0xff0066, "Violet"},
{0xffffff, "White"}
};
int color = (r << 16) + (g << 8) + b;
auto it = names.find(color);
if (it == names.end()) {
return toHex();
}
return it->second;
}
static uint8_t mulcolor(uint8_t f1, uint8_t f2){ static uint8_t mulcolor(uint8_t f1, uint8_t f2){
uint16_t rt=f1; uint16_t rt=f1;

View File

@ -10,7 +10,7 @@ class Color{
uint8_t g; uint8_t g;
uint8_t b; uint8_t b;
Color():r(0),g(0),b(0){} Color():r(0),g(0),b(0){}
Color(uint8_t cr, uint8_t cg,uint8_t cb): Color(uint8_t cr, uint8_t cg, uint8_t cb):
b(cb),g(cg),r(cr){} b(cb),g(cg),r(cr){}
Color(const Color &o):b(o.b),g(o.g),r(o.r){} Color(const Color &o):b(o.b),g(o.g),r(o.r){}
bool equal(const Color &o) const{ bool equal(const Color &o) const{
@ -22,6 +22,8 @@ class Color{
bool operator != (const Color &other) const{ bool operator != (const Color &other) const{
return ! equal(other); return ! equal(other);
} }
String toHex();
String toName();
}; };
static Color COLOR_GREEN=Color(0,255,0); static Color COLOR_GREEN=Color(0,255,0);

View File

@ -310,7 +310,7 @@ private:
getdisplay().setCursor(202, y0 + 80); getdisplay().setCursor(202, y0 + 80);
getdisplay().print("Bl color:"); getdisplay().print("Bl color:");
getdisplay().setCursor(320, y0 + 80); getdisplay().setCursor(320, y0 + 80);
getdisplay().print(commonData->backlight.color); getdisplay().print(commonData->backlight.color.toName());
getdisplay().setCursor(202, y0 + 96); getdisplay().setCursor(202, y0 + 96);
getdisplay().print("Bl mode:"); getdisplay().print("Bl mode:");
getdisplay().setCursor(320, y0 + 96); getdisplay().setCursor(320, y0 + 96);