Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r8ceb25eb60c36ccd2d6ff305cb389c5128d6317a -r4889578e404c34d4c1de51bd6a1155d4710d6d25 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 8ceb25eb60c36ccd2d6ff305cb389c5128d6317a) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 4889578e404c34d4c1de51bd6a1155d4710d6d25) @@ -322,7 +322,7 @@ F32 totalTargetFillFlow = targetFillFlowRate + ( targetFillFlowRate * ratios.acidMixingRatio ) + ( targetFillFlowRate * ratios.bicarbMixingRatio ); // Time fill = Fill volume / Qfill. Qfill is converted from L/min to mL/min and the time is converted from minutes to milliseconds - U32 timeFillMS = ( prevTargetFillVolumeML[ getDGActiveReservoir() ] / ( ML_PER_LITER * totalTargetFillFlow ) ) * SEC_PER_MIN * MS_PER_SECOND; + U32 timeFillMS = ( getTargetFillVolumeBasedOnDialysateFlowML() / ( ML_PER_LITER * totalTargetFillFlow ) ) * SEC_PER_MIN * MS_PER_SECOND; // Add the prepare time in the DG mode fill to the calculated fill time in milliseconds U32 timeTotalFillMS = timeFillMS + ratios.timeFillPrepMS; @@ -525,16 +525,17 @@ // Get the target fill flow rate in L/min F32 targetFillFlowRateLPM = getTargetFillFlowRateLPM(); DG_RESERVOIR_ID_T inactiveRsrvr = getDGInactiveReservoir(); + DG_RESERVOIR_ID_T activeRsrvr = 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)prevTargetFillVolumeML[ getDGActiveReservoir() ]; + dilutionLevelPct = volSpentUFML / (F32)prevTargetFillVolumeML[ activeRsrvr ]; // Check if the dilution level has exceeded the limit or the spent volume is more than the amount of volume in the reservoir // If it has, trigger the fill command. This if should not happen and the predictive dilution level should trigger just in time // in advance - if ( ( dilutionLevelPct >= MAX_RESERVOIR_DILUTION ) || ( volSpentML >= (F32)prevTargetFillVolumeML[ getDGActiveReservoir() ] ) ) + if ( ( dilutionLevelPct >= MAX_RESERVOIR_DILUTION ) || ( volSpentML >= (F32)prevTargetFillVolumeML[ activeRsrvr ] ) ) { if ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == dgSubMode ) { @@ -633,20 +634,19 @@ // 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)prevTargetFillVolumeML[ inactiveRsrvr ]; + dilutionLevelPct = volSpentUFML / (F32)prevTargetFillVolumeML[ active ]; // Wait for the reservoir to settle and then send the commands to switch the active reservoir if ( ( TRUE == didTimeout( reservoirSwitchStartTimeMS, RESERVOIR_FRESH_SETTLE_TIME_MS ) ) && ( ( dilutionLevelPct >= MAX_RESERVOIR_DILUTION ) || ( volSpentML >= (F32)getTargetFillVolumeBasedOnDialysateFlowML() ) || ( TRUE == isDialysateTempAlarmActive() ) ) ) { DG_SWITCH_RSRVRS_CMD_T rsrvrCmd; - DG_RESERVOIR_ID_T inactiveRes = getDGInactiveReservoir(); - rsrvrCmd.reservoirID = (U32)inactiveRes; + rsrvrCmd.reservoirID = (U32)inactiveRsrvr; rsrvrCmd.useLastTrimmerHeaterDC = TRUE; // Signal dialysis sub-mode to capture baseline volume for next reservoir. - setStartReservoirVolume( inactiveRes ); + setStartReservoirVolume( inactiveRsrvr ); // Command DG to switch reservoirs cmdSetDGActiveReservoir( &rsrvrCmd );