/// a static array of red-green-blue-white values together with free functions to set them #pragma once #include "helpers/ColorRGBW.h" #include "Arduino.h" // TODO #include template class LedStripRGBW { public: static constexpr int NUM_LEDS = TNumLeds; void set(int idx, uint8_t r, uint8_t g, uint8_t b, uint8_t w) { // green: 0 // red: 8 // blue: 16 // white: 24 if (idx < 0 || idx >= NUM_LEDS) Serial.printf("Out of bounds idx %i\n", idx); else data_[idx] = (g << 0) | (r << 8) | (b << 16) | (w << 24); } const uint32_t *rawData() const { return data_; } constexpr static int numLeds() { return TNumLeds; } private: uint32_t data_[TNumLeds]; }; template constexpr int numLeds() { return TLedStrip::NUM_LEDS; } template constexpr int numLeds(const LedStripRGBW &) { return TNumLeds; } template void setLedRGB(LedStripRGBW &s, int beginIdx, int endIdx, uint8_t r, uint8_t g, uint8_t b) { for (int i = beginIdx; i < endIdx; ++i) s.set(i, r, g, b, 0); } template void setLedRGB(LedStripRGBW &s, int idx, uint8_t r, uint8_t g, uint8_t b) { s.set(idx, r, g, b, 0); } template void setLedRGBW(LedStripRGBW &s, int beginIdx, int endIdx, uint8_t r, uint8_t g, uint8_t b, uint8_t w) { for (int i = beginIdx; i < endIdx; ++i) s.set(i, r, g, b, w); } template void setLedRGBW(LedStripRGBW &s, int idx, uint8_t r, uint8_t g, uint8_t b, uint8_t w) { s.set(idx, r, g, b, w); } template void setLedRGBW(LedStripRGBW &s, int idx, const ColorRGBW &c) { s.set(idx, c.r, c.g, c.b, c.w); } template void clear(LedStripRGBW &s) { for (int i = 0; i < TNumLeds; ++i) s.set(i, 0, 0, 0, 0); }