Hammer Detect MODULE PSEUDOCODE
HammerDetect Module (State Machine)
InitHammerDetect
initialize currentState as HammerInit
return True
End of InitHammerDetect
RunHammerDetect
States: HammerInit, WaitForDetect, HammerIdle
Events: ES_BEAR_DEAD, ES_HAMMER_DOWN, ES_GAME_STOPPED, ES_GAME_OVER, ES_CARD_READ
If currentState is HammerInit
If EventType is ES_BEAR_DEAD
set currentState to WaitForDetect
End if
End if
If currentState is WaitForDetect
If EventType is ES_HAMMER_DOWN
post Event ES_HAMMER_DOWN to EOGButton Module
set currentState to HammerIdle
Else if EventType is ES_GAME_OVER
set currentState to HammerIdle
Else if EventType is ES_GAME_STOPPED
set currentState to HammerIdle
End if
If currentState is HammerIdle
If EventType is ES_CARD_READ
set currentState to HammerInit
End if
End if
End of RunHammerDetect
check4Hammer reads nothing, returns true
returnVal is false
read hammer detect pin and save to currentHammerState
If currentHammerState is not equal to lastHammerState
post ES_HAMMER_DOWN to HammerDetect module
start GAME_STOP_TIMER
set returnVal to true
End if
return returnVal
End of check4Hammer
InitHammerDetect
initialize currentState as HammerInit
return True
End of InitHammerDetect
RunHammerDetect
States: HammerInit, WaitForDetect, HammerIdle
Events: ES_BEAR_DEAD, ES_HAMMER_DOWN, ES_GAME_STOPPED, ES_GAME_OVER, ES_CARD_READ
If currentState is HammerInit
If EventType is ES_BEAR_DEAD
set currentState to WaitForDetect
End if
End if
If currentState is WaitForDetect
If EventType is ES_HAMMER_DOWN
post Event ES_HAMMER_DOWN to EOGButton Module
set currentState to HammerIdle
Else if EventType is ES_GAME_OVER
set currentState to HammerIdle
Else if EventType is ES_GAME_STOPPED
set currentState to HammerIdle
End if
If currentState is HammerIdle
If EventType is ES_CARD_READ
set currentState to HammerInit
End if
End if
End of RunHammerDetect
check4Hammer reads nothing, returns true
returnVal is false
read hammer detect pin and save to currentHammerState
If currentHammerState is not equal to lastHammerState
post ES_HAMMER_DOWN to HammerDetect module
start GAME_STOP_TIMER
set returnVal to true
End if
return returnVal
End of check4Hammer