Skip to content
Open
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
24 changes: 23 additions & 1 deletion src/arduino-timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,28 @@ class Timer {
}
}

/* Left until the task ends */
unsigned long
left(const Task &task) const
{
auto lft = 0ul;
if (!task)
return lft;

timer_foreach_const_task(t) {
if (t->handler && task_id(t) == task) {
const unsigned long now = time_func();
const unsigned long duration = now - t->start;

if (duration < t->expires)
lft = t->expires - duration;
break;
}
}

return lft;
}

/* Ticks the timer forward - call this function in loop() */
unsigned long
tick()
Expand Down Expand Up @@ -223,7 +245,7 @@ class Timer {

inline
Task
task_id(const struct task * const t)
task_id(const struct task * const t) const
{
const Task id = reinterpret_cast<Task>(t);

Expand Down