#include "..\list\list.h"
#include "state.c"
Data Structures | |
struct | STATE_TRAN |
Definition of a state transition. More... | |
struct | STATE_ACTION |
Definition of a state action. More... | |
struct | STATEMGR |
Definition of a state machine. More... | |
Defines | |
#define | STATE_ACTIVE |
This define can be evaluated to check if this module is included and active. | |
Functions | |
STATEMGR * | STATEMGR_create (var vState) |
Creates new State Manager. | |
void | STATEMGR_remove (STATEMGR *psState) |
Removes a State Machine. | |
void | STATEMGR_addTransition (STATEMGR *psState, var vCurState, var vNewState, void *pfCheck, void *pfSwitch) |
Add new transition to State Machine. | |
void | STATEMGR_addState (STATEMGR *psState, var vCurState, void *pfAction, void *pfInit, void *pfDeinit) |
Add new state to State Machine. | |
void | STATEMGR_execute (STATEMGR *psState) |
Execute cyclical actions and transition checks for State Machine. | |
var | STATEMGR_getState (STATEMGR *psState) |
Get currently active state. |
void STATEMGR_addState | ( | STATEMGR * | psState, | |
var | vCurState, | |||
void * | pfAction, | |||
void * | pfInit, | |||
void * | pfDeinit | |||
) |
Add new state to State Machine.
A new state with init, deinit and cyclical callback functions is added. States can only be added, but not removed. Each state may only be added once. If a state is added multiple times, only the first definition will be recognized.
psState | Pointer to affected STATEMGR | |
vCurState | Current state | |
pfAction | Pointer to cyclical action callback function (type void func(void)) [optional: may be set to NULL] | |
pfInit | Pointer to initialization function (called on state entry - type void func(void)) [optional: may be set to NULL] | |
pfDeinit | Pointer to deinitialization function (called on state exit - type void func(void)) [optional: may be set to NULL] |
void STATEMGR_addTransition | ( | STATEMGR * | psState, | |
var | vCurState, | |||
var | vNewState, | |||
void * | pfCheck, | |||
void * | pfSwitch | |||
) |
Add new transition to State Machine.
A new state transition with check condition callback and tranistion action callback is added. Transitions can only be added, but not removed.
psState | Pointer to affected STATEMGR | |
vCurState | Current state | |
vNewState | Next state | |
pfCheck | Check condition callback function (type: var func(void) - return value 1 = true, 0 = false) | |
pfSwitch | Pointer to transition action callback function (type void func(void)) [optional: may be set to NULL] |
STATEMGR* STATEMGR_create | ( | var | vState | ) |
Creates new State Manager.
Use STATEMGR_addTransition and STATEMGR_addAction to configure state manager.
vState | initial state |
void STATEMGR_execute | ( | STATEMGR * | psState | ) |
Execute cyclical actions and transition checks for State Machine.
Must be called cyclically.
psState | Pointer to affected STATEMGR |
var STATEMGR_getState | ( | STATEMGR * | psState | ) |
Get currently active state.
Should only be used for stopping loop functions and never for if checks.
psState | Pointer to affected STATEMGR |
void STATEMGR_remove | ( | STATEMGR * | psState | ) |
Removes a State Machine.
Frees all memory previously allocated by the given state machine.
psState | Pointer to affected STATEMGR |