Skip to content

Commit

Permalink
candle animation
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripraus committed Dec 23, 2020
1 parent 9de5e56 commit 6f3f299
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/floower-esp32/automaton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void Automaton::init() {
changeState(STATE_STANDBY);
floower->onLeafTouch([=](FloowerTouchEvent event){ onLeafTouch(event); });
remote->onTakeOver([=]() { onRemoteTookOver(); }); // remote controller took over

floower->startAnimation(FloowerColorAnimation::CANDLE);
}

void Automaton::update() {
Expand Down
18 changes: 7 additions & 11 deletions src/floower-esp32/floower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ void Floower::startAnimation(FloowerColorAnimation animation) {
animations.StartAnimation(1, 10000, [=](const AnimationParam& param){ pixelsRainbowAnimationUpdate(param); });
}
else if (animation == CANDLE) {
animations.StartAnimation(1, 10000, [=](const AnimationParam& param){ pixelsCandleAnimationUpdate(param); });
pixelsTargetColor = pixelsColor = RgbColor(255, 100, 0); // orange
animations.StartAnimation(1, 100, [=](const AnimationParam& param){ pixelsCandleAnimationUpdate(param); });
}
}

Expand Down Expand Up @@ -322,18 +323,13 @@ void Floower::pixelsRainbowAnimationUpdate(const AnimationParam& param) {
}

void Floower::pixelsCandleAnimationUpdate(const AnimationParam& param) {
HsbColor hsbOriginal = HsbColor(pixelsOriginColor);
float hue = hsbOriginal.H + param.progress;
if (hue > 1.0) {
hue = hue - 1;
}
pixelsColor = RgbColor(HsbColor(hue, 1, 0.4)); // TODO: fine tune
showColor(pixelsColor);

if (param.state == AnimationState_Completed) {
if (pixelsTargetColor.CalculateBrightness() > 0) { // while there is something to show
animations.RestartAnimation(param.index);
HsbColor hsbColor = HsbColor(pixelsTargetColor);
for (uint8_t i = 0; i < 7; i++) {
hsbColor.B = random(40, 100) / 100.0;
pixels.SetPixelColor(i, hsbColor);
}
animations.StartAnimation(param.index, random(20, 200), [=](const AnimationParam& param){ pixelsCandleAnimationUpdate(param); });
}
}

Expand Down

0 comments on commit 6f3f299

Please sign in to comment.