// Takes: uint8_t Priority: Service priority number
// Returns: True if init event is posted bool MotorInit (uint8_t Priority){ set local priority setup motor hardware set current state to ready return es_init event } // Post Function // Takes: ES_Event ThisEvent: event to be posted // Returns: true if event was successfully posted bool PostMotor(ES_Event ThisEvent){ set up post function } // Motor running service for controlling the curtain // Takes: ES_Event ThisEvent: of type ES_OPEN_CURTAIN, ES_CLOSE_CURTAIN, or ES_T IMEOUT // Returns: ES_Event ReturnEvent: ES_NO_EVENT if no errors occur ES_Event RunMotor(ES_Event ThisEvent){ set next state to current state if the state is ready: if the event is ES_OPEN set the motor forward set the motor timer next state is moving if the event is ES_RESET check that the curtain is not already closed if the curtain is not already closed set the motor backward set the motor timer next state is moving if the state is moving: if the event is ES_TIMEOUT or ES_BUTTON_DOWN set the motor stop next state is ready set the current state to next state } // Run the Motor // Takes: uint8_t input1 and uint8_t input2: 1 or zero to set motor direction // Returns: nothing static void Motor(uint8_t input1, uint8_t input2) { if input 1 and input 2 are both off stop the motor else if input 1 is high but input 2 is low run the motor forward else if input 1 is low and input 2 is high run the motor backwards } // Initialize motor hardware/peripherals // Takes: nothing // Returns: nothing static void MotorHardwareInit(void) { set up pins for input 1 and 2 as digital output initially at 0 set pwm for enable pin Initialize the curtain button input pin and set to digital input }