esp32-sk6812/include/Animation/AnimationController.h
Thomas Kolb 917627c0d0 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
2019-12-10 22:41:11 +01:00

44 lines
899 B
C++

#pragma once
#include <memory>
#include "Animation.h"
#include <FreeRTOS.h>
#include <freertos/semphr.h>
class AnimationController
{
public:
enum DefaultAnimation {
FIRE_HOT = 0,
FIRE_COLD = 1,
NUM_DEFAULT_ANIMATIONS
};
AnimationController(Fader *fader);
void changeAnimation(std::unique_ptr<Animation> anim, bool transition = true);
void changeAnimation(DefaultAnimation animation_id, bool transition = true);
void loop(void);
void stop(void);
void restart(void);
bool isIdle(void)
{
return m_animation->finished() && !m_nextAnimation;
}
private:
Fader *m_fader;
std::unique_ptr<Animation> m_animation;
std::unique_ptr<Animation> m_nextAnimation;
SemaphoreHandle_t m_updateMutex;
uint64_t m_frame;
};