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

64 lines
1.3 KiB
C
Raw Normal View History

2021-11-27 21:18:54 +01:00
#pragma once
#include "effects/Common.h"
#include "effects/AlexaSwipe.h"
#include "effects/RandomTwoColorInterpolation.h"
#pragma pack(push, 1)
struct EffectSwipeAndChangeConfig
{
EffectAlexaSwipeConfig swipeCfg;
EffectRandomTwoColorInterpolationConfig changeCfg;
};
#pragma pack(pop)
template <typename TLedStrip>
class EffectSwipeAndChange
{
public:
EffectSwipeAndChange(const EffectSwipeAndChangeConfig &cfg, TLedStrip &ledStrip)
: effect1_(cfg.swipeCfg, ledStrip),
effect2_(cfg.changeCfg, ledStrip),
effectRunning_(0)
{
}
int operator()()
{
if (!effect1_.finished())
{
return effect1_();
}
else
{
if (effectRunning_ == 0)
effect2_.begin();
effectRunning_ = 1;
return effect2_();
}
}
private:
EffectAlexaSwipe<TLedStrip> effect1_;
EffectRandomTwoColorInterpolation<TLedStrip> effect2_;
int effectRunning_;
};
// Traits
template <>
struct EffectIdToConfig<EffectId::SWIPE_AND_CHANGE>
{
using type = EffectSwipeAndChangeConfig;
};
template <>
struct EffectConfigToId<EffectSwipeAndChangeConfig>
{
static constexpr auto id = EffectId::SWIPE_AND_CHANGE;
};
template <typename TLedStrip>
struct EffectIdToClass<EffectId::SWIPE_AND_CHANGE, TLedStrip>
{
using type = EffectSwipeAndChange<TLedStrip>;
};