Class for one-shot millisecond timers. More...
#include <Map27/Timer.h>
Public Member Functions | |
Map27Timer () | |
void | stop () |
void | start () |
void | start (uint32_t interval) |
void | poll () |
void | setInterval (uint32_t interval) |
void | setCallback (void(*callback)(void *), void *callbackArg=0) |
uint32_t | interval () |
bool | active () |
Protected Member Functions | |
void | triggered () |
Called when the timer is triggered. | |
Class for one-shot millisecond timers.
This class implements a basic one-shot timer. The current implementation is intended to be polled periodically to determine whether the set time has expire, although this can be changed to suit event-driven environments. The current implementation uses Unix based times, but can be ported to other architectures.
Each timer has a time interval in milliseconds, and callback which will be called when the timer expires (or at least it will be called from within poll() the first time poll() is called after the time would expire.
The usual mode of use is:
Map27Timer::Map27Timer | ( | ) |
Constructor Defaults to inactive, with an interval of 0 msec.
bool Map27Timer::active | ( | ) |
uint32_t Map27Timer::interval | ( | ) |
Get the current timer interval
void Map27Timer::poll | ( | ) |
Poll the timer for expiry. If more than interval milliconds have past sine the last start, trigger the callback and mark the timer as inactive (ie this as a one-shot timer)
void Map27Timer::setCallback | ( | void(*)(void *) | callback, |
void * | callbackArg = 0 |
||
) |
Set the callback function. The callback function will be called whenever the timer triggers. When the timer triggers, the calback function wil be called like:
[in] | callback | Pointer to the allback function |
[in] | callbackArg | OPtional argument to be p[assed to callback() |
void Map27Timer::setInterval | ( | uint32_t | interval | ) |
void Map27Timer::start | ( | ) |
Start (or restart) the timer, using the last set interval. Any unexpired potion of the current timer is lost, and the interval starts again from now.
void Map27Timer::start | ( | uint32_t | interval | ) |
Start (or restart) the timer, using the given interval. Any unexpired potion of the current timer is lost, and the interval starts again from now.
[in] | interval | The timer interval in milliseconds. |
void Map27Timer::stop | ( | ) |
Stop the timer The timer econes inactive and will not trigger