Callback Timer API¶
-
template <typename TimerApi>
classCallbackTimer
: protected TimerApi¶ Callback timer class template.
- 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
- Template Parameters
TimerApi
: The physical timer implementation
Subclassed by DelegateCallbackTimer< TimerApi >
Public Types
-
template<>
usingMillis
= NanoTime::TimeSource<Clock, NanoTime::Milliseconds, uint32_t>¶
-
template<>
usingMicros
= NanoTime::TimeSource<Clock, NanoTime::Microseconds, TimeType>¶
Public Functions
-
template <NanoTime::Unit unit, TimeType time>
CallbackTimer &initialize
(TimerCallback callback, void *arg = nullptr) Initialise timer with an interval (static check) and callback.
- Note
- If interval out of range compilation will fail with error
- Template Parameters
unit
: Time unit for intervaltime
: Timer interval
- Parameters
callback
: Callback function to call when timer triggersarg
: Optional argument passed to callback
- Return Value
CallbackTimer&
: Reference to timer
-
template <NanoTime::Unit unit>
CallbackTimer &initialize
(TimeType time, TimerCallback callback, void *arg = nullptr) Initialise timer with an interval and callback.
- Template Parameters
unit
: Time unit for interval
- Parameters
time
: Timer intervalcallback
: Callback function to call when timer triggersarg
: Optional argument passed to callback
- Return Value
CallbackTimer&
: Reference to timer
-
template <TimeType microseconds>
CallbackTimer &initializeUs
(TimerCallback callback, void *arg = nullptr) Initialise timer in microseconds (static check) with Timer Callback and optional argument.
-
template <TimeType microseconds>
CallbackTimer &initializeUs
(InterruptCallback callback = nullptr) Initialise timer in microseconds (static check) with optional Interrupt Callback (no argument)
-
CallbackTimer &
initializeUs
(TimeType microseconds, TimerCallback callback, void *arg = nullptr) Initialise timer in microseconds with Timer Callback and optional argument.
-
CallbackTimer &
initializeUs
(TimeType microseconds, InterruptCallback callback = nullptr) Initialise timer in microseconds with optional Interrupt Callback (no arg)
-
template <uint32_t milliseconds>
CallbackTimer &initializeMs
(TimerCallback callback, void *arg = nullptr) Initialise hardware timer in milliseconds (static check) with Timer Callback and optional argument.
-
template <uint32_t milliseconds>
CallbackTimer &initializeMs
(InterruptCallback callback = nullptr) Initialise hardware timer in milliseconds (static check) and optional Interrupt Callback (no arg)
-
CallbackTimer &
initializeMs
(uint32_t milliseconds, TimerCallback callback, void *arg = nullptr) Initialise hardware timer in milliseconds with Timer Callback and optional argument.
-
CallbackTimer &
initializeMs
(uint32_t milliseconds, InterruptCallback callback = nullptr) Initialise hardware timer in milliseconds with optional Interrupt Callback (no arg)
-
bool
start
(bool repeating = true) Start timer running.
- Parameters
repeating
: True to restart timer when it triggers, false for one-shot (Default: true)
- Return Value
bool
: True if timer started
-
bool
startOnce
() Start one-shot timer.
- Note
- Timer starts and will run for configured period then stop
- Return Value
bool
: True if timer started
-
void
stop
() Stops timer.
-
bool
restart
() Restart timer.
- Note
- Timer is stopped then started with current configuration
- Return Value
bool
: True if timer started
-
bool
isStarted
() const Check if timer is started.
- Return Value
bool
: True if started
-
TickType
getInterval
() const Get timer interval in clock ticks.
-
bool
checkInterval
(TickType ticks) const Check timer interval is valid.
- Parameters
ticks
: Interval to check
- Return Value
bool
: true if interval is within acceptable range for this timer
-
bool
setInterval
(TickType ticks) Set timer interval in timer ticks.
- Parameters
ticks
: Interval in timer ticks
-
template <TimeType ticks>
voidsetInterval
() Set timer interval in timer ticks (static check)
- Note
- On error, compilation fails with error message
- Template Parameters
ticks
: Interval in ticks
-
template <NanoTime::Unit unit, TimeType time>
voidsetInterval
() Set timer interval in specific time unit (static check)
- Note
- On error, compilation fails with error message
- Template Parameters
unit
:time
: Interval to set
-
template <NanoTime::Unit unit>
boolsetInterval
(TimeType time) Set timer interval in timer ticks.
- Template Parameters
unit
:
- Parameters
time
: Interval in given units
-
bool
setIntervalUs
(TimeType microseconds) Set timer interval in microseconds.
-
template <TimeType microseconds>
voidsetIntervalUs
() Set timer interval in microseconds (static check)
-
bool
setIntervalMs
(uint32_t milliseconds) Set timer interval in milliseconds.
-
template <uint32_t milliseconds>
voidsetIntervalMs
() Set timer interval in milliseconds (static check)
-
void
setCallback
(TimerCallback callback, void *arg = nullptr) Set timer trigger callback.
- Parameters
callback
: Function to call when timer triggersarg
: Optional argument passed to callback
-
void
setCallback
(InterruptCallback callback) Set timer trigger callback.
- Note
- Provided for convenience where callback argument not required
- Parameters
callback
: Function to call when timer triggers
Public Static Functions
-
static constexpr Millis
millis
() Get a millisecond time source.
-
static constexpr Micros
micros
() Get a microsecond time source.
-
template <uint64_t us>
static constexpr uint64_tusToTicks
() Convert microsecond count into timer ticks.
-
static TickType
usToTicks
(TimeType time) Convert microsecond count into timer ticks.
-
template <uint64_t ticks>
static constexpr uint64_tticksToUs
() Convert timer ticks into microseconds.
-
static TimeType
ticksToUs
(TickType ticks) Convert timer ticks into microseconds.
-
template <uint64_t ticks>
static constexpr voidcheckInterval
() Check timer interval in ticks is valid (static check)
- Note
- On error, compilation fails with error message
- Template Parameters
ticks
: Timer interval to check
-
template <NanoTime::Unit unit, uint64_t time>
static constexpr voidcheckInterval
() Check timer interval in specific time unit is valid (static check)
- Note
- On error, compilation fails with error message
- Template Parameters
unit
: Time unit for intervaltime
: Interval to check
-
template <uint64_t milliseconds>
static constexpr voidcheckIntervalMs
() Check timer interval in milliseconds is valid (static check)
-
template <uint64_t microseconds>
static constexpr voidcheckIntervalUs
() Check timer interval in microseconds is valid (static check)