Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r54f45c387430e440ab4607451fc84dea61f273f1 -r62ee40b55ed96eb0de1c0f05455eb986f76c1842 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 54f45c387430e440ab4607451fc84dea61f273f1) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 62ee40b55ed96eb0de1c0f05455eb986f76c1842) @@ -17,11 +17,11 @@ #include "ConductivitySensors.h" #include "DrainPump.h" -#include "LoadCell.h" #include "ModeDrain.h" #include "OperationModes.h" #include "Pressures.h" #include "Reservoirs.h" +#include "TaskGeneral.h" #include "TemperatureSensors.h" #include "Valves.h" @@ -32,11 +32,12 @@ // ********** private definitions ********** -#define TARGET_DRAIN_PUMP_RPM 2800 ///< Target drain pump speed (in RPM). +#define TARGET_DRAIN_PUMP_RPM 2800 ///< Target drain pump speed (in RPM). +#define DRAIN_WEIGH_UNCHANGE_TIMEOUT ( 10 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. // ********** private data ********** -static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. +static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. // ********** private function prototypes ********** @@ -45,9 +46,8 @@ /*********************************************************************//** * @brief * The initDrainMode function initializes the drain mode module. - * @details - * Inputs : none - * Outputs : drainState + * @details Inputs: none + * @details Outputs: drainState * @return none *************************************************************************/ void initDrainMode( void ) @@ -58,9 +58,8 @@ /*********************************************************************//** * @brief * The transitionToDrainMode function prepares for transition to drain mode. - * @details - * Inputs : none - * Outputs : Drain mode initialized + * @details Inputs: none + * @details Outputs: Drain mode initialized * @return none *************************************************************************/ void transitionToDrainMode( void ) @@ -76,9 +75,8 @@ /*********************************************************************//** * @brief * The execDrainMode function executes the drain mode state machine. - * @details - * Inputs : drainState - * Outputs : Check water quality, drain mode state machine executed + * @details Inputs: drainState + * @details Outputs: Check water quality, drain mode state machine executed * @return current state. *************************************************************************/ U32 execDrainMode( void ) @@ -112,25 +110,18 @@ /*********************************************************************//** * @brief * The handleDrainState function handles the drain state of the drain mode state machine. - * @details - * Inputs : none - * Outputs : Drain out from reservoir + * @details Inputs: none + * @details Outputs: Drain out from reservoir * @return the next state *************************************************************************/ static DG_DRAIN_STATE_T handleDrainState( void ) { DG_DRAIN_STATE_T result = DG_DRAIN_STATE_DRAIN; - LOAD_CELL_ID_T drainWeightLoadCell = LOAD_CELL_A1; + RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); - // determine which load cell to use for drain volume - we want weight of inactive reservoir - if ( RESERVOIR_1 == getActiveReservoir() ) + // if we have reached our target drain to volume (by weight) or cannot drain anymore, we are done draining - go back to re-circ mode + if ( hasTargetDrainVolumeBeenReached( inactiveReservoir, DRAIN_WEIGH_UNCHANGE_TIMEOUT ) ) { - drainWeightLoadCell = LOAD_CELL_B1; - } - - // if we've reached our target drain to volume (by weight), we're done draining - go back to re-circ mode - if ( getReservoirDrainVolumeTargetMl() >= getLoadCellFilteredWeight( drainWeightLoadCell ) ) - { setDrainPumpTargetSpeed( 0 ); requestNewOperationMode( DG_MODE_CIRC ); } @@ -141,9 +132,8 @@ /*********************************************************************//** * @brief * The getCurrentDrainState function returns the current state of the drain mode. - * @details - * Inputs : drainState - * Outputs : none + * @details Inputs: drainState + * @details Outputs: none * @return the current state of drain mode. *************************************************************************/ DG_DRAIN_STATE_T getCurrentDrainState( void )