Psuedogamebuttons
Psuedogamebuttons
Psuedogamebuttons
Psuedo-code for the GameButton module (a service that implements a state machine)
InitializeGameButton
Takes a priority number, returns True.
CheckButtonEvents
Takes no parameters, returns True if an event was posted
Local ReturnVal = False, CurrentInputState, MultipleDown = False
CurrentState is Debouncing
If ThisEvent is ES_TIMOUT and EventParam is BUTTON_DEBOUNCE_TIMER
Set NextState to Ready2Sample
EndIf
End of Debouncing Block
CurrentState is Ready2Sample
If ThisEvent is ES_TRASH_BUTTON
Start BUTTON_DEBOUNCE_TIMER to BUTTON_DEBOUNCE_TIME
Post ES_TRASH_BUTTON to Game SM
Set NextState to Debouncing
EndIf
If ThisEvent is ES_COMPOST_BUTTON
Start BUTTON_DEBOUNCE_TIMER to BUTTON_DEBOUNCE_TIME
Post ES_COMPOST_BUTTON to Game SM
Set NextState to Debouncing
EndIf
If ThisEvent is ES_RECYCLING_BUTTON
Start BUTTON_DEBOUNCE_TIMER to BUTTON_DEBOUNCE_TIME
Post ES_RECYCLING_BUTTON to Game SM
Set NextState to Debouncing
EndIf
If ThisEvent is ES_MULTIPLE_DOWN
Start BUTTON_DEBOUNCE_TIMER to BUTTON_DEBOUNCE_TIME
Post ES_MULTIPLE_DOWN to Game SM
Set NextState to Debouncing
EndIf
If ThisEvent is ES_RESET_BUTTON
Start BUTTON_DEBOUNCE_TIMER to BUTTON_DEBOUNCE_TIME
Post ES_RESET_BUTTON to all services
Set NextState to Debouncing
EndIf
End of Ready2Sample Block
Set CurrentState to NextState
Return ReturnEvent
End of RunGameButton
End of GameButtonSM