WaitingSM State Machine
WaitingSM Pseudocode
START OF WaitingSM
/******************************************************************************/
GAME WAITING MODULE STATE MACHINE PSEUDO-CODE
InitializeWaitingSM
Takes a priority number, returns True
Initialize the MyPriority variable with the passed in parameter
Set CurrentState to be InitWaitingSM
post Event ES_INIT to InitWaitingSM (this service)
End
RunWaitingSM (implements the state machine for the Marathon Beekeeping Initialization, i.e. waiting and setting up players)
The EventType field of ThisEvent will be of one: ES_INIT, ES_STOMPRISE, ES_PLAYERON,
ES_BATONON, ES_BATONFALL, ES_RESET, ES_CARDREAD, ES_TIMEOUT
List fo States: InitPSM, WaitCardSwipe, WaitingFor2Players, WaitPlayerOnMsg, WaitPlayerStompRise
Wait2Batons, WaitBatonOn, WaitBatonFall, InitDone
Returns ES_NO_EVENT
Local Variables: NextState
Set NextState to CurrentState
Based on the state of the CurrentState variable, choose one of the following blocks of code:
CurrentState is InitWaitingSM
IF ThisEvent is ES_INIT
Set NextState to WaitCardSwipe
ENDIF
End InitWaitingSM
CurrentState is WaitCardSwipe
IF ThisEvent is ES_CARDREAD
Send SWIPE message
Light Red Standby LED
IF StompPin Low
Set CurrentState to WaitingFor2Players
ELSE StompPin High
Send ES_PLAYERON to other C32
Yellow Waiting for Other Player LED On
Set CurrentState to WaitPlayerOnMsg
ENDIF
ENDIF
End WaitCardSwipe
CurrentState is WaitingFor2Players
IF ThisEvent is ES_PLAYERON
Set NextState to WaitPlayerStompRise
ENDIF
IF ThisEvent is ES_STOMPRISE
Red Standby LED off
Yellow Waiting for Other Player LED On
Set NextState to WaitPlayerOnMsg
ENDIF
IF ThisEvent is ES_RESET
call reset function
Set NextState to WaitCardSwipe
ENDIF
End WaitingFor2Players
CurrentState is WaitPlayerOnMsg
IF ThisEvent is ES_PLAYERON
Set NextState to Wait2Batons
ENDIF
IF ThisEvent is ES_RESET
call reset function
Set NextState to WaitCardSwipe
ENDIF
End WaitPlayerOnMsg
CurrentState is WaitPlayerStompRise
IF ThisEvent is ES_STOMPRISE
Set NextState to Wait2Batons
ENDIF
IF ThisEvent is ES_RESET
call reset function
Set NextState to WaitCardSwipe
End WaitPlayerStompRise
CurrentState is Wait2Batons
IF ThisEvent is ES_BATONON
Set NextState to WaitBatonFall
ENDIF
IF ThisEvent is ES_BATONFALL
Set NextState to WaitBatonOn
ENDIF
IF ThisEvent is ES_RESET
call reset function
Set NextState to WaitCardSwipe
End Wait2Batons
CurrentState is WaitBatonOn
IF ThisEvent is ES_BATONON
start goTimer
Set NextState to InitDone
ENDIF
IF ThisEvent is ES_RESET
call reset function
Set NextState to WaitCardSwipe
End WaitBatonOn
CurrentState is WaitBatonFall
IF ThisEvent is ES_BATONFALL
start goTimer
Set NextState to InitDone
ENDIF
IF ThisEvent is ES_RESET
call reset function
Set NextState to WaitCardSwipe
End WaitBatonFall
IF CurrentState is InitDone
IF ThisEvent is ES_RESET
Turn off all LEDs
Set NextState to WaitCardSwipe
END InitDone
Set CurrentState to NextState
Return ES_No_EVENT
END of InitSM
/******************************************************************************/
Private Functions
/******************************************************************************/
void reset( void)
Purpose: resets the game components to their inititial state
Turn off all LEDs
/******************************************************************************/