diff --git a/lib/obp60task/LedSpiTask.cpp b/lib/obp60task/LedSpiTask.cpp index 74497e7..506c457 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; @@ -231,4 +255,4 @@ void handleSpiLeds(void *param){ void createSpiLedTask(LedTaskData *param){ xTaskCreate(handleSpiLeds,"handleLeds",4000,param,3,NULL); -} \ No newline at end of file +} 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);