Vous êtes sur la page 1sur 5

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

Pseudo-code for the Eye Clock module (a service that implements a state machine)

InitializeEyeClock
Takes a priority number, returns True.

Initialize the MyPriority variable with the passed in parameter.


Set CurrentState to AllOn
Post Event ES_Init to EyeClock queue (this service)
End of InitializeEyeClock

RunEyeClockSM (implements the state machine for Eye Clock)


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 AllOff
If ThisEvent is ES_INIT
Turn on all LEDs
Set NextState to SixLEDOn
Endif
If ThisEvent is ES_RESET_BUTTON
Turn on all LEDs
Set NextState to SixLEDOn
End AllOff Block

CurrentState is SixLEDOn
If ThisEvent is ES_TIMEOUT and parameter is EYE_TIMER
Turn off LED 1
Set EYE_TIMER to be 10s and start timer
Set NextState to FiveLEDOn
EndIf
If ThisEvent is ES_LEAF_INSERTED
Turn on all LEDs
Set EYE_TIMER to be 10s and start timer
EndIf
If ThisEvent is ES_GAME_WON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
If ThisEvent is ES_GAME_LOST
Turn off all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
If ThisEvent is ES_RESET_BUTTON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
If ThisEvent is ES_NO_ACTIVITY
Set EventType to ES_ERROR
Set EventParam to line number
EndIf
End SixLEDOn block

CurrentState is FiveLEDOn
If ThisEvent is ES_TIMEOUT and parameter is EYE_TIMER
Turn off LED 2
Set EYE_TIMER to be 10s and start timer
Set NextState to FourLEDOn
EndIf
If ThisEvent is ES_GAME_LOST
Turn off All LEDs
Set NextState to AllOff
Stop EYE_TIMER
EndIf
If ThisEvent is ES_GAME_WON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
If ThisEvent is ES_RESET_BUTTON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
End FiveLEDOn block

CurrentState is FourLEDOn
If ThisEvent is ES_TIMEOUT and parameter is EYE_TIMER
Turn off LED 3
Set EYE_TIMER to be 10s and start timer
Set NextState to ThreeLEDOn
EndIf
If ThisEvent is ES_GAME_LOST
Turn off all LEDs
Set NextState to AllOff
Stop EYE_TIMER
EndIf
If ThisEvent is ES_GAME_WON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
If ThisEvent is ES_RESET_BUTTON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
End FourLEDOn block

CurrentState is ThreeLEDOn
If ThisEvent is ES_TIMEOUT and parameter is EYE_TIMER
Turn off LED 4
Set EYE_TIMER to be 10s and start timer
Set NextState to TwoLEDOn
EndIf
If ThisEvent is ES_GAME_LOST
Turn off all LEDs
Set NextState to AllOff
Stop EYE_TIMER
EndIf
If ThisEvent is ES_GAME_WON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
If ThisEvent is ES_RESET_BUTTON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
End ThreeLEDOn block

CurrentState is TwoLEDOn
If ThisEvent is ES_TIMEOUT and parameter is EYE_TIMER
Turn off LED 5
Set EYE_TIMER to be 10s and start timer
Set NextState to OneLEDOn
EndIf
If ThisEvent is ES_GAME_LOST
Turn off all LEDs
Set NextState to AllOff
Stop EYE_TIMER
EndIf
If ThisEvent is ES_GAME_WON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
If ThisEvent is ES_RESET_BUTTON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
End TwoLEDOn block

CurrentState is OneLEDOn
If ThisEvent is ES_TIMEOUT and parameter is EYE_TIMER
Turn off all LED
Post ES_GAME_LOST to List2
Set NextState to AllOff
EndIf
If ThisEvent is ES_GAME_LOST
Turn off all LEDs
Set NextState to AllOff
Stop EYE_TIMER
If ThisEvent is ES_GAME_WON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
If ThisEvent is ES_RESET_BUTTON
Turn on all LEDs
Set NextState to SixLEDOn
Stop EYE_TIMER
EndIf
End OneLEDOn block

Set CurrentState to NextState


Return ReturnEvent
End of RunEyeClockSM

Vous aimerez peut-être aussi