Skip to content

Commit

Permalink
new rainbow loop animation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraus committed Mar 16, 2021
1 parent e234477 commit 26f748c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/floower-esp32/floower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ void Floower::startAnimation(FloowerColorAnimation animation) {
pixelsOriginColor = pixelsColor;
animations.StartAnimation(1, 10000, [=](const AnimationParam& param){ pixelsRainbowAnimationUpdate(param); });
}
else if (animation == RAINBOW_LOOP) {
pixelsTargetColor = pixelsColor = colorWhite;
animations.StartAnimation(1, 10000, [=](const AnimationParam& param){ pixelsRainbowLoopAnimationUpdate(param); });
}
else if (animation == CANDLE) {
pixelsTargetColor = pixelsColor = candleColor; // candle orange
for (uint8_t i = 0; i < 6; i++) {
Expand All @@ -342,10 +346,10 @@ void Floower::stopAnimation(bool retainColor) {

void Floower::pixelsRainbowAnimationUpdate(const AnimationParam& param) {
float hue = pixelsOriginColor.H + param.progress;
if (hue > 1.0) {
if (hue >= 1.0) {
hue = hue - 1;
}
pixelsColor = HsbColor(hue, 1, config->colorBrightness);
pixelsColor = HsbColor(hue, 1, pixelsOriginColor.B);
showColor(pixelsColor);

if (param.state == AnimationState_Completed) {
Expand All @@ -355,6 +359,21 @@ void Floower::pixelsRainbowAnimationUpdate(const AnimationParam& param) {
}
}

void Floower::pixelsRainbowLoopAnimationUpdate(const AnimationParam& param) {
double hue = param.progress;
double step = 1.0 / 6.0;
pixels.SetPixelColor(0, HsbColor(param.progress, 1, config->colorBrightness));
for (uint8_t i = 1; i < 7; i++, hue += step) {
if (hue >= 1.0) {
hue = hue - 1;
}
pixels.SetPixelColor(i, HsbColor(hue, 1, config->colorBrightness));
}
if (param.state == AnimationState_Completed) {
animations.RestartAnimation(param.index);
}
}

void Floower::pixelsCandleAnimationUpdate(const AnimationParam& param) {
pixels.SetPixelColor(0, pixelsTargetColor);
for (uint8_t i = 0; i < 6; i++) {
Expand Down
2 changes: 2 additions & 0 deletions src/floower-esp32/floower.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

enum FloowerColorAnimation {
RAINBOW,
RAINBOW_LOOP,
CANDLE
};

Expand Down Expand Up @@ -73,6 +74,7 @@ class Floower {
void pixelsTransitionAnimationUpdate(const AnimationParam& param);
void pixelsFlashAnimationUpdate(const AnimationParam& param);
void pixelsRainbowAnimationUpdate(const AnimationParam& param);
void pixelsRainbowLoopAnimationUpdate(const AnimationParam& param);
void pixelsCandleAnimationUpdate(const AnimationParam& param);
void showColor(HsbColor color);

Expand Down
4 changes: 2 additions & 2 deletions src/floower-esp32/remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void Remote::StateChangeCharacteristicsCallbacks::onWrite(BLECharacteristic *cha
if (CHECK_BIT(statePacket.data.mode, STATE_TRANSITION_MODE_BIT_COLOR)) {
// blossom color
HsbColor color = HsbColor(statePacket.data.getColor());
remote->floower->transitionColor(color.H, color.S, remote->config->colorBrightness, statePacket.data.duration * 100);
remote->floower->transitionColor(color.H, color.S, color.B, statePacket.data.duration * 100);
}
if (CHECK_BIT(statePacket.data.mode, STATE_TRANSITION_MODE_BIT_PETALS)) {
// petals open/close
Expand All @@ -238,7 +238,7 @@ void Remote::StateChangeCharacteristicsCallbacks::onWrite(BLECharacteristic *cha
// play animation (according to value)
switch (statePacket.data.value) {
case 1:
remote->floower->startAnimation(FloowerColorAnimation::RAINBOW);
remote->floower->startAnimation(FloowerColorAnimation::RAINBOW_LOOP);
break;
case 2:
remote->floower->startAnimation(FloowerColorAnimation::CANDLE);
Expand Down

0 comments on commit 26f748c

Please sign in to comment.