Pseudocode for ButtonModule FSM
Initialize Variables:
CurrentState ↠InitBState
MyPriority ↠Priority of this service
Function InitButtonModule(Priority):
Set MyPriority to Priority
Set CurrentState to InitBState
Post ES_INIT event to this service
If post is successful, return true
Else, return false
Function PostButtonModule(Event):
Post Event to the service queue with MyPriority
Return success/failure of the operation
Function RunButtonModule(Event):
Initialize ReturnEvent to ES_NO_EVENT (default state for no errors)
Switch(CurrentState):
Case InitBState:
If Event.Type is ES_INIT:
Perform actions for initialization (if any)
Transition to WaitForPress state
Case WaitForPress:
If Event.Type is BUTTON_DOWN:
Start a timer for QUARTER_SEC duration
Transition to PressDetected state
Case PressDetected:
If Event.Type is ES_TIMEOUT:
Print "Press Detected" message
Create new BUTTON_PRESSED event
Post BUTTON_PRESSED event to RecInputService
Transition back to WaitForPress state
Default:
Do nothing (no defined behavior for other states)
Return ReturnEvent
Function QueryButtonModule():
Return CurrentState