You are on page 1of 1

Limit Switch Service Pseudo Code Using the Gen2.

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

InitLimitSwitchService
Takes a priority number, returns True
Initialize the MyPriority variable with the passed in parameter
Configure digital input on RPB4
Configure pullup resistor on RPB4
Post Event ES_Init to LimitSwitchService queue (this service)
End of InitLimitSwitchService

PostLimitSwitchService
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 PostLimitSwitchService

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

CheckLimitSwitch
Event checker, takes nothing, returns a Boolean
Initialize static uint8_t HasBeenPressed as 0
Read RPB4 into SwitchStatus
If SwitchStatus is 1 and HasBeenPressed is 0:
Post LIMIT_CHANGE event to SPIPeripheralService with param 1
Set HasBeenPressed to 1
Return true
Elif SwitchStatus is 0 and HasBeenPressed is 1:
Post LIMIT_CHANGE event to SPIPeripheralService with param 0
Set HasBeenPressed to 0
Return true
Endif
Return false
End of CheckLimitSwitch

You might also like