Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r81872acd6f2ce222c6b9a9b93f65b7cd3665f28f -rd7be59e36db5e9899b02dd0bfadadc50fed934c0 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 81872acd6f2ce222c6b9a9b93f65b7cd3665f28f) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision d7be59e36db5e9899b02dd0bfadadc50fed934c0) @@ -7,8 +7,8 @@ * * @file ModeFlush.c * -* @author (last) Dara Navaei -* @date (last) 30-Apr-2022 +* @author (last) Bill Bracken +* @date (last) 22-Aug-2022 * * @author (original) Leonardo Baloa * @date (original) 20-Dec-2019 @@ -49,14 +49,15 @@ #define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 6 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. // Flush drain path state defines -#define FLUSH_DRAIN_WAIT_TIME_MS ( 2 * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. TODo it was 2 minutes +#define FLUSH_DRAIN_WAIT_TIME_MS ( 2 * 60 * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. // Flush dialysate state defines #define FLUSH_DIALYSATE_WAIT_TIME_MS ( 60 * MS_PER_SECOND ) ///< Flush dialysate wait time in milliseconds. // Flush concentrate straws state defines #define FLUSH_CONCENTRATE_STRAWS_TIME_MS ( 3 * 60 * MS_PER_SECOND ) ///< Flush concentrate straws wait time in milliseconds. todo was 3 minutes #define ACID_PUMP_SPEED_ML_PER_MIN -30.0F ///< Acid pump speed in mL/min. + // The bicarb pump is 2% faster than the acid pump to create a flow from acid to bicarb line during flush #define BICARB_PUMP_SPEED_ML_PER_MIN 30.6F ///< Bicarb pump speed in mL/min. @@ -94,7 +95,7 @@ static U32 dataPublishCounter; ///< Flush data publish counter. static BOOL hasWaterCancellationBeenSet; ///< Water cancellation set/not set boolean flag. static F32 flushLinesVolumeL; ///< Volume of water pumped by RO pump during flush lines state. -static BOOL haveDrainParamsBeenInit[ NUM_OF_DG_RESERVOIRS ]; ///< Boolean flag to indicate whether the drain parameters have been reset or not. +static BOOL haveDrainParamsBeenInit[ NUM_OF_DG_RESERVOIRS ]; ///< Boolean flag to indicate whether the drain parameters have been reset or not. // ********** private function prototypes ********** @@ -132,20 +133,20 @@ void initFlushMode( void ) { // Initialize the variables - flushState = DG_FLUSH_STATE_START; - prevFlushState = DG_FLUSH_STATE_START; - flushUIState = FLUSH_UI_STATE_NOT_RUNNING; - rsrvrFillStableTimeCounter = 0; - overallFlushElapsedTimeStart = 0; - isThisInitialDrain = TRUE; - dataPublishCounter = 0; - rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; - rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; - hasWaterCancellationBeenSet = FALSE; - flushLinesVolumeL = 0.0; - haveDrainParamsBeenInit[ DG_RESERVOIR_1 ] = FALSE; - haveDrainParamsBeenInit[ DG_RESERVOIR_2 ] = FALSE; - stateTimerStart = 0; + flushState = DG_FLUSH_STATE_START; + prevFlushState = DG_FLUSH_STATE_START; + flushUIState = FLUSH_UI_STATE_NOT_RUNNING; + rsrvrFillStableTimeCounter = 0; + overallFlushElapsedTimeStart = 0; + isThisInitialDrain = TRUE; + dataPublishCounter = 0; + rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; + rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; + hasWaterCancellationBeenSet = FALSE; + flushLinesVolumeL = 0.0; + haveDrainParamsBeenInit[ DG_RESERVOIR_1 ] = FALSE; + haveDrainParamsBeenInit[ DG_RESERVOIR_2 ] = FALSE; + stateTimerStart = 0; } /*********************************************************************//** @@ -307,15 +308,19 @@ // Close VPi to prevent wasting water setValveState( VPI, VALVE_STATE_CLOSED ); + // Set the actuators to drain R1 setValveState( VRD1, VALVE_STATE_OPEN ); + // Set VPO + setValveState( VPO, VALVE_STATE_FILL_C_TO_NC); + setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); - flushUIState = FLUSH_UI_STATE_DRAIN_DEVICE; + flushUIState = FLUSH_UI_STATE_DRAIN_DEVICE; stateTimerStart = getMSTimerCount(); - rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; - state = DG_FLUSH_STATE_DRAIN_R1; + rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; + state = DG_FLUSH_STATE_DRAIN_R1; return state; } @@ -351,10 +356,12 @@ // Set the actuators to drain R2 // NOTE: Drain pump is already on and VDr is already on drain state setValveState( VRD2, VALVE_STATE_OPEN ); + // Set VPO + setValveState( VPO, VALVE_STATE_FILL_C_TO_NC); stateTimerStart = getMSTimerCount(); - rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; - state = DG_FLUSH_STATE_DRAIN_R2; + rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; + state = DG_FLUSH_STATE_DRAIN_R2; } else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) { @@ -395,6 +402,7 @@ setValveState( VPI, VALVE_STATE_OPEN ); setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VRD2, VALVE_STATE_CLOSED ); + setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); state = DG_FLUSH_STATE_FLUSH_DRAIN; } @@ -514,7 +522,7 @@ rsrvr1Status = DG_RESERVOIR_BELOW_TARGET; rsrvr2Status = DG_RESERVOIR_BELOW_TARGET; flushUIState = FLUSH_UI_STATE_FLUSH_RESERVOIRS; - state = DG_FLUSH_STATE_FLUSH_R1_TO_R2; + state = DG_FLUSH_STATE_FLUSH_R1_TO_R2; } return state; @@ -573,7 +581,7 @@ // Set both reservoirs' status rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; rsrvr2Status = DG_RESERVOIR_BELOW_TARGET; - state = DG_FLUSH_STATE_FLUSH_R2_AND_DRAIN_R1; + state = DG_FLUSH_STATE_FLUSH_R2_AND_DRAIN_R1; } else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) { @@ -637,7 +645,7 @@ // until reservoir 1 is filled up and the tubing might expand or leak. // Before checking whether reservoir 1 is filled pre-maturely, we have to make sure reservoir 1 is drained completely to make // sure the extra volume that is read is not because of previous water that is being drained currently and it is above 500 mL - if ( ( volume > RSRVRS_PARTIAL_FILL_VOL_ML ) && ( 0 == drainPumpRPM ) ) + if ( ( volume >= RSRVRS_PARTIAL_FILL_VOL_ML ) && ( 0 == drainPumpRPM ) ) { prevFlushState = state; alarmDetectedPendingTrigger = ALARM_ID_DG_INVALID_LOAD_CELL_VALUE; @@ -665,12 +673,14 @@ // Close VPi and VPd to drain setValveState(VPI, VALVE_STATE_CLOSED); setValveState(VPD, VALVE_STATE_DRAIN_C_TO_NO); + // Set VPO + setValveState( VPO, VALVE_STATE_FILL_C_TO_NC); stateTimerStart = getMSTimerCount(); isThisInitialDrain = FALSE; rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; flushUIState = FLUSH_UI_STATE_DRAIN_RESERVOIRS; - state = DG_FLUSH_STATE_DRAIN_R1; + state = DG_FLUSH_STATE_DRAIN_R1; } // Check if reservoir 1 fill timed out else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) @@ -877,12 +887,6 @@ // Raise the alarm failFlushMode(); - - // If the caps alarm was active, clear it at the of the cancel water path - if ( TRUE == isAlarmActive( ALARM_ID_DG_DIALYSATE_OR_CONC_CAP_NOT_IN_PROPER_POSITION ) ) - { - clearAlarmCondition( ALARM_ID_DG_DIALYSATE_OR_CONC_CAP_NOT_IN_PROPER_POSITION ); - } } } else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) @@ -956,7 +960,17 @@ status = DG_RESERVOIR_REACHED_TARGET; rsrvrFillStableTimeCounter = 0; // Set the state timer in case it needs to be used for another timeout check - stateTimerStart = getMSTimerCount(); + if ( ( DG_FLUSH_STATE_FLUSH_R2_AND_DRAIN_R1 == flushState) && ( DG_RESERVOIR_2 == r) ) + { + if ( rsrvr1Status == DG_RESERVOIR_REACHED_TARGET ) + { + stateTimerStart = getMSTimerCount(); + } + } + else + { + stateTimerStart = getMSTimerCount(); + } } } else if ( TRUE == didTimeout( stateTimerStart, timeout ) ) @@ -1000,18 +1014,28 @@ if ( TRUE == isDrainComplete ) { - // Set the state timer in case it needs to be used for another timeout check - stateTimerStart = getMSTimerCount(); + if ( ( DG_FLUSH_STATE_FLUSH_R2_AND_DRAIN_R1 == flushState) && ( DG_RESERVOIR_1 == r) ) + { + if ( ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status) && ( 0 == getDrainPumpTargetRPM() ) ) + { + stateTimerStart = getMSTimerCount(); + } + } + else + { + stateTimerStart = getMSTimerCount(); + } + haveDrainParamsBeenInit[ r ] = FALSE; - status = DG_RESERVOIR_REACHED_TARGET; + status = DG_RESERVOIR_REACHED_TARGET; } else if ( TRUE == didTimeout( stateTimerStart, timeout ) ) { // Failed to drain on time - prevFlushState = flushState; - haveDrainParamsBeenInit[ r ] = FALSE; - alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; - status = DG_RESERVOIR_NOT_REACHED_TARGET; + prevFlushState = flushState; + haveDrainParamsBeenInit [ r ] = FALSE; + alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; + status = DG_RESERVOIR_NOT_REACHED_TARGET; } return status; @@ -1066,7 +1090,7 @@ prevFlushState = flushState; flushState = DG_FLUSH_STATE_CANCEL_WATER_PATH; alarmDetectedPendingTrigger = ALARM_ID_DG_DIALYSATE_OR_CONC_CAP_NOT_IN_PROPER_POSITION; - } + } } }