Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hang when animations are called too quickly. #214

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/pbio/src/light/animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ void pbio_light_animation_start(pbio_light_animation_t *animation) {
pbio_light_animation_list_head = animation;

process_start(&pbio_light_animation_process);
// HACK: init timer since we don't call etimer_set()
timer_set(&animation->timer.timer, 0);
// fake a timer event to load the first cell and start the timer
process_post_synch(&pbio_light_animation_process, PROCESS_EVENT_TIMER, &animation->timer);

PROCESS_CONTEXT_BEGIN(&pbio_light_animation_process);
etimer_set(&animation->timer, 0);
PROCESS_CONTEXT_END(&pbio_light_animation_process);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better than the old hack. 👍


assert(animation->next_animation != PBIO_LIGHT_ANIMATION_STOPPED);
}
Expand Down Expand Up @@ -120,6 +120,11 @@ PROCESS_THREAD(pbio_light_animation_process, ev, data) {
clock_time_t interval = animation->next(animation);
if (pbio_light_animation_is_started(animation)) {
etimer_reset_with_new_interval(&animation->timer, interval);
/* If the timer is to fire in the past, restart it immediately instead. */
if (clock_time() > etimer_expiration_time(&animation->timer)) {
etimer_reset_with_new_interval(&animation->timer, 0);
etimer_restart(&animation->timer);
}
}
}

Expand Down