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:
parent
c33a5fcade
commit
917627c0d0
|
@ -24,6 +24,7 @@ class AnimationController
|
|||
|
||||
void loop(void);
|
||||
|
||||
void stop(void);
|
||||
void restart(void);
|
||||
|
||||
bool isIdle(void)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -180,4 +180,8 @@ void FireAnimation::reset(void)
|
|||
m_running = true;
|
||||
|
||||
m_fader->set_fadestep(10);
|
||||
|
||||
for(auto &energy: m_energy) {
|
||||
energy = 0;
|
||||
}
|
||||
}
|
||||
|
|
21
src/main.cpp
21
src/main.cpp
|
@ -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});
|
||||
|
|
Loading…
Reference in a new issue