Sie sind auf Seite 1von 3

Pseudocode for ButtonDebounce

Define:
Debounce interval
Debounce quiet time

Module level functions:

Module level variables:


Priority of this module
last button state
current state
bool Hi
Bool getting range
GameStatus pointer
range

Function: InitButtonDebounceService
Parameters: the priority of this service
Returns: bool, true
initialize port line to monitor the button
assign RC0 to digital, set to input, and configure internal pull-up
sample the button port pin and use it to init LastButtonState
set CurrentState to Debouncing
Start debounce timer
return true
end InitButtonDebounceService

Function: PostButtonDebounceService
Parameters: the event to post to the queue
Returns: bool, false if the Enqueue operation failed, true otherwise
return ES_PostToService with MyPriority as paramater and given event as event type
end of PostButtonDebounceService

Function: Check4ButtonEvent
Parameters: none
Returns: bool, false if the Enqueue operation failed, true otherwise

Get current state of button

if current button state is not equal to last button state,


if button is up
post ES_TEAM_BUTTON_UP
set last button state to current button state
return true
if button is down
post ES_TEAM_BUTTON_DOWN
set last button state to current button state
return true
endif
Post result to this state machine
endif
return returnval
end Check4ButtonEvent

Function: RunButtonDebounceService
Parameters: the event to process
Returns: returnval is ES_NO_EVENT if no error

switch CurrentState
case: if state is debouncing
if this event is timeout event of button timer
set current state to Ready2Sample
Endif
If this event is timeout event of debounce quiet timer
If we are getting the range
Get the distance to detonate
Set getting range = false
Endif
Set we launched to true
endif
end case
case: if state is Ready2Sample
if this event is ES_BUTTON_UP
start timer, enter debouncing statae
endif
if this event is ES_BUTTON_DOWN
start timer, enter debouncing state
if TX_State is not transmitting
Start debounce quiet timer
Endif
Endif
If this event is timeout of debounce quiet timer
Post ES_TRANSMIT to TX, RX, LED services
endif
endif
end case
return returnval
end of RunButtonDebounceService

Das könnte Ihnen auch gefallen