Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_menuFsm.h File Reference

Implementation of a Finite State Machine, for a Menu. More...

Go to the source code of this file.

Data Structures

struct  _FSM
 

Macros

#define FSM_ACTION_ENTRY   0
 
#define FSM_ACTION_EXIT   1
 
#define FSM_ACTION_INPUT   2
 
#define FSM_ACTION_TRANS   3
 
#define fsmSetAction2Entry(sm)   {sm.action = FSM_ACTION_ENTRY;}
 
#define fsmSetAction2Exit(sm)   {sm.action = FSM_ACTION_EXIT;}
 
#define fsmSetAction2Input(sm)   {sm.action = FSM_ACTION_INPUT;}
 
#define fsmSetAction2Transition(sm)   {sm.action = FSM_ACTION_TRANS;}
 
#define fsmSetState(sm, newState)   {sm.stateTop=newState; sm.stateSub1=0; sm.action=FSM_ACTION_ENTRY;}
 
#define fsmIncState(sm, lastState)   { (sm.stateTop==lastState) ? sm.stateTop=0 : sm.stateTop++; sm.stateSub1=0; sm.action=FSM_ACTION_ENTRY;}
 
#define fsmDecState(sm, lastState)   { (sm.stateTop==0) ? sm.stateTop=lastState : sm.stateTop--; sm.stateSub1=0; sm.action=FSM_ACTION_ENTRY;}
 
#define fsmSetStateSub1(sm, newState)   {sm.stateSub1=newState; sm.action=FSM_ACTION_ENTRY;}
 
#define fsmIncStateSub1(sm, lastState)   { (sm.stateSub1==lastState) ? sm.stateSub1=1 : sm.stateSub1++; sm.action=FSM_ACTION_ENTRY;}
 
#define fsmDecStateSub1(sm, lastState)   { (sm.stateSub1==1) ? sm.stateSub1=lastState : sm.stateSub1--; sm.action=FSM_ACTION_ENTRY;}
 

Typedefs

typedef struct _FSM FSM
 

Detailed Description

Implementation of a Finite State Machine, for a Menu.

Author
Modtronix Engineering
Compiler:
MPLAB XC16 compiler

Description

This module implements a Finite State Machine, with special functianality for implementing a menu with a Top level, and Sub Levels

A finite state machine (FSM) or finite automation is a model of behaviour composed of states, transitions and actions. A state stores information about the past, i.e. it reflects the input changes from the system start to the present moment. A transition indicates a state change and is described by a condition that would need to be fulfilled to enable the transition. An action is a description of an activity that is to be performed at a given moment. There are several action types: Entry action

  • execute the action when entering the state Exit action
  • execute the action when exiting the state Input action
  • execute the action dependent on present state and input conditions Transition action
  • execute the action when performing a certain transition

For details see:
https://en.wikipedia.org/wiki/Finite_state_machine

Configuration

The following defines are used to configure this module, and should be placed in projdefs.h. Note that all items marked [-DEFAULT-] are defaults, and do not have to be placed in projdefs.h if they contain desired configuration! For details, see Project Configuration.

// *********************************************************************
// -------------- FSM State Machine Configuration --------------------
// *********************************************************************

Macro Definition Documentation

#define fsmDecState (   sm,
  lastState 
)    { (sm.stateTop==0) ? sm.stateTop=lastState : sm.stateTop--; sm.stateSub1=0; sm.action=FSM_ACTION_ENTRY;}

Decrement Top State. Disable Sub1 state (set to 0). Sets the action to ENTRY.

#define fsmDecStateSub1 (   sm,
  lastState 
)    { (sm.stateSub1==1) ? sm.stateSub1=lastState : sm.stateSub1--; sm.action=FSM_ACTION_ENTRY;}

Decrement Sub1 State. Sets the action to ENTRY.

#define fsmIncState (   sm,
  lastState 
)    { (sm.stateTop==lastState) ? sm.stateTop=0 : sm.stateTop++; sm.stateSub1=0; sm.action=FSM_ACTION_ENTRY;}

Increment Top State. Disable Sub1 state (set to 0). Sets the action to ENTRY.

#define fsmIncStateSub1 (   sm,
  lastState 
)    { (sm.stateSub1==lastState) ? sm.stateSub1=1 : sm.stateSub1++; sm.action=FSM_ACTION_ENTRY;}

Increment Sub1 State. Sets the action to ENTRY.

#define fsmSetAction2Entry (   sm)    {sm.action = FSM_ACTION_ENTRY;}

Change action of current state to FSM_ACTION_ENTRY. The state is not changed.

#define fsmSetAction2Exit (   sm)    {sm.action = FSM_ACTION_EXIT;}

Change action of current state to FSM_ACTION_EXIT. The state is not changed.

#define fsmSetAction2Input (   sm)    {sm.action = FSM_ACTION_INPUT;}

Change action of current state to FSM_ACTION_INPUT. The state is not changed.

#define fsmSetAction2Transition (   sm)    {sm.action = FSM_ACTION_TRANS;}

Change action of current state to FSM_ACTION_TRANS. The state is not changed.

#define fsmSetState (   sm,
  newState 
)    {sm.stateTop=newState; sm.stateSub1=0; sm.action=FSM_ACTION_ENTRY;}

Set the Top State to the given state. Disable Sub1 state (set to 0). Sets the action to ENTRY.

#define fsmSetStateSub1 (   sm,
  newState 
)    {sm.stateSub1=newState; sm.action=FSM_ACTION_ENTRY;}

Set the Sub1 State to the given state. Sets the action to ENTRY.