Callback timer class template. More...
#include <CallbackTimer.h>
Public Types | |
using | Millis = NanoTime::TimeSource< Clock, NanoTime::Milliseconds, uint32_t > |
using | Micros = NanoTime::TimeSource< Clock, NanoTime::Microseconds, TimeType > |
Public Member Functions | |
template<NanoTime::Unit unit, TimeType time> | |
CallbackTimer & | initialize (TimerCallback callback, void *arg=nullptr) |
Initialise timer with an interval (static check) and callback. More... | |
template<NanoTime::Unit unit> | |
CallbackTimer & | initialize (TimeType time, TimerCallback callback, void *arg=nullptr) |
Initialise timer with an interval and callback. More... | |
template<TimeType microseconds> | |
CallbackTimer & | initializeUs (TimerCallback callback, void *arg=nullptr) |
Initialise timer in microseconds (static check) with Timer Callback and optional argument. More... | |
template<TimeType microseconds> | |
CallbackTimer & | initializeUs (InterruptCallback callback=nullptr) |
Initialise timer in microseconds (static check) with optional Interrupt Callback (no argument) More... | |
CallbackTimer & | initializeUs (TimeType microseconds, TimerCallback callback, void *arg=nullptr) |
Initialise timer in microseconds with Timer Callback and optional argument. More... | |
CallbackTimer & | initializeUs (TimeType microseconds, InterruptCallback callback=nullptr) |
Initialise timer in microseconds with optional Interrupt Callback (no arg) More... | |
template<uint32_t milliseconds> | |
CallbackTimer & | initializeMs (TimerCallback callback, void *arg=nullptr) |
Initialise hardware timer in milliseconds (static check) with Timer Callback and optional argument. More... | |
template<uint32_t milliseconds> | |
CallbackTimer & | initializeMs (InterruptCallback callback=nullptr) |
Initialise hardware timer in milliseconds (static check) and optional Interrupt Callback (no arg) More... | |
CallbackTimer & | initializeMs (uint32_t milliseconds, TimerCallback callback, void *arg=nullptr) |
Initialise hardware timer in milliseconds with Timer Callback and optional argument. More... | |
CallbackTimer & | initializeMs (uint32_t milliseconds, InterruptCallback callback=nullptr) |
Initialise hardware timer in milliseconds with optional Interrupt Callback (no arg) More... | |
bool | start (bool repeating=true) |
Start timer running. More... | |
bool | startOnce () |
Start one-shot timer. More... | |
void | stop () |
Stops timer. More... | |
bool | restart () |
Restart timer. More... | |
bool | isStarted () const |
Check if timer is started. More... | |
NanoTime::Time< TimeType > | getIntervalUs () const |
Get timer interval in microseconds. More... | |
NanoTime::Time< uint32_t > | getIntervalMs () const |
Get timer interval in milliseconds. More... | |
TickType | getInterval () const |
Get timer interval in clock ticks. More... | |
bool | checkInterval (TickType ticks) const |
Check timer interval is valid. More... | |
bool | setInterval (TickType ticks) |
Set timer interval in timer ticks. More... | |
template<TimeType ticks> | |
void | setInterval () |
Set timer interval in timer ticks (static check) More... | |
template<NanoTime::Unit unit, TimeType time> | |
void | setInterval () |
Set timer interval in specific time unit (static check) More... | |
template<NanoTime::Unit unit> | |
bool | setInterval (TimeType time) |
Set timer interval in timer ticks. More... | |
bool | setIntervalUs (TimeType microseconds) |
Set timer interval in microseconds. More... | |
template<TimeType microseconds> | |
void | setIntervalUs () |
Set timer interval in microseconds (static check) More... | |
bool | setIntervalMs (uint32_t milliseconds) |
Set timer interval in milliseconds. More... | |
template<uint32_t milliseconds> | |
void | setIntervalMs () |
Set timer interval in milliseconds (static check) More... | |
void | setCallback (TimerCallback callback, void *arg=nullptr) |
Set timer trigger callback. More... | |
void | setCallback (InterruptCallback callback) |
Set timer trigger callback. More... | |
Static Public Member Functions | |
static constexpr Millis | millis () |
Get a millisecond time source. More... | |
static constexpr Micros | micros () |
Get a microsecond time source. More... | |
template<uint64_t us> | |
static constexpr uint64_t | usToTicks () |
Convert microsecond count into timer ticks. More... | |
static TickType | usToTicks (TimeType time) |
Convert microsecond count into timer ticks. More... | |
template<uint64_t ticks> | |
static constexpr uint64_t | ticksToUs () |
Convert timer ticks into microseconds. More... | |
static TimeType | ticksToUs (TickType ticks) |
Convert timer ticks into microseconds. More... | |
template<uint64_t ticks> | |
static constexpr void | checkInterval () |
Check timer interval in ticks is valid (static check) More... | |
template<NanoTime::Unit unit, uint64_t time> | |
static constexpr void | checkInterval () |
Check timer interval in specific time unit is valid (static check) More... | |
template<uint64_t milliseconds> | |
static constexpr void | checkIntervalMs () |
Check timer interval in milliseconds is valid (static check) More... | |
template<uint64_t microseconds> | |
static constexpr void | checkIntervalUs () |
Check timer interval in microseconds is valid (static check) More... | |
Protected Attributes | |
bool | callbackSet = false |
User has provided callback function. More... | |
bool | intervalSet = false |
User has set valid time interval. More... | |
bool | repeating = false |
Timer is auto-repeat. More... | |
bool | started = false |
Timer is active, or has fired. More... | |
Detailed Description
template<typename TimerApi>
class CallbackTimer< TimerApi >
Callback timer class template.
- Template Parameters
-
TimerApi The physical timer implementation
- Note
- Methods return object reference for Method Chaining http://en.wikipedia.org/wiki/Method_chaining This class template provides basic C-style callbacks for best performance
Member Typedef Documentation
◆ Micros
using CallbackTimer< TimerApi >::Micros = NanoTime::TimeSource<Clock, NanoTime::Microseconds, TimeType> |
◆ Millis
using CallbackTimer< TimerApi >::Millis = NanoTime::TimeSource<Clock, NanoTime::Milliseconds, uint32_t> |
Member Function Documentation
◆ checkInterval() [1/3]
|
inlinestaticconstexpr |
Check timer interval in ticks is valid (static check)
- Template Parameters
-
ticks Timer interval to check
- Note
- On error, compilation fails with error message
◆ checkInterval() [2/3]
|
inlinestaticconstexpr |
Check timer interval in specific time unit is valid (static check)
- Template Parameters
-
unit Time unit for interval time Interval to check
- Note
- On error, compilation fails with error message
◆ checkInterval() [3/3]
|
inline |
Check timer interval is valid.
- Parameters
-
ticks Interval to check
- Return values
-
bool true if interval is within acceptable range for this timer
◆ checkIntervalMs()
|
inlinestaticconstexpr |
Check timer interval in milliseconds is valid (static check)
◆ checkIntervalUs()
|
inlinestaticconstexpr |
Check timer interval in microseconds is valid (static check)
◆ getInterval()
|
inline |
Get timer interval in clock ticks.
◆ getIntervalMs()
|
inline |
Get timer interval in milliseconds.
◆ getIntervalUs()
|
inline |
Get timer interval in microseconds.
◆ initialize() [1/2]
|
inline |
Initialise timer with an interval (static check) and callback.
- Template Parameters
-
unit Time unit for interval time Timer interval
- Parameters
-
callback Callback function to call when timer triggers arg Optional argument passed to callback
- Return values
-
CallbackTimer& Reference to timer
- Note
- If interval out of range compilation will fail with error
◆ initialize() [2/2]
|
inline |
Initialise timer with an interval and callback.
- Template Parameters
-
unit Time unit for interval
- Parameters
-
time Timer interval callback Callback function to call when timer triggers arg Optional argument passed to callback
- Return values
-
CallbackTimer& Reference to timer
◆ initializeMs() [1/4]
|
inline |
Initialise hardware timer in milliseconds (static check) and optional Interrupt Callback (no arg)
◆ initializeMs() [2/4]
|
inline |
Initialise hardware timer in milliseconds (static check) with Timer Callback and optional argument.
◆ initializeMs() [3/4]
|
inline |
Initialise hardware timer in milliseconds with optional Interrupt Callback (no arg)
◆ initializeMs() [4/4]
|
inline |
Initialise hardware timer in milliseconds with Timer Callback and optional argument.
◆ initializeUs() [1/4]
|
inline |
Initialise timer in microseconds (static check) with optional Interrupt Callback (no argument)
◆ initializeUs() [2/4]
|
inline |
Initialise timer in microseconds (static check) with Timer Callback and optional argument.
◆ initializeUs() [3/4]
|
inline |
Initialise timer in microseconds with optional Interrupt Callback (no arg)
◆ initializeUs() [4/4]
|
inline |
Initialise timer in microseconds with Timer Callback and optional argument.
◆ isStarted()
|
inline |
Check if timer is started.
- Return values
-
bool True if started
◆ micros()
|
inlinestaticconstexpr |
Get a microsecond time source.
◆ millis()
|
inlinestaticconstexpr |
Get a millisecond time source.
◆ restart()
|
inline |
Restart timer.
- Return values
-
bool True if timer started
- Note
- Timer is stopped then started with current configuration
◆ setCallback() [1/2]
|
inline |
Set timer trigger callback.
- Parameters
-
callback Function to call when timer triggers
- Note
- Provided for convenience where callback argument not required
◆ setCallback() [2/2]
|
inline |
Set timer trigger callback.
- Parameters
-
callback Function to call when timer triggers arg Optional argument passed to callback
◆ setInterval() [1/4]
|
inline |
Set timer interval in timer ticks (static check)
- Template Parameters
-
ticks Interval in ticks
- Note
- On error, compilation fails with error message
◆ setInterval() [2/4]
|
inline |
Set timer interval in specific time unit (static check)
- Template Parameters
-
unit time Interval to set
- Note
- On error, compilation fails with error message
◆ setInterval() [3/4]
|
inline |
Set timer interval in timer ticks.
- Parameters
-
ticks Interval in timer ticks
◆ setInterval() [4/4]
|
inline |
Set timer interval in timer ticks.
- Template Parameters
-
unit
- Parameters
-
time Interval in given units
◆ setIntervalMs() [1/2]
|
inline |
Set timer interval in milliseconds (static check)
◆ setIntervalMs() [2/2]
|
inline |
Set timer interval in milliseconds.
◆ setIntervalUs() [1/2]
|
inline |
Set timer interval in microseconds (static check)
◆ setIntervalUs() [2/2]
|
inline |
Set timer interval in microseconds.
◆ start()
|
inline |
Start timer running.
- Parameters
-
repeating True to restart timer when it triggers, false for one-shot (Default: true)
- Return values
-
bool True if timer started
◆ startOnce()
|
inline |
Start one-shot timer.
- Return values
-
bool True if timer started
- Note
- Timer starts and will run for configured period then stop
◆ stop()
|
inline |
Stops timer.
◆ ticksToUs() [1/2]
|
inlinestaticconstexpr |
Convert timer ticks into microseconds.
◆ ticksToUs() [2/2]
|
inlinestatic |
Convert timer ticks into microseconds.
◆ usToTicks() [1/2]
|
inlinestaticconstexpr |
Convert microsecond count into timer ticks.
◆ usToTicks() [2/2]
|
inlinestatic |
Convert microsecond count into timer ticks.
Member Data Documentation
◆ callbackSet
|
protected |
User has provided callback function.
◆ intervalSet
|
protected |
User has set valid time interval.
◆ repeating
|
protected |
Timer is auto-repeat.
◆ started
|
protected |
Timer is active, or has fired.
The documentation for this class was generated from the following file: