You are on page 1of 2

Idle.

c // a service that implements a state machine to reset the system if idle


for 30sec
Data private to the module: MyPriority, CurrentState, IDLE_TIME
Module functions: InitIdle, PostIdle and RunIdle

InitIdle
Takes a priority number
returns a bool: false if error in initialization, true otherwise

PostIdle
Takes an event to post to the queue.
Returns a bool: false if the Enqueue operation failed, true otherwise

RunIdle
Takes in ThisEvent as parameter. ThisEvent will be one of:ES_Init, CORRECT_NOTE,
MOVE DOWN, MOVE_UP, FULLY_DOWN, FULLY_UP, CAR_PLACED, HEADSPHONE_RESET, ES_TIMEOUT.
The parameter field of ES_TIMEOUT will be the timer that caused the event to occur.
Returns ES_NO_EVENT if no error ES_ERROR otherwise

Description
set return event to ES_NO_EVENT(assuming no error)
switch based on CurrentState:

CurrentState is Initialization
If ThisEvent is ES_Init
Set currentState to Interacting
End Initialization block

CurrentState is Interacting
If ThisEvent is CORRECT_NOTE or MOVE_DOWN or MOVE_UP or FULLY_DOWN or
FULLY_UP or CAR_PLACE
Start/reset Idle timer
Else If ThisEvent is ES_TIMEOUT with parameter IdleTimer
Post Event EARLY_RESET to all services
Set CurrentState to Idling
Else If ThisEvent is HEADPHONES_RESET or ES_TIMEOUT with parameter
MainTimer
Stop idleTimer
Set CurrentState to Idling
Endif
End Interacting block

CurrentState is Idling
If ThisEvent is CAR_PLACED
Start idle timer
Set CurrentState to Interacting
End if
End Idling block
Return ReturnVal
End RunIdle

You might also like