Skip to content
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
8 changes: 7 additions & 1 deletion src/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ class Timer {
struct task * const task = &tasks[i];
const unsigned long duration = t - task->start;

if (task->handler && duration >= task->expires) {
// Tasks that were generated by a task earlier in the loop could have
// a start time larger than the "current time" given as an argument.
//
// Check if t >= task->start to prevent the underflow from triggering tasks early.
//
// See https://github.com/contrem/arduino-timer/pull/7 for more info.
if (task->handler && t >= task->start && duration >= task->expires) {
task->repeat = task->handler(task->opaque) && task->repeat;

if (task->repeat) task->start = t;
Expand Down