Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r4d1a8ff389678d2f9a0bde6effba32d8c4ac5fb1 -ra89d6b091874136d75a9bfbdbbc1ff00f42467b3 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 4d1a8ff389678d2f9a0bde6effba32d8c4ac5fb1) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision a89d6b091874136d75a9bfbdbbc1ff00f42467b3) @@ -8,7 +8,7 @@ * @file ModeDrain.c * * @author (last) Dara Navaei -* @date (last) 01-Jan-2022 +* @date (last) 13-Jun-2022 * * @author (original) Leonardo Baloa * @date (original) 20-Dec-2019 @@ -19,6 +19,7 @@ #include "ConductivitySensors.h" #include "DrainPump.h" #include "Heaters.h" +#include "ModeFill.h" #include "ModeDrain.h" #include "OperationModes.h" #include "Pressures.h" @@ -37,30 +38,34 @@ // ********** private definitions ********** -#define TARGET_DRAIN_PUMP_RPM 2300 ///< 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 TARGET_DRAIN_PUMP_RPM 2400 ///< 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_EMPTY_TARE_WAIT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) /// Time period to wait after drain complete and before taring load cells. +#define DRAIN_EMPTY_TARE_WAIT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) /// 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. +#define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. +#define TARGET_RO_FLOW_RATE_L 0.3F ///< Target flow rate for RO pump. -#define DELAY_RES_DRAIN_VALVE_MS 1000 ///< Delay reservoir drain valve open by 1 second. -#define DELAY_DRAIN_PUMP_MS 2000 ///< Delay drain pump on by 2 seconds. +#define DELAY_RES_DRAIN_VALVE_MS 1000 ///< Delay reservoir drain valve open by 1 second. +#define DELAY_DRAIN_PUMP_MS 2000 ///< Delay drain pump on by 2 seconds. -#define DIALYSATE_DRAIN_TIME_OUT ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Dialysate drain time out. +#define DIALYSATE_DRAIN_TIME_OUT ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Dialysate drain time out. -#define RINSE_CONCENTRATE_LINES_WAIT ( 25 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Time period to wait for concentrate lines to rinse. +#define RINSE_CONCENTRATE_LINES_WAIT ( 25 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Time period to wait for concentrate lines to rinse. -#define RINSE_SPEED ( ( CONCENTRATE_PUMP_MAX_SPEED - 3.0 ) * -1.0 ) ///< Reserver the concentrate speed to rinse out concentrate lines. +#define RINSE_SPEED ( ( CONCENTRATE_PUMP_MAX_SPEED - 3.0F ) * -1.0F ) ///< Reserver the concentrate speed to rinse out concentrate lines. +#define ACID_CONCENTRATION_BOTTLE_VOLUME_ML 3430.0F ///< Bottle volume of acid concentration in mL. +#define BICARB_CONCENTRATION_BOTTLE_VOLUME_ML 3780.0F ///< Bottle volume of bicarb concentration in mL. +#define CONCENTRATION_BOTTLE_LOW_VOLUME_ML 100.0F ///< Concentration bottle low volume in mL. + // ********** private data ********** -static DG_DRAIN_STATE_T drainState; ///< Currently active drain state. -static U32 drainEmptyTareTimerCtr; ///< Timer counter for delay between drain complete and load cell tare. -static BOOL rinseConcentrateLines; ///< Flag indicates to rinse concentrate lines. -static U32 rinseConcentrateLinesTimerCtr; ///< Timer counter for rinsing concentrate lines. -static U32 dialysateDrainStartTime; ///< Dialysate drain start time. +static DG_DRAIN_STATE_T drainState; ///< Currently active drain state. +static U32 drainEmptyTareTimerCtr; ///< Timer counter for delay between drain complete and load cell tare. +static BOOL rinseConcentrateLines; ///< Flag indicates to rinse concentrate lines. +static U32 rinseConcentrateLinesTimerCtr; ///< Timer counter for rinsing concentrate lines. +static U32 dialysateDrainStartTime; ///< Dialysate drain start time. // ********** private function prototypes ********** static DG_DRAIN_STATE_T handleDrainStateStart( void ); @@ -73,14 +78,15 @@ * The initDrainMode function initializes the drain mode module. * @details Inputs: none * @details Outputs: drainState, drainEmptyTareTimerCtr, dialysateDrainStartTime, - * rinseConcentrateLines, rinseConcentrateLinesTimerCtr + * rinseConcentrateLinesTimerCtr * @return none *************************************************************************/ void initDrainMode( void ) { + // NOTE: rinseConcentrateLines should not be initialized here. This variable is set by the caller when a drain command is requested. + // The caller will specify whether to set the rinse lines or not. drainState = DG_DRAIN_STATE_START; drainEmptyTareTimerCtr = 0; - rinseConcentrateLines = FALSE; rinseConcentrateLinesTimerCtr = 0; dialysateDrainStartTime = 0; } @@ -117,9 +123,7 @@ // NOTE: The target flow rate should be set prior to setting the start primary heater // because the initial guess in the heaters driver needs the target flow to calculate // the new PWMs for the main and small primary heaters -#ifndef DISABLE_FLOW_CONTROL_TREATMENT setROPumpTargetFlowRateLPM( TARGET_RO_FLOW_RATE_L, TARGET_RO_PRESSURE_PSI ); -#endif setHeaterTargetTemperature( DG_PRIMARY_HEATER, getPrimaryHeaterTargetTemperature() ); startHeater( DG_PRIMARY_HEATER ); @@ -138,7 +142,7 @@ // check inlet water conductivity, temperature, pressure, and RO rejection ratio checkInletWaterConductivity(); checkInletWaterTemperature(); - checkInletPressure(); + checkInletWaterPressure(); checkRORejectionRatio(); // execute current drain state @@ -225,7 +229,7 @@ *************************************************************************/ static DG_DRAIN_STATE_T handleDrainStateDrain( void ) { - DG_DRAIN_STATE_T result = DG_DRAIN_STATE_DRAIN; + DG_DRAIN_STATE_T result = DG_DRAIN_STATE_DRAIN; DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); // if we have reached our target drain to volume (by weight) or cannot drain anymore, we are done draining - go back to generation idle mode @@ -242,6 +246,26 @@ setValveState( VRD2, VALVE_STATE_CLOSED ); } +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_EMPTY_BOTTLES_ALARM ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + // Detect empty bottles using integrated volumes + if ( ( ACID_CONCENTRATION_BOTTLE_VOLUME_ML - getChemicalUsedVolumeML( ACID ) ) <= CONCENTRATION_BOTTLE_LOW_VOLUME_ML ) // || // SRSDG 437 + { + resetChemicalUsedVolumeML( ACID ); + setThisFisrtFillFlag( TRUE ); // indicates bottles need prime + activateAlarmNoData( ALARM_ID_DG_ACID_BOTTLE_LOW_VOLUME ); + } + + if ( ( BICARB_CONCENTRATION_BOTTLE_VOLUME_ML - getChemicalUsedVolumeML( BICARB ) ) <= CONCENTRATION_BOTTLE_LOW_VOLUME_ML ) // || // SRSDG 438 + { + resetChemicalUsedVolumeML( BICARB ); + setThisFisrtFillFlag( TRUE ); + activateAlarmNoData( ALARM_ID_DG_BICARB_BOTTLE_LOW_VOLUME ); + } + } + if ( TRUE == isReservoirTarePending() ) { // Tare reservoir load cells at empty if requested result = DG_DRAIN_STATE_TARE; @@ -251,9 +275,7 @@ requestNewOperationMode( DG_MODE_GENE ); } } - - // Drain timed out raise the alarm - if ( TRUE == didTimeout( dialysateDrainStartTime, DIALYSATE_DRAIN_TIME_OUT ) ) + else if ( TRUE == didTimeout( dialysateDrainStartTime, DIALYSATE_DRAIN_TIME_OUT ) ) // Drain timed out raise the alarm { activateAlarmNoData( ALARM_ID_DG_DIALYSATE_DRAIN_TIME_OUT ); } @@ -289,7 +311,7 @@ requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); } - rinseConcentrateLinesTimerCtr = 0; + result = DG_DRAIN_STATE_RINSE; }