Skip to content

Commit 7d1078f

Browse files
committed
src:timer: return ticks until next event
1 parent b7117dc commit 7d1078f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/timer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ class Timer {
7777
}
7878

7979
/* Ticks the timer forward - call this function in loop() */
80-
void
80+
unsigned long
8181
tick()
8282
{
83+
unsigned long ticks = (unsigned long)-1;
84+
8385
for (size_t i = 0; i < max_tasks; ++i) {
8486
struct task * const task = &tasks[i];
8587

@@ -92,9 +94,14 @@ class Timer {
9294

9395
if (task->repeat) task->start = t;
9496
else remove(task);
97+
} else {
98+
const unsigned long remaining = task->expires - duration;
99+
ticks = remaining < ticks ? remaining : ticks;
95100
}
96101
}
97102
}
103+
104+
return ticks == (unsigned long)-1 ? 0 : ticks;
98105
}
99106

100107
/* DEPRECATED */

0 commit comments

Comments
 (0)