diff --git a/src/Fader.cpp b/src/Fader.cpp index e865fee..a9db117 100644 --- a/src/Fader.cpp +++ b/src/Fader.cpp @@ -1,31 +1,39 @@ #include "Fader.h" -Fader::Fader(std::size_t nmodules, uint8_t fadestep) - : m_fadestep(fadestep), - m_curColor(nmodules), - m_targetColor(nmodules) +Fader::Fader(std::size_t nstrips, std::size_t nmodules_per_strip, uint8_t fadestep) + : m_strips(nstrips), + m_modulesPerStrip(nmodules_per_strip), + m_fadestep(fadestep), + m_curColor(nstrips * nmodules_per_strip), + m_targetColor(nstrips * nmodules_per_strip) {} -void Fader::set_color(uint32_t module, const Fader::Color &color) +void Fader::set_color(uint32_t strip, uint32_t module, const Fader::Color &color) { - m_targetColor[module] = m_curColor[module] = color; + uint32_t idx = make_module_idx(strip, module); + + m_targetColor[idx] = m_curColor[idx] = color; m_somethingChanged = true; } -void Fader::add_color(uint32_t module, const Fader::Color &color) +void Fader::add_color(uint32_t strip, uint32_t module, const Fader::Color &color) { - m_curColor[module] += color; - m_curColor[module].normalize(); - m_targetColor[module] += color; - m_targetColor[module].normalize(); + uint32_t idx = make_module_idx(strip, module); + + m_curColor[idx] += color; + m_curColor[idx].normalize(); + m_targetColor[idx] += color; + m_targetColor[idx].normalize(); m_somethingChanged = true; } -void Fader::fade_color(uint32_t module, const Fader::Color &color) +void Fader::fade_color(uint32_t strip, uint32_t module, const Fader::Color &color) { - m_targetColor[module] = color; + uint32_t idx = make_module_idx(strip, module); + + m_targetColor[idx] = color; m_somethingChanged = true; } diff --git a/src/Fader.h b/src/Fader.h index 3892bf0..4a42222 100644 --- a/src/Fader.h +++ b/src/Fader.h @@ -28,11 +28,11 @@ class Fader }; - Fader(std::size_t nmodules, uint8_t fadestep = 1); + Fader(std::size_t nstrips, std::size_t nmodules_per_strip, uint8_t fadestep = 1); - void set_color(uint32_t module, const Color &color); - void fade_color(uint32_t module, const Color &color); - void add_color(uint32_t module, const Color &color); + void set_color(uint32_t strip, uint32_t module, const Color &color); + void fade_color(uint32_t strip, uint32_t module, const Color &color); + void add_color(uint32_t strip, uint32_t module, const Color &color); void set_color(const Color &color); // for all LEDs void fade_color(const Color &color); // for all LEDs void add_color(const Color &color); // for all LEDs @@ -50,6 +50,9 @@ class Fader return m_curColor; } + std::size_t modules_per_strip(void) { return m_modulesPerStrip; } + std::size_t strips(void) { return m_strips; } + private: /*! * Fade the colour value in cur towards target. @@ -60,6 +63,13 @@ class Fader */ bool update_fade(int16_t *cur, const int16_t *target); + inline uint32_t make_module_idx(uint32_t strip, uint32_t module) + { + return strip * m_modulesPerStrip + module; + } + + std::size_t m_strips; + std::size_t m_modulesPerStrip; uint8_t m_fadestep; bool m_somethingChanged; diff --git a/src/main.cpp b/src/main.cpp index 7cddb0d..bc2a97e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,10 +12,11 @@ #include const uint32_t FRAME_INTERVAL_US = 16666; -const uint32_t NUM_LEDS = 138; +const uint32_t NUM_STRIPS = 2; +const uint32_t NUM_LEDS = 69; std::array STRANDS { // Avoid using any of the strapping pins on the ESP32, anything >=32, 16, 17... not much left. - strand_t {.rmtChannel = 0, .gpioNum = 4, .ledType = LED_SK6812W_V1, .brightLimit = 32, .numPixels = NUM_LEDS}, + strand_t {.rmtChannel = 0, .gpioNum = 4, .ledType = LED_SK6812W_V1, .brightLimit = 32, .numPixels = NUM_LEDS * NUM_STRIPS}, }; bool led_on = false;