fixes
This commit is contained in:
@@ -36,6 +36,8 @@ public:
|
||||
|
||||
beginIdx_ = constrain(static_cast<int>(cfg.begin * NUM_LEDS + 0.5f), 0, NUM_LEDS - 1);
|
||||
endIdx_ = constrain(static_cast<int>(cfg.end * NUM_LEDS + 0.5f), 0, NUM_LEDS - 1);
|
||||
while (endIdx_ < beginIdx_)
|
||||
endIdx_ += NUM_LEDS;
|
||||
}
|
||||
|
||||
bool finished() const { return finished_; }
|
||||
@@ -45,22 +47,25 @@ public:
|
||||
if (finished_)
|
||||
return 1000000;
|
||||
|
||||
const float progress = static_cast<float>(DELAY_MS * calls_) / config_.transition_time_in_ms;
|
||||
const float progress = config_.transition_time_in_ms > 0.0f ? static_cast<float>(DELAY_MS * calls_) / config_.transition_time_in_ms : 1.f;
|
||||
|
||||
// Finished case
|
||||
if(progress > 1.0) {
|
||||
if (config_.transition_time_in_ms <= 0.0f || progress >= 1.0)
|
||||
{
|
||||
finished_ = true;
|
||||
clear(ledStrip_);
|
||||
for (int i = beginIdx_; i < endIdx_; i += config_.increment)
|
||||
setLedRGBW(ledStrip_, i % NUM_LEDS, config_.color);
|
||||
return 10000000;
|
||||
}
|
||||
|
||||
// In-progress case
|
||||
clear(ledStrip_);
|
||||
for(int i = beginIdx_; i != endIdx_; i += config_.increment) {
|
||||
ColorRGBW newColor = hsv2rgb(interpolate(rgb2hsv(state_[i]), rgb2hsv(config_.color), progress));
|
||||
newColor.w = config_.color.w * progress + state_[i].w * (1 - progress);
|
||||
setLedRGBW(ledStrip_, i, newColor);
|
||||
if(i >= NUM_LEDS)
|
||||
i = 0;
|
||||
for (int i = beginIdx_; i < endIdx_; i += config_.increment)
|
||||
{
|
||||
const auto idx = i % NUM_LEDS;
|
||||
ColorRGBW newColor = ColorRGBW::interpolate(state_[idx], config_.color, progress);
|
||||
setLedRGBW(ledStrip_, idx, newColor);
|
||||
}
|
||||
|
||||
++calls_;
|
||||
@@ -68,6 +73,11 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static int int_interpolate(int prev, int next, float progress)
|
||||
{
|
||||
return static_cast<float>(prev) * (1 - progress) +
|
||||
static_cast<float>(next) * progress;
|
||||
}
|
||||
EffectStaticDetailedConfig config_;
|
||||
TLedStrip &ledStrip_;
|
||||
ColorRGBW state_[NUM_LEDS];
|
||||
|
||||
@@ -13,4 +13,14 @@ struct ColorRGBW
|
||||
uint8_t(s * b),
|
||||
uint8_t(s * w)};
|
||||
}
|
||||
|
||||
static inline ColorRGBW interpolate(const ColorRGBW &c1, const ColorRGBW &c2, float f)
|
||||
{
|
||||
return ColorRGBW{
|
||||
static_cast<uint8_t>((1.0f - f) * static_cast<float>(c1.r) + f * static_cast<float>(c2.r)),
|
||||
static_cast<uint8_t>((1.0f - f) * static_cast<float>(c1.g) + f * static_cast<float>(c2.g)),
|
||||
static_cast<uint8_t>((1.0f - f) * static_cast<float>(c1.b) + f * static_cast<float>(c2.b)),
|
||||
static_cast<uint8_t>((1.0f - f) * static_cast<float>(c1.w) + f * static_cast<float>(c2.w)),
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user