Add friendly color names to color class for system page display
This commit is contained in:
parent
7edd201daa
commit
32ba4a64ed
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue