Callback Timer API
-
template<typename TimerApi>
class CallbackTimer : 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< OsTimer64Api< AutoDeleteTimer > >, DelegateCallbackTimer< OsTimer64Api< Timer > >, DelegateCallbackTimer< TimerApi >
Public Functions
-
template<NanoTime::Unit unit, TimeType time>
inline 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 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
-
template<NanoTime::Unit unit>
inline 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 interval
callback – Callback function to call when timer triggers
arg – Optional argument passed to callback
- Return values:
CallbackTimer& – Reference to timer
-
template<TimeType microseconds>
inline CallbackTimer &initializeUs(TimerCallback callback, void *arg = nullptr) Initialise timer in microseconds (static check) with Timer Callback and optional argument.
-
template<TimeType microseconds>
inline CallbackTimer &initializeUs(InterruptCallback callback = nullptr) Initialise timer in microseconds (static check) with optional Interrupt Callback (no argument)
-
inline CallbackTimer &initializeUs(TimeType microseconds, TimerCallback callback, void *arg = nullptr)
Initialise timer in microseconds with Timer Callback and optional argument.
-
inline CallbackTimer &initializeUs(TimeType microseconds, InterruptCallback callback = nullptr)
Initialise timer in microseconds with optional Interrupt Callback (no arg)
-
template<uint32_t milliseconds>
inline CallbackTimer &initializeMs(TimerCallback callback, void *arg = nullptr) Initialise hardware timer in milliseconds (static check) with Timer Callback and optional argument.
-
template<uint32_t milliseconds>
inline CallbackTimer &initializeMs(InterruptCallback callback = nullptr) Initialise hardware timer in milliseconds (static check) and optional Interrupt Callback (no arg)
-
inline CallbackTimer &initializeMs(uint32_t milliseconds, TimerCallback callback, void *arg = nullptr)
Initialise hardware timer in milliseconds with Timer Callback and optional argument.
-
inline CallbackTimer &initializeMs(uint32_t milliseconds, InterruptCallback callback = nullptr)
Initialise hardware timer in milliseconds with optional Interrupt Callback (no arg)
-
inline bool start(bool repeating = true)
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
-
inline bool startOnce()
Start one-shot timer.
Note
Timer starts and will run for configured period then stop
- Return values:
bool – True if timer started
-
inline void stop()
Stops timer.
-
inline bool restart()
Restart timer.
Note
Timer is stopped then started with current configuration
- Return values:
bool – True if timer started
-
inline bool isStarted() const
Check if timer is started.
- Return values:
bool – True if started
-
inline TickType getInterval() const
Get timer interval in clock ticks.
-
inline bool checkInterval(TickType ticks) const
Check timer interval is valid.
- Parameters:
ticks – Interval to check
- Return values:
bool – true if interval is within acceptable range for this timer
-
inline bool setInterval(TickType ticks)
Set timer interval in timer ticks.
- Parameters:
ticks – Interval in timer ticks
-
template<TimeType ticks>
inline void setInterval() 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>
inline void setInterval() 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>
inline bool setInterval(TimeType time) Set timer interval in timer ticks.
- Template Parameters:
unit –
- Parameters:
time – Interval in given units
-
inline bool setIntervalUs(TimeType microseconds)
Set timer interval in microseconds.
-
template<TimeType microseconds>
inline void setIntervalUs() Set timer interval in microseconds (static check)
-
inline bool setIntervalMs(uint32_t milliseconds)
Set timer interval in milliseconds.
-
template<uint32_t milliseconds>
inline void setIntervalMs() Set timer interval in milliseconds (static check)
-
inline void setCallback(TimerCallback callback, void *arg = nullptr)
Set timer trigger callback.
- Parameters:
callback – Function to call when timer triggers
arg – Optional argument passed to callback
-
inline 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 inline constexpr Millis millis()
Get a millisecond time source.
-
static inline constexpr Micros micros()
Get a microsecond time source.
-
template<uint64_t us>
static inline constexpr uint64_t usToTicks() Convert microsecond count into timer ticks.
-
static inline TickType usToTicks(TimeType time)
Convert microsecond count into timer ticks.
-
template<uint64_t ticks>
static inline constexpr uint64_t ticksToUs() Convert timer ticks into microseconds.
-
static inline TimeType ticksToUs(TickType ticks)
Convert timer ticks into microseconds.
-
template<uint64_t ticks>
static inline constexpr void checkInterval() 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 inline constexpr void checkInterval() 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 interval
time – Interval to check
-
template<uint64_t milliseconds>
static inline constexpr void checkIntervalMs() Check timer interval in milliseconds is valid (static check)
-
template<uint64_t microseconds>
static inline constexpr void checkIntervalUs() Check timer interval in microseconds is valid (static check)