Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r7c73db9d00db93c5374fc0fbbe61117e589e95a2 -rf9570a9717805d0759622da836a33ee04f3fa40f --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 7c73db9d00db93c5374fc0fbbe61117e589e95a2) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision f9570a9717805d0759622da836a33ee04f3fa40f) @@ -40,6 +40,8 @@ #define DIA_FLOW_TO_FILL_FLOW_FIRST_ORDER_COEFF 7.5F ///< Dialysate flow rate to fill flow rate first order coefficient. #define DIA_FLOW_TO_FILL_FLOW_CONSTANT 2.0F ///< Dialysate flow rate to fill flow rate constant. +#define MAX_RESERVOIR_VOL_BEFORE_SWITCH_ML 1900.0F ///< Maximum reservoir volume before we switch reservoirs (in mL). + // ********** private data ********** /// States of the treatment reservoir management state machine. @@ -169,10 +171,8 @@ checkReservoirMaxVolume(); calculateActiveReservoirCycleTime(); - // TODO do we need this? Should we not call the reservoir management exec function in saline bolus? - - // Calculate volume used from active reservoir - do not accumulate if saline bolus is in progress - if ( getSalineBolusState() != SALINE_BOLUS_STATE_IN_PROGRESS ) + // Calculate volume used from active reservoir - do not accumulate if not performing dialysis or saline bolus is in progress + if ( ( TREATMENT_DIALYSIS_STATE == getTreatmentState() ) && ( getDialysisState() != DIALYSIS_SALINE_BOLUS_STATE ) ) { volSpentML += ( flowRateMLPerMS * msSinceLastVolumeCalc ); @@ -523,9 +523,7 @@ timeWaitToFillMS = timeDepleteMS - ( getFillTimeMS() + RESERVOIR_SETTLE_TIME_MS + RESERVOIR_CYCLE_EXTRA_MARGIN_TIME_MS ); // If the wait time has elapsed, trigger a fill command - // TODO uncomment - //if ( timeWaitToFillMS <= 0 ) - // TODO uncomment + if ( timeWaitToFillMS <= 0 ) { cmdStartDGFill( FILL_RESERVOIR_TO_VOLUME_ML, targetFillFlowRateLPM ); } @@ -597,10 +595,16 @@ static TREATMENT_RESERVOIR_MGMT_STATE_T handleReservoirMgmtWaitForFillSettleState( void ) { TREATMENT_RESERVOIR_MGMT_STATE_T state = TREATMENT_RESERVOIR_MGMT_WAIT_FOR_FILL_SETTLE_STATE; + DG_RESERVOIR_ID_T active = getDGActiveReservoir(); + // Get the ultra-filtration volume milliliters + // Get the dilution level in percent = spent ultra-filtration volume / target fill volume in milliliters + volSpentUFML = getReservoirUltrafiltrationVol( activeReservoir ); + dilutionLevelPct = volSpentUFML / (F32)FILL_RESERVOIR_TO_VOLUME_ML; + // Wait for the reservoir to settle and then send the commands to switch the active reservoir TODO - restore #define below if ( ( TRUE == didTimeout( reservoirSwitchStartTimeMS, 15000 /*RESERVOIR_SETTLE_TIME_MS*/ ) ) && - ( ( dilutionLevelPct >= MAX_RESERVOIR_DILUTION ) || ( volSpentML >= (F32)FILL_RESERVOIR_TO_VOLUME_ML ) ) ) + ( ( dilutionLevelPct >= MAX_RESERVOIR_DILUTION ) || ( volSpentML >= (F32)FILL_RESERVOIR_TO_VOLUME_ML ) || ( getReservoirWeight( active ) > MAX_RESERVOIR_VOL_BEFORE_SWITCH_ML ) ) ) { DG_RESERVOIR_ID_T inactiveRes = getDGInactiveReservoir();