* GearMotor * This controls the DC gear motor that opens the sarcophagus door. define: MOTOR_OPEN_TIME 2400 // gear motor opening run time [ms] define: MOTOR_CLOSE_TIME 100 // gear motor closing run time [ms] Module data: MyPriority; // module-level variable for the GearMotor module's priority * Initializes the GearMotor service. * uint8_t priority: priority of the GearMotor service InitializeGearMotor Param: priority Return: bool, true unless the initialization failed 1) post the initial transition event of type ES_INIT with the priority value 2) if the initialization event posted correctly return true else return false end InitializeGearMotor * Runs the GearMotor service. * CurrentEvent: the current event that has occurred RunGearMotor Param: CurrentEvent Return: ES_Event called ES_NO_EVENT; // assume no problems will occur 1) decide what the gear motor should do based on the Event Type if the event type is DoorOpen call the openDir function to set the motor to rotate in the opening direction. start the GEAR_MOTOR_TIMER with the parameter MOTOR_OPEN_TIME determine duration if the event type is DoorClose call the closeDir function to set the motor to rotate in the opening direction. start the GEAR_MOTOR_TIMER with the parameter MOTOR_CLOSE_TIME determine duration if the event type is ES_TIMEOUT: if the timer that expired is the Gear Motor timer call the brake function to stop the motor end if 2) return ReturnEvent; end RunGearMotor * Posts events to the GearMotor service. * ThisEvent: event to post to GearMotor servce * return true if successfully posted; false otherwise PostGearMotor Param: ThisEvent, event to post to GearMotor service Return bool, true if successfully posted; false otherwise 1) return ES_PostToService(MyPriority, ThisEvent) end PostGearMotor * Sets the motor to rotate in the opening direction. Private function. openDir takes no parameters, returns nothing Set pin1 on the gear motor high Set pin2 on the gear motor low end openDir * Sets the motor to rotate in the closing direction. Private function. closeDir takes no parameters, returns nothing Set pin1 on the gear motor low Set pin2 on the gear motor high end closeDir * Stops the motor. Private function. takes no parameters, returns nothing brake Set both pin1 and pin2 on the gear motor high to stop rotation end brake