Skip to content

Commit

Permalink
Try to avoid repetition interval drift
Browse files Browse the repository at this point in the history
  • Loading branch information
mairas committed Dec 4, 2020
1 parent 1c97324 commit a5ba5e1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ReactESP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ void DelayReaction::tick() {


void RepeatReaction::tick() {
this->last_trigger_time = micros64();
this->callback();
ReactESP::app->timed_queue.push(this);
auto now = micros64();
this->last_trigger_time = this->last_trigger_time + this->interval;
if (this->last_trigger_time + this->interval < now) {
// we're lagging more than one full interval; reset the time
this->last_trigger_time = now;
}
this->callback();
ReactESP::app->timed_queue.push(this);
}


Expand Down

0 comments on commit a5ba5e1

Please sign in to comment.