2019-12-02 23:06:04 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "Animation.h"
|
|
|
|
|
2019-12-09 22:22:51 +01:00
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <freertos/semphr.h>
|
|
|
|
|
2019-12-14 23:12:57 +01:00
|
|
|
|
2019-12-02 23:06:04 +01:00
|
|
|
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-23 19:56:33 +01:00
|
|
|
FONT_TEST = 3,
|
2019-12-30 12:18:04 +01:00
|
|
|
MATRIX_CODE = 4,
|
2019-12-31 23:39:09 +01:00
|
|
|
FIREWORK = 5,
|
2019-12-08 22:58:50 +01:00
|
|
|
|
|
|
|
NUM_DEFAULT_ANIMATIONS
|
|
|
|
};
|
|
|
|
|
2019-12-14 23:12:57 +01:00
|
|
|
static const constexpr std::array<const char*, NUM_DEFAULT_ANIMATIONS> AnimationNames{
|
|
|
|
"Hot Fire",
|
2019-12-15 21:39:03 +01:00
|
|
|
"Cold Fire",
|
2019-12-23 19:56:33 +01:00
|
|
|
"Snowfall",
|
2019-12-30 12:18:04 +01:00
|
|
|
"Font Test",
|
2019-12-31 23:39:09 +01:00
|
|
|
"Matrix Code",
|
|
|
|
"Fireworks"
|
2019-12-14 23:12:57 +01:00
|
|
|
};
|
|
|
|
|
2019-12-02 23:06:04 +01:00
|
|
|
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);
|
|
|
|
|
2019-12-02 23:06:04 +01:00
|
|
|
void loop(void);
|
|
|
|
|
2019-12-10 22:41:11 +01:00
|
|
|
void stop(void);
|
2019-12-03 22:09:55 +01:00
|
|
|
void restart(void);
|
|
|
|
|
2019-12-05 01:11:37 +01:00
|
|
|
bool isIdle(void)
|
|
|
|
{
|
2019-12-16 23:29:05 +01:00
|
|
|
return !m_animation || (m_animation->finished() && !m_nextAnimation);
|
2019-12-05 01:11:37 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 23:06:04 +01:00
|
|
|
private:
|
|
|
|
Fader *m_fader;
|
|
|
|
std::unique_ptr<Animation> m_animation;
|
2019-12-03 22:09:55 +01:00
|
|
|
std::unique_ptr<Animation> m_nextAnimation;
|
2019-12-02 23:06:04 +01:00
|
|
|
|
2019-12-09 22:22:51 +01:00
|
|
|
SemaphoreHandle_t m_updateMutex;
|
|
|
|
|
2019-12-02 23:06:04 +01:00
|
|
|
uint64_t m_frame;
|
|
|
|
};
|