Map27
 All Classes Functions Variables Enumerations Enumerator Pages
Public Member Functions | Protected Member Functions | List of all members
Map27Timer Class Reference

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.
 

Detailed Description

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:

* #define INTERVAL 12345
* Timer mytimer;
* mytimer.setCallback(mycallbackfunction, mycallbackarg);
* mytimer.start(INTERVAL);
* mytimer.poll();
* ....
* mytimer.poll();
* .... // do some things, during which time the INTERVAL expires
*
* mytimer.poll();
* // poll() calls mycallbackfunction(mycallbackarg);
* // timer is now inactive until start() is called again
*
Examples:
test.cpp.

Constructor & Destructor Documentation

Map27Timer::Map27Timer ( )

Constructor Defaults to inactive, with an interval of 0 msec.

Member Function Documentation

bool Map27Timer::active ( )

Determine if the timer is active

Returns
true if the timer is currently active.
Examples:
test.cpp.
uint32_t Map27Timer::interval ( )

Get the current timer interval

Returns
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)

Examples:
test.cpp.
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:

* callback(callbackArg);
*
Parameters
[in]callbackPointer to the allback function
[in]callbackArgOPtional argument to be p[assed to callback()
Examples:
test.cpp.
void Map27Timer::setInterval ( uint32_t  interval)

Set the desired interval. Any previously set interval is lost. If the new interval is less than the time since the last start() the timer will trigger.

Parameters
[in]intervalThe timer interval in in illisconds.
Examples:
test.cpp.
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.

Examples:
test.cpp.
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.

Parameters
[in]intervalThe timer interval in milliseconds.
void Map27Timer::stop ( )

Stop the timer The timer econes inactive and will not trigger


The documentation for this class was generated from the following files: