Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r4af713cb53b909ba87893dc814d39af89fb8e8d2 -r87a22cbaa87daab0d7cedabc67452cead83d8630 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 4af713cb53b909ba87893dc814d39af89fb8e8d2) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 87a22cbaa87daab0d7cedabc67452cead83d8630) @@ -17,7 +17,6 @@ #include "ConductivitySensors.h" #include "DrainPump.h" -#include "LoadCell.h" #include "ModeDrain.h" #include "OperationModes.h" #include "Pressures.h" @@ -34,14 +33,11 @@ // ********** private definitions ********** #define TARGET_DRAIN_PUMP_RPM 2800 ///< Target drain pump speed (in RPM). -#define DRAIN_WEIGHT_CHANGE_TOLERANCE 0.1 ///< Weight changes during draining tolerance. -#define DRAIN_WEIGH_UNCHANGE_TIMEOUT ( 10 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Time period of unchanged weight during draining before timeout. +#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 F32 previousWeight; ///< Previous weight of the reservoir draining. -static U32 weightNotDroppingTimerCounter; ///< Timer counter for the period weight not dropping. // ********** private function prototypes ********** @@ -57,8 +53,6 @@ void initDrainMode( void ) { drainState = DG_DRAIN_STATE_START; - previousWeight = 0.0; - weightNotDroppingTimerCounter = 0; } /*********************************************************************//** @@ -123,33 +117,11 @@ static DG_DRAIN_STATE_T handleDrainState( void ) { DG_DRAIN_STATE_T result = DG_DRAIN_STATE_DRAIN; - LOAD_CELL_ID_T drainWeightLoadCell = LOAD_CELL_A1; - F32 currentFilteredWeight; - U32 const targetWeight = getReservoirDrainVolumeTargetMl(); + 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've reached our target drain to volume (by weight) or cannot drain anymore, we're done draining - go back to re-circ mode + if ( hasTargetDrainVolumeReached( inactiveReservoir, DRAIN_WEIGH_UNCHANGE_TIMEOUT ) ) { - drainWeightLoadCell = LOAD_CELL_B1; - } - - currentFilteredWeight = getLoadCellFilteredWeight( drainWeightLoadCell ); - - // if weight stays the same for 10 seconds, timeout and auto calibration - if ( fabs( previousWeight - currentFilteredWeight ) < DRAIN_WEIGHT_CHANGE_TOLERANCE ) - { - previousWeight = currentFilteredWeight; - - if ( ++weightNotDroppingTimerCounter >= DRAIN_WEIGH_UNCHANGE_TIMEOUT ) - { - weightNotDroppingTimerCounter = 0; - setLoadCellAutoCal( drainWeightLoadCell, currentFilteredWeight - targetWeight ); - } - } - - // if we've reached our target drain to volume (by weight), we're done draining - go back to re-circ mode - if ( targetWeight >= currentFilteredWeight ) - { setDrainPumpTargetSpeed( 0 ); requestNewOperationMode( DG_MODE_CIRC ); }