Door Sensor Service
This service is responsible for detecting if the cabinet doors have been open or closed. If the doors are open, the state machine transitions to a Begin state. If the cabinet doors are closed, the state transitions back to Idle.
Constants and Module Variables
Module Defines
Static int LastDoorState, Read_Door_PIN as PORTBbits.RB5, Set_Door_PIN as TRISBbits.TRISB5
Service Initialization
InitDoorSensorStatus
Inputs: priority
Set Set_Door_PIN to 1
Set LastDoorState to Read_Btn_PIN
Post initial ES_INIT
Module Functions
CheckDoorState
No input
Declare int CurrentDoorState, ReturnVal to be false
Set CurrentDoorState to Read_Door_PIN
If CurrentDoorState is different from LastDoorState
Set ReturnVal to true
If CurrentDoorState is 0
Post ES_DOOR_OPEN event to SpiceRackFSM
Else
Post ES_DOOR_CLOSE event to SpiceRackFSM
Update LastDoorState to be CurrentDoorState
Return ReturnVal