You are on page 1of 1

AudioMod (a service that implements a state machine)

Module Variables: CurrentState, MyPriority


InitializeAudio
Takes a priority number, returns true.
Initialize the MyPriority variable with the passed in parameter.
Set CurrentState to InitAudio
Post ES_INIT to AudioMod
End of InitializeAudio (return True)
RunAudio (implements the state machine for Audio)
The EventType field of ThisEvent will be one of: ES_INIT, TargetHit, TargetMiss or ES_TIMEOUT
Returns ES_NO_EVENT
Local Variable: NextState
Set NextState to CurrentState
Based on the state of the CurrentState variable choose one of the following blocks of code:
CurrentState is InitAudio
If ThisEvent is ES_INIT
Turn off hit and miss audio
Set NextState to AUDIO_OFF
End if
End of InitAudio block
CurrentState is AUDIO_OFF
If ThisEvent is TargetHit
Start Audio timer which expires in 5 sec and posts to AudioMod
Set NextState to AUDIO_ON
Set audio line of target hit to be high
End if
If ThisEvent is TargetMiss
Start Audio timer which expires in 5 sec and posts to AudioMod
Set NextState to AUDIO_ON
Set audio line of target miss to be high
End if
End of AUDIO_OFF block
CurrentState is AUDIO_ON
If ThisEvent is ES_TIMEOUT from Audio timer
Turn both audio lines as low
Set NextState to AUDIO_OFF
End if
End of AUDIO_ON block
Set CurrentState to NextState
Return ES_NO_EVENT
End of RunAudio

You might also like