Power Button Service Pseudocode - Notepad
Power Button Service Pseudocode - Notepad
/*
This module contains the logic to debounce the power button and send a single
POWER_BUTTON_PRESS event to GameProgressionService whenever the power button is
pressed. Also contains the event checker for the power button.
*/
InitPowerButton
initialize input pin as digital input
set LastButtonState to current value of RB3 (input pin)
RunPowerButton
switch on current state:
initial pseudostate:
if received ES_INIT event:
set current state to PowerButtonIdle
PowerButtonIdle:
if received BUTTONDOWN event for the power button
(EventParam is 1):
set current state to ButtonDown
init POWER_BUTTON_TIMER to debounce button press
ButtonDown:
if received ES_TIMEOUT event from POWER_BUTTON_TIMER:
set current state to ButtonUp // button press has
been debounced
ButtonUp:
if received BUTTONUP event from power button (EventParam is
1):
set current state to PowerButtonIdle
create a POWER_BUTTON_PRESS event
post event to GameProgressionservice
return ES_NO_EVENT
CheckPowerButtonPress:
set returnVal to false;
read CurrentButtonState from RB3
if the CurrentButtonState is 1:
// then button has been pressed down so
set buttonPress event type to BUTTONDOWN
set buttonPress event param to 1 // to specify which button
is pressed
else:
// button is currentlyt 0 which means the button has gone up
set the buttonPress event type to BUTTONUP
set buttonPress event param to 1 // to specify which button
is pressed