#pragma once #include 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; }; } }; Fader(std::size_t nmodules, 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(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& get_color_values(void) { m_somethingChanged = false; return m_curColor; } 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); uint8_t m_fadestep; bool m_somethingChanged; std::vector m_curColor; std::vector m_targetColor; };