Skip to content

Commit acbbbd3

Browse files
committed
README: update with template handler usage
1 parent 0af91bd commit acbbbd3

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Or using the *Timer* constructors for different task limits / time resolution
1515
```cpp
1616
Timer<10> timer; // 10 concurrent tasks, using millis as resolution
1717
Timer<10, micros> timer; // 10 concurrent tasks, using micros as resolution
18+
Timer<10, micros, int> timer; // 10 concurrent tasks, using micros as resolution, with handler argument of type int
1819
```
1920

2021
Call *timer*.**tick()** in the loop function
@@ -65,33 +66,36 @@ timer.in(1000, [](void *argument) -> bool { return argument; }, argument);
6566
6667
```cpp
6768
/* Constructors */
68-
/* Create a timer object with default settings - millis resolution, TIMER_MAX_TASKS (=16) task slots */
69+
/* Create a timer object with default settings:
70+
millis resolution, TIMER_MAX_TASKS (=16) task slots, T = void *
71+
*/
6972
Timer<> timer_create_default(); // auto timer = timer_create_default();
7073
7174
/* Create a timer with max_tasks slots and time_func resolution */
72-
Timer<size_t max_tasks = TIMER_MAX_TASKS, unsigned long (*time_func)(void) = millis> timer;
75+
Timer<size_t max_tasks = TIMER_MAX_TASKS, unsigned long (*time_func)(void) = millis, typename T = void *> timer;
7376
Timer<> timer; // Equivalent to: auto timer = timer_create_default()
7477
Timer<10> timer; // Timer with 10 task slots
7578
Timer<10, micros> timer; // timer with 10 task slots and microsecond resolution
79+
Timer<10, micros, int> timer; // timer with 10 task slots, microsecond resolution, and handler argument type int
7680
77-
/* Signature for handler functions */
78-
bool handler(void *argument);
81+
/* Signature for handler functions - T = void * by default */
82+
bool handler(T argument);
7983
8084
/* Timer Methods */
8185
/* Ticks the timer forward, returns the ticks until next event, or 0 if none */
82-
unsigned int tick(); // call this function in loop()
86+
unsigned long tick(); // call this function in loop()
8387
8488
/* Calls handler with opaque as argument in delay units of time */
8589
Timer<>::Task
86-
in(unsigned long delay, handler_t handler, void *opaque = NULL);
90+
in(unsigned long delay, handler_t handler, T opaque = T());
8791
8892
/* Calls handler with opaque as argument at time */
8993
Timer<>::Task
90-
at(unsigned long time, handler_t handler, void *opaque = NULL);
94+
at(unsigned long time, handler_t handler, T opaque = T());
9195
9296
/* Calls handler with opaque as argument every interval units of time */
9397
Timer<>::Task
94-
every(unsigned long interval, handler_t handler, void *opaque = NULL);
98+
every(unsigned long interval, handler_t handler, T opaque = T());
9599
96100
/* Cancel a timer task */
97101
void cancel(Timer<>::Task &task);

0 commit comments

Comments
 (0)