Skip to content

Commit 9f6f82b

Browse files
committed
Merge branch 'mc/ticks-optional'
* mc/ticks-optional: README: document ticks() and tick<void>() src:arduino-timer: make ticks calculation optional
2 parents db7bb5b + 10ed8f6 commit 9f6f82b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ timer.in(1000, [](void*) -> bool { return false; });
6262
timer.in(1000, [](void *argument) -> bool { return argument; }, argument);
6363
```
6464
65+
Getting the number of **ticks** until the next *Task*
66+
```cpp
67+
auto ticks = timer.ticks(); // usefull for sleeping until the next task
68+
```
69+
```cpp
70+
void loop {
71+
auto ticks = timer.tick(); // returns the number of ticks
72+
}
73+
```
74+
75+
Avoiding **ticks** calculation inside of **tick**
76+
```cpp
77+
void loop {
78+
timer.tick<void>(); // avoids ticks() calculation
79+
}
80+
```
81+
6582
### API
6683

6784
```cpp

src/arduino-timer.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class Timer {
9999
/* Ticks the timer forward - call this function in loop() */
100100
unsigned long
101101
tick()
102+
{
103+
tick<void>();
104+
return ticks();
105+
}
106+
107+
template <typename R> void
108+
tick()
102109
{
103110
for (size_t i = 0; i < max_tasks; ++i) {
104111
struct task * const task = &tasks[i];
@@ -115,8 +122,6 @@ class Timer {
115122
}
116123
}
117124
}
118-
119-
return ticks();
120125
}
121126

122127
/* Ticks until the next event */

0 commit comments

Comments
 (0)