Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r2e3b3b2034ee5afb52a8630568145c9705afff9f -r78a138b18328bce8312abac79d76aad9dfe8ea3a --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 2e3b3b2034ee5afb52a8630568145c9705afff9f) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 78a138b18328bce8312abac79d76aad9dfe8ea3a) @@ -34,7 +34,8 @@ // ********** private definitions ********** #define TARGET_DRAIN_PUMP_RPM 1800 ///< Target drain pump speed (in RPM). -#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +#define DRAIN_EMPTY_TARE_WAIT ( MS_PER_SECOND ) ///< Time period to wait after drain complete and before taring load cells. #define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. #define TARGET_RO_FLOW_RATE_L 0.3 ///< Target flow rate for RO pump. @@ -44,11 +45,13 @@ // ********** private data ********** -static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. +static DG_DRAIN_STATE_T drainState; ///< Currently active drain state. +static U32 drainEmptyTareTimerCtr; ///< Timer counter for delay between drain complete and load cell tare. // ********** private function prototypes ********** static DG_DRAIN_STATE_T handleDrainState( void ); +static DG_DRAIN_STATE_T handleTareState( void ); /*********************************************************************//** * @brief @@ -60,6 +63,7 @@ void initDrainMode( void ) { drainState = DG_DRAIN_STATE_START; + drainEmptyTareTimerCtr = 0; } /*********************************************************************//** @@ -121,6 +125,10 @@ drainState = handleDrainState(); break; + case DG_DRAIN_STATE_TARE: + drainState = handleTareState(); + break; + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DRAIN_MODE_INVALID_EXEC_STATE, drainState ) drainState = DG_DRAIN_STATE_START; @@ -132,9 +140,10 @@ /*********************************************************************//** * @brief - * The handleDrainState function handles the drain state of the drain mode state machine. + * The handleDrainState function handles the drain state of the drain mode + * state machine. * @details Inputs: none - * @details Outputs: Drain out from reservoir + * @details Outputs: none * @return the next state *************************************************************************/ static DG_DRAIN_STATE_T handleDrainState( void ) @@ -146,7 +155,6 @@ if ( hasTargetDrainVolumeBeenReached( inactiveReservoir, DRAIN_WEIGHT_UNCHANGE_TIMEOUT ) ) { setDrainPumpTargetRPM( 0 ); - requestNewOperationMode( DG_MODE_CIRC ); #ifndef V_2_SYSTEM if ( DG_RESERVOIR_1 == inactiveReservoir ) @@ -158,13 +166,45 @@ setValveState( VRD2, VALVE_STATE_CLOSED ); } #endif + + if ( TRUE == isReservoirTarePending() ) + { // Tare reservoir load cells at empty if requested + result = DG_DRAIN_STATE_TARE; + } + else + { + requestNewOperationMode( DG_MODE_CIRC ); + } } return result; } /*********************************************************************//** * @brief + * The handleTareState function handles the tare state of the drain mode + * state machine. + * @details Inputs: drainEmptyTareTimerCtr + * @details Outputs: drainEmptyTareTimerCtr + * @return the next state + *************************************************************************/ +static DG_DRAIN_STATE_T handleTareState( void ) +{ + DG_DRAIN_STATE_T result = DG_DRAIN_STATE_TARE; + DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); + + if ( ++drainEmptyTareTimerCtr > DRAIN_EMPTY_TARE_WAIT ) + { + drainEmptyTareTimerCtr = 0; + tareLoadCellsAtEmpty( inactiveReservoir ); + requestNewOperationMode( DG_MODE_CIRC ); + } + + return result; +} + +/*********************************************************************//** + * @brief * The getCurrentDrainState function returns the current state of the drain mode. * @details Inputs: drainState * @details Outputs: none