@@ -16,19 +16,19 @@ auto timerset = Timers::create_default();
1616
1717Or using the * TimerSet* constructors for different timer limits / time clocks.
1818``` cpp
19- Timers::TimerSet<10 > timerset; // 10 concurrent timers , using millisecond clock
20- Timers::TimerSet<10 , Timers::Clock::micros> microtimerset; // 10 concurrent timers , using microsecond clock
19+ Timers::TimerSet<10 > timerset; // 10 concurrent Timers , using millisecond clock
20+ Timers::TimerSet<10 , Timers::Clock::micros> microtimerset; // 10 concurrent Timers , using microsecond clock
2121```
2222
23- Call * timerset* .** tick_and_delay()** in the ``` loop ``` function to execute handlers for any timers
24- which have expired and then delay until the next scheduled timer expiration.
23+ Call * timerset* .** tick_and_delay()** in the ``` loop ``` function to execute handlers for any Timers
24+ which have expired and then delay until the next scheduled Timer expiration.
2525``` cpp
2626void loop () {
2727 timerset.tick_and_delay();
2828}
2929```
3030
31- Call * timerset* .** tick()** in the ``` loop ``` function to execute handlers for any timers
31+ Call * timerset* .** tick()** in the ``` loop ``` function to execute handlers for any Timers
3232which have expired, and then return so additional processing can be handled in the loop function.
3333``` cpp
3434void loop () {
@@ -46,7 +46,7 @@ Timers::HandlerResult function_to_call() {
4646Make a function to call (with an argument) when a * Timer* expires.
4747``` cpp
4848Timers::HandlerResult function_to_call_with_arg (int value) {
49- return Timers::TimerStatus::completed; // to stop the timer - 'repeat' to repeat the action
49+ return Timers::TimerStatus::completed; // to stop the Timer - 'repeat' to repeat the action
5050}
5151```
5252
@@ -101,39 +101,52 @@ timerset.cancel(timer);
101101
102102``` cpp
103103/* Constructors */
104- /* Create a timer object with default settings:
105- millis resolution, TIMER_MAX_TASKS (=16) task slots, T = void *
104+ /* Create a TimerSet object with default settings:
105+ millisecond clock, TIMERSET_DEFAULT_TIMERS (=16) Timer slots
106106*/
107- Timer <> timer_create_default (); // auto timer = timer_create_default ();
107+ Timers::TimerSet <> Timers::create_default () // auto timerset = Timers::create_default ();
108108
109- /* Create a timer with max_tasks slots and time_func resolution */
110- Timer<size_t max_tasks = TIMER_MAX_TASKS, unsigned long (* time_func)(void) = millis, typename T = void * > timer;
111- Timer<> timer; // Equivalent to: auto timer = timer_create_default()
112- Timer<10> timer; // Timer with 10 task slots
113- Timer<10, micros> timer; // timer with 10 task slots and microsecond resolution
114- Timer<10, micros, int> timer; // timer with 10 task slots, microsecond resolution, and handler argument type int
109+ /* Create a TimerSet with max_timers slots and millisecond clock */
110+ Timers::TimerSet<size_t max_timers = TIMERSET_DEFAULT_TIMERS, typename clock = Clock::millis>()
115111
116- /* Signature for handler functions - T = void * by default * /
117- bool handler(T argument);
112+ Timers::TimerSet<> timerset; // Equivalent to: auto timerset = Timers::create_default();
113+ Timers::TimerSet<10 > timerset; // TimerSet with 10 Timer slots
114+ Timers::TimerSet<10 , Timers::Clock::micros> timerset; // TimerSet with 10 Timer slots and microsecond clock
118115
119- /* Timer Methods * /
120- /* Ticks the timer forward, returns the ticks until next event, or 0 if none * /
121- unsigned long tick(); // call this function in loop()
116+ /* Handler function signature; returns a HandlerResult */
117+ Timers::HandlerResult handler () // declared as Timers::Handler
122118
123- /* Calls handler with opaque as argument in delay units of time * /
124- Timer<>::Task
125- in(unsigned long delay, handler_t handler, T opaque = T());
119+ /* HandlerResult contains a TimerStatus, and optional 'next' Timepoint */
120+ /* (in handler function) */
121+ return Timers::TimerStatus::completed; // remove Timer from TimerSet
122+ return Timers::TimerStatus::repeat; // repeat Timer at previously-set interval
123+ return { Timers::TimerStatus::reschedule, 3000 }; // repeat Timer at new interval of 3000 clock ticks
126124
127- /* Calls handler with opaque as argument at time * /
128- Timer<>::Task
129- at(unsigned long time, handler_t handler, T opaque = T());
125+ /* TimerSet Methods * /
126+ // Ticks the TimerSet forward, returns the ticks until next event, or 0 if none
127+ Timers::Timepoint tick(); // call this function in loop()
130128
131- /* Calls handler with opaque as argument every interval units of time * /
132- Timer<>::Task
133- every(unsigned long interval, handler_t handler, T opaque = T());
129+ // Ticks the TimerSet forward, and delays until the next event
130+ void tick_and_delay(); // call this function in loop()
134131
135- /* Cancel a timer task * /
136- void cancel(Timer<>::Task &task);
132+ /* Calls handler in delay units of time * /
133+ Timers::TimerHandle
134+ in (Timers::Timepoint delay, Timers::Handler handler);
135+
136+ /* Calls handler at time * /
137+ Timers::TimerHandle
138+ at (Timers::Timepoint time, Timers::Handler handler);
139+
140+ /* Calls handler every interval units of time * /
141+ Timers::TimerHandle
142+ every (Timers::Timepoint interval, Timers::Handler handler);
143+
144+ /* Calls handler now and every interval units of time * /
145+ Timers::TimerHandle
146+ now_and_every (Timers::Timepoint interval, Timers::Handler handler);
147+
148+ /* Cancel a Timer * /
149+ void cancel(Timers::TimerHandle timer);
137150```
138151
139152### Installation
0 commit comments