Skip to content

Commit 6e6f9bd

Browse files
committed
Overloaded ticks() function, getting the ticks left for a specific task
Signed-off-by: Greg <sixtelgreg@gmail.com>
1 parent a90f1ff commit 6e6f9bd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/arduino-timer.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,30 @@ class Timer {
114114
}
115115
}
116116

117+
/* Left until the task ends */
118+
unsigned long
119+
ticks(const Task &task)
120+
{
121+
auto lft = 0ul;
122+
if (!task)
123+
return lft;
124+
125+
timer_foreach_task(t) {
126+
if (t->handler && task_id(t) == task) {
127+
const unsigned long now = time_func();
128+
const unsigned long duration = now - t->start;
129+
130+
if (duration >= t->expires)
131+
break;
132+
133+
lft = t->expires - duration;
134+
break;
135+
}
136+
}
137+
138+
return lft;
139+
}
140+
117141
/* Ticks the timer forward - call this function in loop() */
118142
unsigned long
119143
tick()

0 commit comments

Comments
 (0)