esp32-sk6812/include/Animation/AnimationController.h

75 lines
1.9 KiB
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,
SNOWFALL = 2,
FONT_TEST = 3,
MATRIX_CODE = 4,
FIREWORK = 5,
STELLAR = 6,
RGBW_SINUS = 7,
NUM_DEFAULT_ANIMATIONS
};
enum AnimationInitiator {
NONE,
INTERNAL,
USER
};
static const constexpr std::array<const char*, NUM_DEFAULT_ANIMATIONS> AnimationNames{
"Hot Fire",
"Cold Fire",
"Snowfall",
"Font Test",
"Matrix Code",
"Fireworks",
"Twinkling Sky",
"RGBW Sinus"
};
AnimationController(Fader *fader);
void changeAnimation(std::unique_ptr<Animation> anim, bool transition = true, AnimationInitiator animInitiator = INTERNAL);
void changeAnimation(DefaultAnimation animation_id, bool transition = true, AnimationInitiator animInitiator = INTERNAL);
void loop(void);
void stop(void);
void restart(void);
bool isIdle(void)
{
return !m_animation || (m_animation->finished() && !m_nextAnimation);
}
uint64_t currentFrame(void) { return m_frame; }
AnimationInitiator animationInitiator(void) { return m_animationInitiator; }
DefaultAnimation lastDefaultAnimation(void) { return m_lastDefaultAnimation; }
private:
Fader *m_fader;
std::unique_ptr<Animation> m_animation;
std::unique_ptr<Animation> m_nextAnimation;
SemaphoreHandle_t m_updateMutex;
uint64_t m_frame;
AnimationInitiator m_animationInitiator;
DefaultAnimation m_lastDefaultAnimation;
};