esp32-sk6812/include/Animation/AnimationController.h

52 lines
1.1 KiB
C
Raw Normal View History

#pragma once
#include <memory>
#include "Animation.h"
#include <FreeRTOS.h>
#include <freertos/semphr.h>
class AnimationController
{
public:
2019-12-08 22:58:50 +01:00
enum DefaultAnimation {
FIRE_HOT = 0,
FIRE_COLD = 1,
2019-12-15 21:39:03 +01:00
SNOWFALL = 2,
2019-12-08 22:58:50 +01:00
NUM_DEFAULT_ANIMATIONS
};
static const constexpr std::array<const char*, NUM_DEFAULT_ANIMATIONS> AnimationNames{
"Hot Fire",
2019-12-15 21:39:03 +01:00
"Cold Fire",
"Snowfall"
};
AnimationController(Fader *fader);
2019-12-03 22:09:55 +01:00
void changeAnimation(std::unique_ptr<Animation> anim, bool transition = true);
2019-12-08 22:58:50 +01:00
void changeAnimation(DefaultAnimation animation_id, bool transition = true);
void loop(void);
void stop(void);
2019-12-03 22:09:55 +01:00
void restart(void);
bool isIdle(void)
{
return m_animation->finished() && !m_nextAnimation;
}
private:
Fader *m_fader;
std::unique_ptr<Animation> m_animation;
2019-12-03 22:09:55 +01:00
std::unique_ptr<Animation> m_nextAnimation;
SemaphoreHandle_t m_updateMutex;
uint64_t m_frame;
};