You are on page 1of 1

Button Service Pseudo Code Using the Gen2.

x Event Framework
*************************************************************************************
Pseudo-code for the Button Service module
Data private to the module: MyPriority

InitButtonService
Takes a priority number, returns True
Initialize the MyPriority variable with the passed in parameter
Configure digital input on RPB3
Post Event ES_Init to ButtonService queue (this service)
End of InitButtonService

PostButtonService
Takes an event, returns a Boolean value
Calls ES_PostToService on the passed in event with MyPriority
Returns the result of ES_PostToService
End of PostButtonService

RunButtonService
Takes an event (ThisEvent), returns an event
Initialize ReturnEvent as ES_NO_EVENT
Return ReturnEvent
End of RunButtonService

CheckButton
Event checker, takes nothing, returns a Boolean
Initialize static uint8_t HasBeenPressed as 0
Read RPB3 into ButtonStatus
If ButtonStatus is 1 and HasBeenPressed is 0:
Post BUTTON2_PRESS event to RecipeService and MasterSM
Set HasBeenPressed to 1
Return true
Elif ButtonStatus is 0 and HasBeenPressed is 1:
Set HasBeenPressed to 0
Return true
Endif
Return false
End of CheckButton

You might also like