Animation robustness improvements

- Check if animation is valid in all methods of AnimationController
- Fixed timing (+crash) for quick loops of LED task
This commit is contained in:
Thomas Kolb 2019-12-16 23:29:05 +01:00
parent ecf296a1fc
commit 127b8d6dca
3 changed files with 25 additions and 6 deletions

View file

@ -37,7 +37,7 @@ class AnimationController
bool isIdle(void)
{
return m_animation->finished() && !m_nextAnimation;
return !m_animation || (m_animation->finished() && !m_nextAnimation);
}
private:

View file

@ -75,11 +75,16 @@ void AnimationController::loop(void)
void AnimationController::stop(void)
{
m_animation->stop();
if(m_animation) {
m_animation->stop();
}
}
void AnimationController::restart(void)
{
m_animation->reset();
if(m_animation) {
m_animation->reset();
}
m_frame = 0;
}

View file

@ -187,6 +187,18 @@ static void ledFSM(void)
stateEntered = (lastState != ledState);
}
static void fineDelay(uint32_t us)
{
uint32_t ms = us / 1000;
us -= ms * 1000;
if(ms) {
delay(ms);
}
delayMicroseconds(us);
}
static void ledTask( void * parameter )
{
uint64_t frame = 0;
@ -227,16 +239,18 @@ static void ledTask( void * parameter )
uint32_t now = micros();
uint32_t duration = now - start_time;
if(frame % 50 == 0) {
if(frame % 60 == 0) {
uint32_t load = 100 * duration / FRAME_INTERVAL_US;
Serial.print("CPU Load: ");
Serial.print("Duration: ");
Serial.print(duration);
Serial.print("μs → CPU Load: ");
Serial.print(load);
Serial.println(" %");
}
if(duration < FRAME_INTERVAL_US) {
delayMicroseconds(FRAME_INTERVAL_US - duration);
fineDelay(FRAME_INTERVAL_US - duration);
}
}
/* delete a task when finish,