From 6cbfa854f186a4a0889525e3f2869d8e2f47cb71 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Mon, 25 Nov 2019 22:02:00 +0100 Subject: [PATCH] Fader: flip logical addressing in specific sub-strips MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is useful if „displays“ are build using zig-zag interconnection of the single strips --- include/Fader.h | 8 +++----- src/Fader.cpp | 12 +++++++++++- src/main.cpp | 7 ++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/Fader.h b/include/Fader.h index 4a42222..9a496dd 100644 --- a/include/Fader.h +++ b/include/Fader.h @@ -28,7 +28,7 @@ class Fader }; - Fader(std::size_t nstrips, std::size_t nmodules_per_strip, uint8_t fadestep = 1); + Fader(std::size_t nstrips, std::size_t nmodules_per_strip, uint8_t fadestep = 1, uint32_t flip_strips_mask = 0x00); void set_color(uint32_t strip, uint32_t module, const Color &color); void fade_color(uint32_t strip, uint32_t module, const Color &color); @@ -63,14 +63,12 @@ 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; - } + inline uint32_t make_module_idx(uint32_t strip, uint32_t module); std::size_t m_strips; std::size_t m_modulesPerStrip; uint8_t m_fadestep; + uint32_t m_flipStripsMask; bool m_somethingChanged; std::vector m_curColor; diff --git a/src/Fader.cpp b/src/Fader.cpp index a9db117..ffcd9bf 100644 --- a/src/Fader.cpp +++ b/src/Fader.cpp @@ -1,9 +1,10 @@ #include "Fader.h" -Fader::Fader(std::size_t nstrips, std::size_t nmodules_per_strip, uint8_t fadestep) +Fader::Fader(std::size_t nstrips, std::size_t nmodules_per_strip, uint8_t fadestep, uint32_t flip_strips_mask) : m_strips(nstrips), m_modulesPerStrip(nmodules_per_strip), m_fadestep(fadestep), + m_flipStripsMask(flip_strips_mask), m_curColor(nstrips * nmodules_per_strip), m_targetColor(nstrips * nmodules_per_strip) {} @@ -107,3 +108,12 @@ void Fader::update(void) m_somethingChanged = update_fade(&(m_curColor[i].w), &(m_targetColor[i].w)) || m_somethingChanged; } } + +uint32_t Fader::make_module_idx(uint32_t strip, uint32_t module) +{ + bool flip = m_flipStripsMask & (1 << strip); + if(flip) { + module = m_modulesPerStrip - module - 1; + } + return strip * m_modulesPerStrip + module; +} diff --git a/src/main.cpp b/src/main.cpp index 7e74986..efe0889 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,8 +14,9 @@ #include const uint32_t FRAME_INTERVAL_US = 16666; -const uint32_t NUM_STRIPS = 2; -const uint32_t NUM_LEDS = 69; +const uint32_t NUM_STRIPS = 8; +const uint32_t NUM_LEDS = 16; +const uint32_t FLIP_STRIPS_MASK = 0x000000AA; 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 * NUM_STRIPS}, @@ -28,7 +29,7 @@ size_t frame; WiFiMulti wiFiMulti; -Fader ledFader(NUM_STRIPS, NUM_LEDS); +Fader ledFader(NUM_STRIPS, NUM_LEDS, 1, FLIP_STRIPS_MASK); UDPProto udpProto(&ledFader); bool initLEDs()