Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -rc68065fe2cfcfee46eae9d8a8af68b42b662661c -r130d76b56808975e8ba467a483bdb3a2e9899691 --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision c68065fe2cfcfee46eae9d8a8af68b42b662661c) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 130d76b56808975e8ba467a483bdb3a2e9899691) @@ -1095,6 +1095,9 @@ S32 timeDiff = 0; F32 rateDiff = 0.0; HD_OP_MODE_T currMode = getCurrentOperationMode(); + S32 txSecRem = CALC_TREAT_TIME_REMAINING_IN_SECS(); + S32 txMinEla = CALC_ELAPSED_TREAT_TIME_IN_SECS() / SEC_PER_MIN; + F32 txMinRem = (F32)txSecRem / (F32)SEC_PER_MIN; // Reset pending UF/time settings changes to current values in case request is rejected pendingUFVolumeChange = presMaxUFVolumeML; @@ -1109,9 +1112,12 @@ { DIALYSIS_STATE_T currDialysisState = getDialysisState(); UF_STATE_T currUFState = getUltrafiltrationState(); - F32 uFRate = uFVolume / ((F32)presTreatmentTimeSecs / (F32)SEC_PER_MIN); // What UF rate would be if user selected to adjust it - U32 trtTime = (S32)( uFVolume / presUFRate ) + 1; // What the treatment duration would be if user selected to adjust it - U32 dialVolume = getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ) * trtTime; // What dialysate volume would be if user selected to adjust time + F32 colUFVol = getUltrafiltrationReferenceVolume(); // How much UF volume have we taken so far? + F32 remUFVol = uFVolume - colUFVol; // What would remaining UF volume be after subtracting UF volume already taken + F32 remUFVolCap = RANGE( remUFVol, 0.0F, (F32)MAX_UF_VOLUME_ML ); // Enforce valid range on remaining UF volume + F32 uFRate = remUFVolCap / txMinRem; // What UF rate would be if user selected to adjust it + U32 trtTime = ( fabs( presUFRate ) < NEARLY_ZERO ? txMinEla + 1 : (S32)( remUFVolCap / presUFRate ) + txMinEla + 1 ); // What the treatment duration would be if user selected to adjust it + U32 dialVolume = getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ) * trtTime; // What dialysate volume would be if user selected to adjust time // UF should already be paused but let's make sure. if ( ( TREATMENT_DIALYSIS_STATE == currentTreatmentState ) &&