Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Define:
Debounce interval
Debounce quiet time
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
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