Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -rb692af0986725e87431ca5e23c5721f1b242baac -r051326e2671e8d5b3e99eaa109ea549e94a929f3 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision b692af0986725e87431ca5e23c5721f1b242baac) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 051326e2671e8d5b3e99eaa109ea549e94a929f3) @@ -40,6 +40,8 @@ #define MAX_HOME_FULL_TRAVEL_DIFF 100U ///< Maximum allowed difference in full travel encoder counts between expected and measured during home operation. #define VALVE_TRANSITION_TIMEOUT_MS 3000U ///< Valves transition time out in ms +#define VALVE_FORCE_HOME TRUE ///< Force valve to home even if already homed + /// Valve controller states typedef enum Valve_Control_States { @@ -132,6 +134,48 @@ /*********************************************************************//** * @brief + * The homeValve function requests a valve homing operation on a given valve. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given valve is invalid. + * @details \b Inputs: currentValveStates[] + * @details \b Outputs: currentValveStates[] + * @param valve ID of valve that is set to be homed + * @param force flag indicating whether homing should be forced even if already homed + * @param cartridge flag indicating whether a cartridge may be present requiring a more lax homing + * @return TRUE if the homing command accepted otherwise, FALSE + *************************************************************************/ +BOOL homeValve( VALVE_T valve, BOOL force, BOOL cartridge ) +{ + BOOL result = FALSE; + + if ( valve < NUM_OF_VALVES ) + { + VALVE_STATE_T currState = currentValveStates[ valve ].controlState; + + if ( ( VALVE_STATE_HOMING_NOT_STARTED == currState ) || ( VALVE_STATE_IDLE == currState ) ) + { + // If haven't already homed the valves, home the valves + if ( ( currentValveStates[ valve ].hasValveBeenHomed != TRUE ) || ( VALVE_FORCE_HOME == force ) ) + { + currentValveStates[ valve ].hasHomingBeenRequested = TRUE; + } + // Otherwise, go to position A (home position) + else + { + setValvePosition( valve, VALVE_POSITION_A_INSERT_EJECT ); + } + result = TRUE; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_VALVES_INVALID_VALVE8, (U32)valve ) + } + + return result; +} + +/*********************************************************************//** + * @brief * The setValvePosition function sets the commanded position for a given valve. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid valve or position given. * @details \b Inputs: none