Add functions to treat all LEDs as a single strip

This commit is contained in:
Thomas Kolb 2022-09-09 20:10:15 +02:00
parent 03ff31067a
commit c9471331d3
4 changed files with 33 additions and 18 deletions

View file

@ -42,12 +42,18 @@ class Fader
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 pos, 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(uint32_t pos, const Color &color);
void fade_color(uint32_t strip, uint32_t module, const Color &color);
void fade_color(const Color &color); // for all LEDs
void add_color(uint32_t pos, const Color &color);
void add_color(uint32_t strip, uint32_t module, const Color &color);
void add_color(const Color &color); // for all LEDs
void set_fadestep(uint8_t newFadestep);
void update(void);

View file

@ -32,15 +32,10 @@ void RacerAnimation::Racer::render(void) const
int32_t idx1 = m_pos / 256;
int32_t idx2 = m_pos / 256 + 1;
uint32_t strip1 = m_fader->get_strip_idx(idx1);
uint32_t led1 = m_fader->get_led_idx(idx1);
uint32_t strip2 = m_fader->get_strip_idx(idx2);
uint32_t led2 = m_fader->get_led_idx(idx2);
int32_t scale1 = (idx2 * 256) - m_pos;
int32_t scale2 = m_pos - (idx1 * 256);
m_fader->add_color(strip1, led1,
m_fader->add_color(idx1,
Fader::Color{
static_cast<int16_t>(m_color.r * scale1 / 256),
static_cast<int16_t>(m_color.g * scale1 / 256),
@ -48,7 +43,7 @@ void RacerAnimation::Racer::render(void) const
static_cast<int16_t>(m_color.w * scale1 / 256)
});
m_fader->add_color(strip2, led2,
m_fader->add_color(idx2,
Fader::Color{
static_cast<int16_t>(m_color.r * scale2 / 256),
static_cast<int16_t>(m_color.g * scale2 / 256),
@ -66,7 +61,7 @@ RacerAnimation::RacerAnimation(Fader *fader, uint32_t racer_count)
int32_t maxpos = m_fader->strips() * m_fader->modules_per_strip() * 256;
std::uniform_int_distribution<int32_t> posRng(0, maxpos);
std::uniform_int_distribution<int32_t> speedRng(-256, 256);
std::uniform_int_distribution<int32_t> speedRng(-128, 128);
std::uniform_int_distribution<int16_t> colorRng(0, 255);
std::uniform_int_distribution<int16_t> whiteRng(0, 64);

View file

@ -12,8 +12,12 @@ Fader::Fader(std::size_t nstrips, std::size_t nmodules_per_strip, uint8_t fadest
void Fader::set_color(uint32_t strip, uint32_t module, const Fader::Color &color)
{
uint32_t idx = make_module_idx(strip, module);
set_color(idx, color);
}
m_targetColor[idx] = m_curColor[idx] = color;
void Fader::set_color(uint32_t pos, const Fader::Color &color)
{
m_targetColor[pos] = m_curColor[pos] = color;
m_somethingChanged = true;
}
@ -21,11 +25,15 @@ void Fader::set_color(uint32_t strip, uint32_t module, const Fader::Color &color
void Fader::add_color(uint32_t strip, uint32_t module, const Fader::Color &color)
{
uint32_t idx = make_module_idx(strip, module);
add_color(idx, color);
}
m_curColor[idx] += color;
m_curColor[idx].normalize();
m_targetColor[idx] += color;
m_targetColor[idx].normalize();
void Fader::add_color(uint32_t pos, const Fader::Color &color)
{
m_curColor[pos] += color;
m_curColor[pos].normalize();
m_targetColor[pos] += color;
m_targetColor[pos].normalize();
m_somethingChanged = true;
}
@ -33,8 +41,12 @@ void Fader::add_color(uint32_t strip, uint32_t module, const Fader::Color &color
void Fader::fade_color(uint32_t strip, uint32_t module, const Fader::Color &color)
{
uint32_t idx = make_module_idx(strip, module);
fade_color(idx, color);
}
m_targetColor[idx] = color;
void Fader::fade_color(uint32_t pos, const Fader::Color &color)
{
m_targetColor[pos] = color;
m_somethingChanged = true;
}

View file

@ -26,6 +26,8 @@
#include "coreids.h"
#define HOSTNAME "zamusiclight"
const uint32_t FRAME_INTERVAL_US = 16666;
const uint32_t NUM_STRIPS = 2;
const uint32_t NUM_LEDS = 150;
@ -59,7 +61,7 @@ void WiFiEvent(WiFiEvent_t event)
case SYSTEM_EVENT_ETH_START:
Serial.println("ETH Started");
//set eth hostname here
ETH.setHostname("zamusiclight");
ETH.setHostname(HOSTNAME);
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
@ -393,7 +395,7 @@ void wifi_setup(void)
{
Serial.println("Trying to connect...");
WiFi.setHostname("mlmini");
WiFi.setHostname(HOSTNAME);
for(size_t tries = 0; tries < 10; tries++)
{