Extended Fader to support multiple logical strips

This commit is contained in:
Thomas Kolb 2019-11-17 17:56:08 +01:00
parent 95d295e425
commit 926ea316f7
3 changed files with 38 additions and 19 deletions

View file

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

View file

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

View file

@ -12,10 +12,11 @@
#include <esp32_digital_led_funcs.h>
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<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},
strand_t {.rmtChannel = 0, .gpioNum = 4, .ledType = LED_SK6812W_V1, .brightLimit = 32, .numPixels = NUM_LEDS * NUM_STRIPS},
};
bool led_on = false;