Stability improvements for FireAnimation and AnimationController
This commit is contained in:
parent
b78313d2e0
commit
1bfee92aec
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
#include "Animation.h"
|
#include "Animation.h"
|
||||||
|
|
||||||
|
#include <FreeRTOS.h>
|
||||||
|
#include <freertos/semphr.h>
|
||||||
|
|
||||||
class AnimationController
|
class AnimationController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -33,5 +36,7 @@ class AnimationController
|
||||||
std::unique_ptr<Animation> m_animation;
|
std::unique_ptr<Animation> m_animation;
|
||||||
std::unique_ptr<Animation> m_nextAnimation;
|
std::unique_ptr<Animation> m_nextAnimation;
|
||||||
|
|
||||||
|
SemaphoreHandle_t m_updateMutex;
|
||||||
|
|
||||||
uint64_t m_frame;
|
uint64_t m_frame;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,11 +17,7 @@ class FireAnimation : public Animation
|
||||||
m_stopping = true;
|
m_stopping = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset(void) override
|
void reset(void) override;
|
||||||
{
|
|
||||||
m_stopping = false;
|
|
||||||
m_running = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const constexpr unsigned MAX_NEW_ENERGY = 160;
|
static const constexpr unsigned MAX_NEW_ENERGY = 160;
|
||||||
|
|
|
@ -4,10 +4,14 @@
|
||||||
|
|
||||||
AnimationController::AnimationController(Fader *fader)
|
AnimationController::AnimationController(Fader *fader)
|
||||||
: m_fader(fader), m_animation(nullptr), m_frame(0)
|
: m_fader(fader), m_animation(nullptr), m_frame(0)
|
||||||
{}
|
{
|
||||||
|
m_updateMutex = xSemaphoreCreateMutex();
|
||||||
|
}
|
||||||
|
|
||||||
void AnimationController::changeAnimation(std::unique_ptr<Animation> anim, bool transition)
|
void AnimationController::changeAnimation(std::unique_ptr<Animation> anim, bool transition)
|
||||||
{
|
{
|
||||||
|
xSemaphoreTake(m_updateMutex, portMAX_DELAY);
|
||||||
|
|
||||||
if(transition && m_animation) {
|
if(transition && m_animation) {
|
||||||
m_nextAnimation = std::move(anim);
|
m_nextAnimation = std::move(anim);
|
||||||
m_animation->stop();
|
m_animation->stop();
|
||||||
|
@ -17,6 +21,8 @@ void AnimationController::changeAnimation(std::unique_ptr<Animation> anim, bool
|
||||||
m_animation = std::move(anim);
|
m_animation = std::move(anim);
|
||||||
m_nextAnimation.reset(nullptr);
|
m_nextAnimation.reset(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xSemaphoreGive(m_updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationController::changeAnimation(AnimationController::DefaultAnimation animation_id, bool transition)
|
void AnimationController::changeAnimation(AnimationController::DefaultAnimation animation_id, bool transition)
|
||||||
|
@ -39,6 +45,8 @@ void AnimationController::changeAnimation(AnimationController::DefaultAnimation
|
||||||
|
|
||||||
void AnimationController::loop(void)
|
void AnimationController::loop(void)
|
||||||
{
|
{
|
||||||
|
xSemaphoreTake(m_updateMutex, portMAX_DELAY);
|
||||||
|
|
||||||
if(m_animation && !m_animation->finished()) {
|
if(m_animation && !m_animation->finished()) {
|
||||||
m_animation->loop(m_frame);
|
m_animation->loop(m_frame);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +60,8 @@ void AnimationController::loop(void)
|
||||||
m_animation.swap(m_nextAnimation);
|
m_animation.swap(m_nextAnimation);
|
||||||
m_nextAnimation.reset(nullptr);
|
m_nextAnimation.reset(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xSemaphoreGive(m_updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationController::restart(void)
|
void AnimationController::restart(void)
|
||||||
|
|
|
@ -24,7 +24,7 @@ FireAnimation::FireAnimation(Fader *fader, bool cold)
|
||||||
m_colorMapColors.emplace_back(Fader::Color{255, 128, 0, 40});
|
m_colorMapColors.emplace_back(Fader::Color{255, 128, 0, 40});
|
||||||
}
|
}
|
||||||
|
|
||||||
m_fader->set_fadestep(10);
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t FireAnimation::interpolate(uint32_t energy, std::size_t start_x, std::size_t end_x, uint8_t start_c, uint8_t end_c)
|
uint8_t FireAnimation::interpolate(uint32_t energy, std::size_t start_x, std::size_t end_x, uint8_t start_c, uint8_t end_c)
|
||||||
|
@ -173,3 +173,11 @@ void FireAnimation::loop(uint64_t frame)
|
||||||
m_running = false;
|
m_running = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FireAnimation::reset(void)
|
||||||
|
{
|
||||||
|
m_stopping = false;
|
||||||
|
m_running = true;
|
||||||
|
|
||||||
|
m_fader->set_fadestep(10);
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include <esp32_digital_led_lib.h>
|
#include <esp32_digital_led_lib.h>
|
||||||
#include <esp32_digital_led_funcs.h>
|
#include <esp32_digital_led_funcs.h>
|
||||||
|
|
||||||
|
#include "coreids.h"
|
||||||
|
|
||||||
const uint32_t FRAME_INTERVAL_US = 16666;
|
const uint32_t FRAME_INTERVAL_US = 16666;
|
||||||
const uint32_t NUM_STRIPS = 8;
|
const uint32_t NUM_STRIPS = 8;
|
||||||
const uint32_t NUM_LEDS = 16;
|
const uint32_t NUM_LEDS = 16;
|
||||||
|
|
Loading…
Reference in a new issue