Smoother transitions between UDP and animation

- stop() animation before changing state and wait for completion
- additionally fade to black (in case animation does not stop at black
  or when UDP stream ends)
- reset() the animation when changing back to the animation state
This commit is contained in:
Thomas Kolb 2019-12-10 22:41:11 +01:00
parent c33a5fcade
commit 917627c0d0
4 changed files with 28 additions and 3 deletions

View file

@ -24,6 +24,7 @@ class AnimationController
void loop(void);
void stop(void);
void restart(void);
bool isIdle(void)

View file

@ -64,6 +64,11 @@ void AnimationController::loop(void)
xSemaphoreGive(m_updateMutex);
}
void AnimationController::stop(void)
{
m_animation->stop();
}
void AnimationController::restart(void)
{
m_animation->reset();

View file

@ -180,4 +180,8 @@ void FireAnimation::reset(void)
m_running = true;
m_fader->set_fadestep(10);
for(auto &energy: m_energy) {
energy = 0;
}
}

View file

@ -90,7 +90,8 @@ bool initLEDs()
enum LEDState {
UDP,
ANIMATION,
TRANSITION
TRANSITION,
TRANSITION_FADE2BLACK
};
static void ledFSM(void)
@ -135,16 +136,30 @@ static void ledFSM(void)
if(udpProto.loop()) {
lastUDPUpdate = millis();
ledFader.update();
} else if(millis() - lastUDPUpdate > 3000) {
// seems like no more UDP data arrives -> transition to ANIMATION state
nextState = ANIMATION;
ledState = TRANSITION;
}
ledFader.update();
break;
case TRANSITION:
Serial.print("T");
Serial.print("S");
if(stateEntered) {
animController.stop();
}
if(animController.isIdle()) {
ledState = TRANSITION_FADE2BLACK;
} else {
animController.loop();
}
break;
case TRANSITION_FADE2BLACK:
Serial.print("F");
if(stateEntered) {
ledFader.set_fadestep(2);
ledFader.fade_color(Fader::Color{0, 0, 0, 0});