musicmouse/espmusicmouse/lib/ledtl/effects/Static.h

61 lines
1.2 KiB
C
Raw Normal View History

2021-11-17 23:18:10 +01:00
#pragma once
#include "effects/Common.h"
#include "helpers/ColorRGBW.h"
struct EffectStaticConfig
{
2021-12-15 22:47:28 +01:00
EffectStaticConfig(const ColorRGBW &c = ColorRGBW{0, 0, 0, 0}, uint16_t beg = 0, uint16_t en = 0)
: color(c), begin(beg), end(en) {}
2021-11-17 23:18:10 +01:00
ColorRGBW color;
2021-12-15 22:47:28 +01:00
uint16_t begin = 0;
uint16_t end = 0;
2021-11-17 23:18:10 +01:00
};
template <typename TLedStrip>
class EffectStatic
{
public:
static constexpr auto NUM_LEDS = numLeds<TLedStrip>();
2022-01-12 18:13:59 +01:00
using ConfigType = EffectStaticConfig;
2021-11-17 23:18:10 +01:00
EffectStatic(const EffectStaticConfig &cfg, TLedStrip &ledStrip)
: config_(cfg),
ledStrip_(ledStrip)
{
}
int operator()()
{
2021-12-15 22:47:28 +01:00
if (config_.begin == config_.end)
setLedRGBW(ledStrip_, 0, NUM_LEDS, config_.color);
else
setLedRGBW(ledStrip_, config_.begin, config_.end, config_.color);
2021-11-17 23:18:10 +01:00
return 10000; // nothing changing, return some large time to sleep
}
private:
EffectStaticConfig config_;
TLedStrip &ledStrip_;
};
// Traits
template <>
struct EffectIdToConfig<EffectId::STATIC>
{
using type = EffectStaticConfig;
};
template <>
struct EffectConfigToId<EffectStaticConfig>
{
static constexpr auto id = EffectId::STATIC;
};
template <typename TLedStrip>
struct EffectIdToClass<EffectId::STATIC, TLedStrip>
{
using type = EffectStatic<TLedStrip>;
};