Functions | |
int | Timer_SetActive (bool active) |
Controls the active state of the Timer subsystem. | |
int | Timer_GetActive () |
Returns whether the timer subsystem is active or not. | |
void | Timer_InitializeEntry (TimerEntry *timerEntry, void(*timerCallback)(int id), int id, int timeMs, bool repeat) |
Initializes a new timer structure. | |
int | Timer_Set (TimerEntry *timerEntry) |
Sets a given TimerEntry to run. | |
int | Timer_Cancel (TimerEntry *timerEntry) |
Cancel a timer event. |
For higher resolution timing, check the Fast Timer
The Timer subsystem is based on a collection of TimerEntries. To start a new timer, create a new TimerEntry structure, initialize it with Timer_InitializeEntry( ), and start it with Timer_Set( ).
There are currently a couple of limitations to the Timer system:
Allow existing timer entries to be modified (repeat or not, modify the period, etc.)
int Timer_Cancel | ( | TimerEntry * | timerEntry | ) |
int Timer_GetActive | ( | void | ) |
Returns whether the timer subsystem is active or not.
void Timer_InitializeEntry | ( | TimerEntry * | timerEntry, | |
void(*)(int id) | timerCallback, | |||
int | id, | |||
int | timeMs, | |||
bool | repeat | |||
) |
Initializes a new timer structure.
The event is signified by a callback to the function provided, after the interval specified. The specified ID is passed back to the function to permit one function to work for many events. Pass repeat = true to make the event continue to create callbacks until it is canceled.
timerEntry | pointer to the TimerEntry to be intialized. | |
timerCallback | pointer to the callback function. The function must be of the form void timerCallback( int id ) | |
id | An integer specifying the ID the callback function is to be provided with. | |
timeMs | The time in milliseconds desired for the callback. | |
repeat | Set whether the timer repeats or is a one-time event. |
TimerEntry myTimer; // our TimerEntry Timer_InitializeEntry( &myTimer, myCallback, 0, 250, true ); Timer_Set( &myTimer ); // start our timer void myCallback( int id ) // our code that will get called by the timer every 250 ms. { // do something here }
int Timer_Set | ( | TimerEntry * | timerEntry | ) |
Sets a given TimerEntry to run.
This routine adds the entry to the running queue and then decides if it needs to start the timer (if it's not running) or alter the timer's clock for a shorter period.
timerEntry | pointer to the FastTimerEntry to be run. |
int Timer_SetActive | ( | bool | active | ) |
Controls the active state of the Timer subsystem.
active | whether this subsystem is active or not |