/********** Pseudo code for the AirLeak State Machine ***********/ Include headers Include Libraries needed (AirLeakLib.h) Define module functions SaveHallData RandomExclusive Define module variables MyPriority CurrentState Fan equal 3 HallData[3] previous_HallData[3] MachineCounter; Indices[] equal {0, 1, 2}; Initialization Function: InitializeAirLeak (param: priority) Call library function AirLeak_ReadHallSensors and store current state of hall in previous_HallData MyPriority equals priority Set CurrentState to be Idle_A return true End Function Post function: PostAirLeakSM (param: ThisEvent) Post ThisEvent in this SM using ES_PostToService() Return true if the event was posted, false otherwise End function Run function: RunAirLeakSM (param: ThisEvent) Create event variable ReturnEvent of type ES_NO_EVENT Create event variable NewEvent What is the CurrentState? CurrentState is Idle_A: If ThisEvent.EventType equal to Tot_Inserted Call library function AirLeak_MoveGauge with MAX_OXIGEN_LEVEL as position Indices[] equal {0, 1, 2} (Assigned with a for loop) End if If ThisEvent.EventType equal to Leak_Develops Save system time in variable SysTime Call RandomExclusivew/ param SysTime. Set Fan to what func returns Call library function AirLeak_FanControl to turn Fan On Init AIRLEAK_TIMER with STEP_TIME Save CurrentState equal to FanOn Increment MachineCounter End if If ThisEvent.EventType equal to End_Of_Game or RST MachineCounter equal 0 End if CurrentState is FanOn: Call library function AirLeak_QueryGauge to get current Oxygen_Level If TIME_OUT and Oxygen_Level greater than 0 Call library function AirLeak_MoveGauge to decrement oxygen level, pass as param Oxygen_Level - STEP_OXIGEN Init AIRLEAK_TIMER with STEP_TIME Else If TIME_OUT and Oxygen_Level less or equal to 0 Post to all events End_Of_Game with parameter Game_Over Call library function AirLeak_FanControl to turn Fan Off Set CurrentState to Idle_A and set Fan to 3, an invalid Fan End if If ThisEvent.EventType equal to AirflowPlugged Call library function AirLeak_FanControl to turn Fan Off Post Interaction_Completed to Arcade_SM Call library function AirLeak_MoveGauge with MAX_OXIGEN_LEVEL as position Set CurrentState to Idle_A and set Fan to 3, an invalid Fan End if If ThisEvent.EventType equal to RST Call library function AirLeak_FanControl to turn Fan Off FanIndex equal 0 MachineCounter equal 0 Set CurrentState to Idle_A and set Fan to 3, an invalid Fan End if If ThisEvent.EventType equal to End_Of_Game Call library function AirLeak_FanControl to turn Fan Off FanIndex equal 0 MachineCounter equal 0 Set CurrentState to Idle_A and set Fan to 3, an invalid Fan end if Return ReturnEvent End Function Checker Function: AirPlugChecker (no param) Create event variable ReturnEvent Create bool variable ReturnVal equal false Call library function AirLeak_ReadHallSensors(HallData) to obtain current HallData If Fan is less than 3 If HallData of Fan equals 0 Post to this SM event Airflow_Plugged Call SaveHallData() to save HallData as previous_HallData ReturnVal equal true End if End if If HallData is different from previous_HallData Post to ResetService the event Airflow_Plugged Call SaveHallData() to save HallData as previous_HallData ReturnVal equal true End if Return ReturnVal End Function Function: SaveHallData (no param) For every hall sensor Copy array by element from HallData to previous_HallData End for End Function Function: RandomExclusive(param: SysTime) Create variable ReturnVal Create variable counter equals 3 - MachineCounter If counter is valid (greater than 0) Get remainder of the division SysTime by the counter Set ReturnVal as the element of Indices at remainder position Remove that element from Indices with a for loop Create auxiliary variable n equal remainder For loop starting at n and repeat until n is less than 3 Over write n element of Indices with element n+1 End for End if return ReturnVal End Function