Fader: flip logical addressing in specific sub-strips

This is useful if „displays“ are build using zig-zag interconnection of
the single strips
This commit is contained in:
Thomas Kolb 2019-11-25 22:02:00 +01:00
parent 373bed9121
commit 6cbfa854f1
3 changed files with 18 additions and 9 deletions

View file

@ -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<Color> m_curColor;

View file

@ -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;
}

View file

@ -14,8 +14,9 @@
#include <esp32_digital_led_funcs.h>
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<strand_t, 1> 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()