Вы находитесь на странице: 1из 3

*************************************************************************************

Psuedo-code for the Eve module (a service that implements a state machine)

InitializeEve
Takes a priority number, returns True.

Initialize the MyPriority variable with the passed in parameter.


Initialize LastEveState
Set CurrentState to WaitingForGame
End of InitializeEve

CheckEveEvents
Takes no parameters, returns True if an event was posted
Local ReturnVal = False, CurrentInputState

Get the CurrentInputState from the input line


If the state of the EveLine has changed
Reset ACTIVITY_TIMER to ACTIVITY_TIME
If the current state of the input line is low, then Eve is nearby
PostEvent ES_EVE_TRIGGER to this service
Set ReturnVal to true
EndIf
EndIf
Set LastInputState to CurrentInputState
End of CheckEveEvents

RunEveSM (implements the state machine for Eve)


Set ReturnEvent to 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 WaitingForGame
If ThisEvent is ES_INIT
Turn off heart LED
EndIf
If ThisEvent is ES_GAME_STARTED
Turn Heart LED Off
Set EVE_TIMER to EVE_TIME
Set NextState to HeartOff
Endif
If ThisEvent is ES_RESET_BUTTON
Turn off heart LEDS
EndIf
End WaitingForGame block

CurrentState is HeartOff
If ThisEvent is ES_TIMEOUT and parameter is EVE_TIMER
Turn on Heart LEDs
Post ES_NEED_EVE event to List3
Set NextState to HeartOn
EndIf
If ThisEvent is ES_GAME_LOST
Turn off heart LEDs
Set NextState to WaitingForGame
EndIf
If ThisEvent is ES_GAME_WON
Turn off heart LEDs
Set NextState to WaitingForGame
EndIf
If ThisEvent is ES_RESET_BUTTON
Set NextState to WaitingForGame
EndIf
End HeartOff block

CurrentState is HeartOn
If ThisEvent is ES_EVE_TRIGGER
Turn off Heart LEDs
Start EVE_TIMER to EVE_TIME
Post EVE_TRIGGER event to Sound
Set NextState to HeartOff
Post to LEDStrip to change LED strip lights for correct answers
If ThisEvent is ES_GAME_LOST
Turn off Heart LEDs
Set NextState to WaitingForGame
EndIf
If ThisEvent is ES_GAME_WON
Turn off Heart LEDs
Set NextState to WaitingForGame
EndIf
If ThisEvent is ES_RESET_BUTTON
Turn off Heart LEDs
Set NextState to WaitingForGame
EndIf
End HeartOn block

Set CurrentState to NextState


Return ReturnEvent
End of RunEveSM

Вам также может понравиться