Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r05019ca03114d75099dd3ae6e09f776bd8a2c46e -rede368b67b0aecd60a9d90546eca353eb6f86e58 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision ede368b67b0aecd60a9d90546eca353eb6f86e58) @@ -94,6 +94,7 @@ static U32 dataPublishCounter = 0; ///< Flush data publish counter. static BOOL hasWaterCancellationBeenSet = FALSE; ///< Water cancellation set/not set boolean flag. static F32 flushLinesVolumeL = 0.0; ///< Volume of water pumped by RO pump during flush lines state. +static BOOL haveDrainParamsBeenInit; ///< Boolean flag to indicate whether the drain parameters have been reset or not. // ********** private function prototypes ********** @@ -124,7 +125,7 @@ * @details Outputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, * rsrvr1Status, rsrvr2Status, hasWaterCancellationBeenSet, - * flushLinesVolumeL + * flushLinesVolumeL, haveDrainParamsBeenInit * @return none *************************************************************************/ void initFlushMode( void ) @@ -141,6 +142,7 @@ rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; hasWaterCancellationBeenSet = FALSE; flushLinesVolumeL = 0.0; + haveDrainParamsBeenInit = FALSE; } /*********************************************************************//** @@ -972,20 +974,29 @@ { DG_RESERVOIR_STATUS_T status = DG_RESERVOIR_ABOVE_TARGET; + // If the drain parameters of the reservoir is not initialized, initialize them + if ( FALSE == haveDrainParamsBeenInit ) + { + initDrainParameters( r ); + haveDrainParamsBeenInit = TRUE; + } + BOOL isDrainComplete = hasTargetDrainVolumeBeenReached( r, drainSteadyStateTimeout ); if ( TRUE == isDrainComplete ) { // Set the state timer in case it needs to be used for another timeout check - stateTimerStart = getMSTimerCount(); - status = DG_RESERVOIR_REACHED_TARGET; + stateTimerStart = getMSTimerCount(); + haveDrainParamsBeenInit = FALSE; + status = DG_RESERVOIR_REACHED_TARGET; } else if ( TRUE == didTimeout( stateTimerStart, timeout ) ) { // Failed to drain on time - prevFlushState = flushState; + prevFlushState = flushState; + haveDrainParamsBeenInit = FALSE; alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; - status = DG_RESERVOIR_NOT_REACHED_TARGET; + status = DG_RESERVOIR_NOT_REACHED_TARGET; } return status;