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 loop(void);
void stop(void);
void restart(void); void restart(void);
bool isIdle(void) bool isIdle(void)

View file

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

View file

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

View file

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