* Clock * This file contains the service to tick the DDM 60-s clock. Private constants: CLOCK_RATE 42// integer that corresponds to a 3-degree rotation of the servo arm. Module data: tick = 0 (number of clock ticks) MyPriority (module-level variable for the VibrateMotor module's priority) * Initializes the Clock service. * Priority Number: priority of the Clock service in the game state machine InitializeClock Param: Priority Number Return: bool (true) unless the initialization failed 1)set the priority of this event to the Priority Number 2)call initClock function to rotate the servo arm to the starting position 3)set Event Type to ES_INIT End InitializeClock * Runs the Clock service. RunClock Param: Current Event of type ES_Event Return: ES_Event 1) set the Return Event to ES_NO_EVENT and assume no problems will occur 2) create a Return Event if the Current Event is ES_TIMEOUT and the Event Parameter is CLOCK_TIMER if the Mummy is not disARMed move the clock one tick using tickClock function else set the number of ticks to 0 reinitialize the clock using initClock function end else end if 3) return the Return Event end RunClock *Initializes the clock servo. Private function. initClock takes no parameters, returns nothing 1) make the clock servo move to one end using PWM function provided by Ed end initClock * Ticks the clock servo. Private function. tickClock takes no parameters, returns nothing 1) increase the tick count by 1 2) re-calculate where the servo arm should go on the next pulse using the new tick count 3) if the timer has expired/reached its end position set the number of ticks to 0 reinitialize the clock using initClock function return end if 4) Make clock move to nextPulse using PWM function 5) Reset CLOCK_TIMER end tickClock * Posts events to the Clock service. PostClock Param: ES_Event to post to Clock service Return: bool, true if successfully posted; false otherwise 1) return ES_PostToService(MyPriority, ThisEvent); end PostClock