Stability improvements for FireAnimation and AnimationController

This commit is contained in:
Thomas Kolb 2019-12-09 22:22:51 +01:00
parent b78313d2e0
commit 1bfee92aec
5 changed files with 28 additions and 7 deletions

View File

@ -4,6 +4,9 @@
#include "Animation.h"
#include <FreeRTOS.h>
#include <freertos/semphr.h>
class AnimationController
{
public:
@ -33,5 +36,7 @@ class AnimationController
std::unique_ptr<Animation> m_animation;
std::unique_ptr<Animation> m_nextAnimation;
SemaphoreHandle_t m_updateMutex;
uint64_t m_frame;
};

View File

@ -17,11 +17,7 @@ class FireAnimation : public Animation
m_stopping = true;
}
void reset(void) override
{
m_stopping = false;
m_running = true;
}
void reset(void) override;
private:
static const constexpr unsigned MAX_NEW_ENERGY = 160;

View File

@ -4,10 +4,14 @@
AnimationController::AnimationController(Fader *fader)
: m_fader(fader), m_animation(nullptr), m_frame(0)
{}
{
m_updateMutex = xSemaphoreCreateMutex();
}
void AnimationController::changeAnimation(std::unique_ptr<Animation> anim, bool transition)
{
xSemaphoreTake(m_updateMutex, portMAX_DELAY);
if(transition && m_animation) {
m_nextAnimation = std::move(anim);
m_animation->stop();
@ -17,6 +21,8 @@ void AnimationController::changeAnimation(std::unique_ptr<Animation> anim, bool
m_animation = std::move(anim);
m_nextAnimation.reset(nullptr);
}
xSemaphoreGive(m_updateMutex);
}
void AnimationController::changeAnimation(AnimationController::DefaultAnimation animation_id, bool transition)
@ -39,6 +45,8 @@ void AnimationController::changeAnimation(AnimationController::DefaultAnimation
void AnimationController::loop(void)
{
xSemaphoreTake(m_updateMutex, portMAX_DELAY);
if(m_animation && !m_animation->finished()) {
m_animation->loop(m_frame);
}
@ -52,6 +60,8 @@ void AnimationController::loop(void)
m_animation.swap(m_nextAnimation);
m_nextAnimation.reset(nullptr);
}
xSemaphoreGive(m_updateMutex);
}
void AnimationController::restart(void)

View File

@ -24,7 +24,7 @@ FireAnimation::FireAnimation(Fader *fader, bool cold)
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)
@ -173,3 +173,11 @@ void FireAnimation::loop(uint64_t frame)
m_running = false;
}
}
void FireAnimation::reset(void)
{
m_stopping = false;
m_running = true;
m_fader->set_fadestep(10);
}

View File

@ -18,6 +18,8 @@
#include <esp32_digital_led_lib.h>
#include <esp32_digital_led_funcs.h>
#include "coreids.h"
const uint32_t FRAME_INTERVAL_US = 16666;
const uint32_t NUM_STRIPS = 8;
const uint32_t NUM_LEDS = 16;