2019-11-17 01:16:46 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class Fader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Color {
|
|
|
|
int16_t r, g, b, w;
|
|
|
|
|
|
|
|
Color(int16_t ir = 0, int16_t ig = 0, int16_t ib = 0, int16_t iw = 0) : r(ir), g(ig), b(ib), w(iw) {}
|
|
|
|
|
|
|
|
void operator += (const Color &color)
|
|
|
|
{
|
|
|
|
this->r += color.r;
|
|
|
|
this->g += color.g;
|
|
|
|
this->b += color.b;
|
|
|
|
this->w += color.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void normalize(void)
|
|
|
|
{
|
|
|
|
if(r > 255) { r = 255; } else if (r < 0) { r = 0; };
|
|
|
|
if(g > 255) { g = 255; } else if (g < 0) { g = 0; };
|
|
|
|
if(b > 255) { b = 255; } else if (b < 0) { b = 0; };
|
|
|
|
if(w > 255) { w = 255; } else if (w < 0) { w = 0; };
|
|
|
|
}
|
2019-12-05 01:11:37 +01:00
|
|
|
|
|
|
|
void gamma_correct(void)
|
|
|
|
{
|
|
|
|
r = r * r / 255;
|
|
|
|
g = g * g / 255;
|
|
|
|
b = b * b / 255;
|
|
|
|
w = w * w / 255;
|
|
|
|
}
|
2019-11-17 01:16:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-11-25 22:02:00 +01:00
|
|
|
Fader(std::size_t nstrips, std::size_t nmodules_per_strip, uint8_t fadestep = 1, uint32_t flip_strips_mask = 0x00);
|
2019-11-17 01:16:46 +01:00
|
|
|
|
2019-11-17 17:56:08 +01:00
|
|
|
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);
|
2019-11-17 01:16:46 +01:00
|
|
|
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
|
|
|
|
void set_fadestep(uint8_t newFadestep);
|
|
|
|
|
|
|
|
void update(void);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \returns Whether any color value has changed since the last call to getColorValues().
|
|
|
|
*/
|
|
|
|
bool something_changed(void) const {return m_somethingChanged; };
|
|
|
|
|
|
|
|
const std::vector<Color>& get_color_values(void) {
|
|
|
|
m_somethingChanged = false;
|
|
|
|
return m_curColor;
|
|
|
|
}
|
|
|
|
|
2019-11-17 17:56:08 +01:00
|
|
|
std::size_t modules_per_strip(void) { return m_modulesPerStrip; }
|
|
|
|
std::size_t strips(void) { return m_strips; }
|
|
|
|
|
2019-11-17 01:16:46 +01:00
|
|
|
private:
|
|
|
|
/*!
|
|
|
|
* Fade the colour value in cur towards target.
|
|
|
|
*
|
|
|
|
* \param cur The colour value to update.
|
|
|
|
* \param target The target value that should be reached.
|
|
|
|
* \returns Whether the value was actually changed.
|
|
|
|
*/
|
|
|
|
bool update_fade(int16_t *cur, const int16_t *target);
|
|
|
|
|
2019-11-25 22:02:00 +01:00
|
|
|
inline uint32_t make_module_idx(uint32_t strip, uint32_t module);
|
2019-11-17 17:56:08 +01:00
|
|
|
|
|
|
|
std::size_t m_strips;
|
|
|
|
std::size_t m_modulesPerStrip;
|
2019-11-17 01:16:46 +01:00
|
|
|
uint8_t m_fadestep;
|
2019-11-25 22:02:00 +01:00
|
|
|
uint32_t m_flipStripsMask;
|
2019-11-17 01:16:46 +01:00
|
|
|
bool m_somethingChanged;
|
|
|
|
|
|
|
|
std::vector<Color> m_curColor;
|
|
|
|
std::vector<Color> m_targetColor;
|
2019-12-05 01:11:37 +01:00
|
|
|
};
|