You are on page 1of 2

Game Flag Service Pseudo Code Using the Gen2.

x Event Framework
*************************************************************************************
Pseudo-code for the Game Flag Service module
Data private to the module: MyPriority, CurrentState,
CurrentPosition, FULL_OPEN, FULL_CLOSE, TICKS_PER_STEP,
TICKS_PER_STEP_CCW, DIRECTION_CW, DIRECTION_CCW, timeStep

InitGameFlagService
Takes a priority number, returns True
Initialize the MyPriority variable with the passed in parameter
Set up Timer 2 and Timer 3 with period 50 Hz, 16 bit mode
Set up OC2 on Timer 2
Set OC2 output pin to RPB5
Set CurrentState to InitGameFlag, CurrentPosition to FULL_OPEN
Post Event ES_Init to GameFlagService queue (this service)
End of InitGameFlagService

PostGameFlagService
Takes an event, returns a Boolean value
Calls ES_PostToService on the passed in event with MyPriority
Returns the result of ES_PostToService
End of PostGameFlagService

RunGameFlagService
Takes an event (ThisEvent), returns an event
Initialize ReturnEvent as ES_NO_EVENT

If CurrentState is InitGameFlag:
If ThisEvent is ES_INIT:
Set CurrentState to GameFlagDown
Endif
Elif CurrentState is GameFlagUp:
If ThisEvent is GAME_ENDED:
Set OC2RS to FULL_OPEN
Set CurrentState to GameFlagDown
Endif
Elif CurrentState is GameFlagDown:
If ThisEvent is GAME_STARTED:
Set OC2RS to FULL_CLOSE
Set CurrentState to GameFlagUp
Endif
Endif
Return ReturnEvent
End of RunGameFlagService

You might also like