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:
parent
ecf296a1fc
commit
127b8d6dca
|
@ -37,7 +37,7 @@ class AnimationController
|
|||
|
||||
bool isIdle(void)
|
||||
{
|
||||
return m_animation->finished() && !m_nextAnimation;
|
||||
return !m_animation || (m_animation->finished() && !m_nextAnimation);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
20
src/main.cpp
20
src/main.cpp
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue