Firmware cleanup
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "helpers/ColorConversions.h"
|
||||
#include "helpers/BellCurve.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct EffectAlexaSwipeConfig
|
||||
{
|
||||
float primaryColorWidth; // in degrees
|
||||
@@ -17,6 +18,7 @@ struct EffectAlexaSwipeConfig
|
||||
ColorRGBW primaryColor;
|
||||
ColorRGBW secondaryColor;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
template <typename TLedStrip>
|
||||
class EffectAlexaSwipe
|
||||
@@ -38,7 +40,8 @@ public:
|
||||
speed_(cfg.swipeSpeed / 360 / 1000 * NUM_LEDS * DELAY_MS),
|
||||
startPosition_(cfg.startPosition / 360.0f * NUM_LEDS),
|
||||
primaryColor_(rgb2hsv(cfg.primaryColor)),
|
||||
secondaryColor_(rgb2hsv(cfg.secondaryColor))
|
||||
secondaryColor_(rgb2hsv(cfg.secondaryColor)),
|
||||
finished_(false)
|
||||
{
|
||||
if (cfg.forward)
|
||||
{
|
||||
@@ -52,6 +55,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool finished() { return finished_; }
|
||||
|
||||
int operator()()
|
||||
{
|
||||
clear(ledStrip_);
|
||||
@@ -72,8 +77,13 @@ public:
|
||||
}
|
||||
}
|
||||
currentPosition_ += direction_ * speed_;
|
||||
currentPosition_ = std::min(currentPosition_, float(NUM_LEDS) / 2.0f + bellCurveWidth_ / 2);
|
||||
currentPosition_ = std::max(currentPosition_, 0.0f);
|
||||
const auto maxPosition = float(NUM_LEDS) / 2.0f + bellCurveWidth_ / 2;
|
||||
const auto minPosition = 0.0f;
|
||||
currentPosition_ = std::min(currentPosition_, maxPosition);
|
||||
currentPosition_ = std::max(currentPosition_, minPosition);
|
||||
if (currentPosition_ <= minPosition || currentPosition_ >= maxPosition)
|
||||
finished_ = true;
|
||||
|
||||
return DELAY_MS;
|
||||
}
|
||||
|
||||
@@ -119,6 +129,8 @@ private:
|
||||
const ColorHSV primaryColor_;
|
||||
const ColorHSV secondaryColor_;
|
||||
float direction_;
|
||||
|
||||
bool finished_;
|
||||
};
|
||||
|
||||
// Traits
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
#include "helpers/ColorRGBW.h"
|
||||
#include "helpers/BellCurve.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct EffectCircularConfig
|
||||
{
|
||||
float speed; // in degrees per second
|
||||
float width; // width in degrees
|
||||
ColorRGBW color;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
template <typename TLedStrip>
|
||||
class EffectCircular
|
||||
|
||||
@@ -5,7 +5,8 @@ enum class EffectId
|
||||
STATIC,
|
||||
CIRCULAR,
|
||||
ALEXA_SWIPE,
|
||||
RANDOM_TWO_COLOR_INTERPOLATION
|
||||
RANDOM_TWO_COLOR_INTERPOLATION,
|
||||
SWIPE_AND_CHANGE, // combination of ALEXA_SWIPE and RANDOM_TWO_COLOR_INTERPOLATION
|
||||
};
|
||||
|
||||
template <EffectId id>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "helpers/ColorHSV.h"
|
||||
#include "helpers/ColorConversions.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct EffectRandomTwoColorInterpolationConfig
|
||||
{
|
||||
int32_t cycleDurationMs;
|
||||
@@ -18,6 +19,7 @@ struct EffectRandomTwoColorInterpolationConfig
|
||||
ColorHSV color1;
|
||||
ColorHSV color2;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
template <typename TLedStrip>
|
||||
class EffectRandomTwoColorInterpolation
|
||||
@@ -43,6 +45,13 @@ public:
|
||||
randomizeColors(nextColors_);
|
||||
}
|
||||
|
||||
void begin()
|
||||
{
|
||||
if (config_.startWithExisting)
|
||||
for (int i = 0; i < NUM_LEDS; ++i)
|
||||
currentColors_[i] = rgb2hsv(getLedRGBW(ledStrip_, i));
|
||||
}
|
||||
|
||||
int operator()()
|
||||
{
|
||||
for (int i = 0; i < NUM_LEDS; ++i)
|
||||
|
||||
64
espmusicmouse/lib/ledtl/effects/SwipeAndChange.h
Normal file
64
espmusicmouse/lib/ledtl/effects/SwipeAndChange.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#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>;
|
||||
};
|
||||
Reference in New Issue
Block a user