Manage animations via a central controller
This commit is contained in:
parent
862ad18d24
commit
e4a8c86180
21
include/Animation/AnimationController.h
Normal file
21
include/Animation/AnimationController.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "Animation.h"
|
||||||
|
|
||||||
|
class AnimationController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AnimationController(Fader *fader);
|
||||||
|
|
||||||
|
void setAnimation(std::unique_ptr<Animation> anim, bool transition = true);
|
||||||
|
void loop(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Fader *m_fader;
|
||||||
|
std::unique_ptr<Animation> m_animation;
|
||||||
|
|
||||||
|
uint32_t m_transitionTime;
|
||||||
|
uint64_t m_frame;
|
||||||
|
};
|
30
src/Animation/AnimationController.cpp
Normal file
30
src/Animation/AnimationController.cpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include "Animation/AnimationController.h"
|
||||||
|
|
||||||
|
AnimationController::AnimationController(Fader *fader)
|
||||||
|
: m_fader(fader), m_transitionTime(0), m_frame(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void AnimationController::setAnimation(std::unique_ptr<Animation> anim, bool transition)
|
||||||
|
{
|
||||||
|
m_frame = 0;
|
||||||
|
|
||||||
|
m_animation = std::move(anim);
|
||||||
|
|
||||||
|
if(transition) {
|
||||||
|
m_transitionTime = 256/8;
|
||||||
|
|
||||||
|
m_fader->set_fadestep(8);
|
||||||
|
m_fader->fade_color(Fader::Color{0, 0, 0, 0});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimationController::loop(void)
|
||||||
|
{
|
||||||
|
if(m_transitionTime > 0) {
|
||||||
|
m_transitionTime--;
|
||||||
|
} else if(m_animation) {
|
||||||
|
m_animation->loop(m_frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_frame++;
|
||||||
|
}
|
|
@ -13,6 +13,7 @@
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "Animation/AllAnimations.h"
|
#include "Animation/AllAnimations.h"
|
||||||
|
#include "Animation/AnimationController.h"
|
||||||
|
|
||||||
#include <esp32_digital_led_lib.h>
|
#include <esp32_digital_led_lib.h>
|
||||||
#include <esp32_digital_led_funcs.h>
|
#include <esp32_digital_led_funcs.h>
|
||||||
|
@ -35,7 +36,7 @@ Fader ledFader(NUM_STRIPS, NUM_LEDS, 1, FLIP_STRIPS_MASK);
|
||||||
UDPProto udpProto(&ledFader);
|
UDPProto udpProto(&ledFader);
|
||||||
UpdateServer *updateServer;
|
UpdateServer *updateServer;
|
||||||
|
|
||||||
std::unique_ptr<Animation> currentAnimation = nullptr;
|
AnimationController animController(&ledFader);
|
||||||
|
|
||||||
bool initLEDs()
|
bool initLEDs()
|
||||||
{
|
{
|
||||||
|
@ -93,9 +94,7 @@ static void ledTask( void * parameter )
|
||||||
|
|
||||||
uint32_t start_time = micros();
|
uint32_t start_time = micros();
|
||||||
|
|
||||||
if(currentAnimation) {
|
animController.loop();
|
||||||
currentAnimation->loop(frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
if((WiFi.status() == WL_CONNECTED) || (WiFi.getMode() == WIFI_MODE_AP)) {
|
if((WiFi.status() == WL_CONNECTED) || (WiFi.getMode() == WIFI_MODE_AP)) {
|
||||||
udpProto.loop();
|
udpProto.loop();
|
||||||
|
@ -210,7 +209,7 @@ void setup()
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
currentAnimation = std::unique_ptr<Animation>(new ConnectingAnimation(&ledFader));
|
animController.setAnimation(std::unique_ptr<Animation>(new ConnectingAnimation(&ledFader)));
|
||||||
|
|
||||||
xTaskCreate(
|
xTaskCreate(
|
||||||
ledTask, /* Task function. */
|
ledTask, /* Task function. */
|
||||||
|
|
Loading…
Reference in a new issue