0% found this document useful (0 votes)
55 views

Power Button Service Pseudocode - Notepad

Uploaded by

api-581468038
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Power Button Service Pseudocode - Notepad

Uploaded by

api-581468038
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Power Button Service Pseudocode

/*
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)

set current state to initial pseudostate


post the initial transition event

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 different from LastButtonState:


set the returnVal to true // an event has been detected

create a new buttonPress event

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

You might also like