56 lines
1.1 KiB
C++
56 lines
1.1 KiB
C++
|
|
// overall layout:
|
|
// queue for each led stripe
|
|
//
|
|
|
|
enum class EffectID
|
|
{
|
|
OFF,
|
|
STATIC,
|
|
CIRCLE,
|
|
CIRCLE_WAVE,
|
|
COLOR_FADE,
|
|
RAINBOW_FADE,
|
|
};
|
|
|
|
struct EffectCircularConfig
|
|
{
|
|
float speed; // in degrees per second
|
|
float width; // width in degrees
|
|
float brightnessFalloffFactor;
|
|
};
|
|
|
|
template <typename TLedStrip>
|
|
class AbstractEffect
|
|
{
|
|
public:
|
|
virtual int operator()(TLedStrip &s) = 0;
|
|
};
|
|
|
|
template <typename TLedStrip>
|
|
class EffectCircle : public AbstractEffect<TLedStrip>
|
|
{
|
|
public:
|
|
EffectCircle(const EffectCircularConfig &cfg) : config_(cfg) {}
|
|
int operator()(TLedStrip &s) override;
|
|
|
|
private:
|
|
EffectCircularConfig config_;
|
|
float currentPosition_; // between 0 and 1
|
|
};
|
|
|
|
unsigned char effectStorage[128];
|
|
|
|
template <typename TLedStrip>
|
|
AbstractEffect<TLedStrip> *makeEffect(const char *buffer)
|
|
{
|
|
const EffectID &effectId = *reinterpret_cast<const EffectID *>(buffer);
|
|
if (effectId == EffectID::CIRCLE)
|
|
{
|
|
auto cfg = reinterpret_cast<const EffectCircularConfig *>(buffer + sizeof(EffectID));
|
|
return new (effectStorage) EffectCircle<TLedStrip>(*cfg);
|
|
}
|
|
// read effect id code from buffer
|
|
// read config from buffer
|
|
}
|