From 32ba4a64ed84e92fbdbeb36216b04dffeee8a647 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Thu, 31 Jul 2025 14:23:11 +0200 Subject: [PATCH] Add friendly color names to color class for system page display --- lib/obp60task/LedSpiTask.cpp | 24 ++++++++++++++++++++++++ lib/obp60task/LedSpiTask.h | 4 +++- lib/obp60task/PageSystem.cpp | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/obp60task/LedSpiTask.cpp b/lib/obp60task/LedSpiTask.cpp index fbbd640..219495c 100644 --- a/lib/obp60task/LedSpiTask.cpp +++ b/lib/obp60task/LedSpiTask.cpp @@ -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 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){ uint16_t rt=f1; diff --git a/lib/obp60task/LedSpiTask.h b/lib/obp60task/LedSpiTask.h index c058503..ff63919 100644 --- a/lib/obp60task/LedSpiTask.h +++ b/lib/obp60task/LedSpiTask.h @@ -10,7 +10,7 @@ class Color{ uint8_t g; uint8_t b; 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){} Color(const Color &o):b(o.b),g(o.g),r(o.r){} bool equal(const Color &o) const{ @@ -22,6 +22,8 @@ class Color{ bool operator != (const Color &other) const{ return ! equal(other); } + String toHex(); + String toName(); }; static Color COLOR_GREEN=Color(0,255,0); diff --git a/lib/obp60task/PageSystem.cpp b/lib/obp60task/PageSystem.cpp index bc06b6b..700f9e9 100644 --- a/lib/obp60task/PageSystem.cpp +++ b/lib/obp60task/PageSystem.cpp @@ -310,7 +310,7 @@ private: getdisplay().setCursor(202, y0 + 80); getdisplay().print("Bl color:"); getdisplay().setCursor(320, y0 + 80); - getdisplay().print(commonData->backlight.color); + getdisplay().print(commonData->backlight.color.toName()); getdisplay().setCursor(202, y0 + 96); getdisplay().print("Bl mode:"); getdisplay().setCursor(320, y0 + 96);