Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -r40e0116bbada6d1780bfa832a9c4684ba9fcfcc8 -r44a100f8e5210a02c23b8fcc4527d8e96d577381 --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 40e0116bbada6d1780bfa832a9c4684ba9fcfcc8) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 44a100f8e5210a02c23b8fcc4527d8e96d577381) @@ -62,6 +62,8 @@ static F32 measUFVolume; ///< Current total measured volume for ultrafiltration (Where are we w/r/t ultrafiltration). static F32 resStartVolume[ NUM_OF_DG_RESERVOIRS ]; ///< Reservoir start volume for ultrafiltration (i.e. where did we start with each reservoir). static F32 resFinalVolume[ NUM_OF_DG_RESERVOIRS ]; ///< Reservoir final volume for ultrafiltration (i.e. where did we end after switch with each reservoir). +static F32 resCurrVolume[ NUM_OF_DG_RESERVOIRS ]; ///< Reservoir current volume. +static F32 resLastVolume[ NUM_OF_DG_RESERVOIRS ]; ///< Reservoir previous volume. static F32 measUFVolumeFromPriorReservoirs; ///< Current total ultrafiltration volume from previous reservoirs in current treatment. static U32 uFTimeMS; ///< Current elapsed ultrafiltration time (in ms). Used for calculating UF reference volume. @@ -75,7 +77,7 @@ static U32 salineBolusBroadcastTimerCtr; ///< Saline bolus data broadcast timer counter used to schedule when to transmit data. static BOOL salineBolusStartRequested; ///< Flag indicates a saline bolus start has been requested by user. static BOOL salineBolusAbortRequested; ///< Flag indicates a salien bolus abort has been requested by user. -static BOOL salineBolusAutoResumeUF; ///< Flag indicates UF should be auto-resumed after saline bolus completes. +static BOOL salineBolusAutoResumeUF = FALSE; ///< Flag indicates UF should be auto-resumed after saline bolus completes. static F32 totalSalineVolumeDelivered; ///< Volume (mL) in total of saline delivered so far (cumulative for all boluses including current one). static F32 bolusSalineVolumeDelivered; ///< Volume (mL) of current bolus delivered so far. static F32 bolusSalineVolumeDelivered_Safety; ///< Volume (mL) of current bolus delivered so far according to safety monitor. @@ -125,6 +127,8 @@ refUFVolume = 0.0; measUFVolume = 0.0; measUFVolumeFromPriorReservoirs = 0.0; + // Send reset UF volumes to dialysate outlet pump + setDialOutUFVolumes( refUFVolume, measUFVolume ); uFTimeMS = 0; lastUFTimeStamp = 0; @@ -156,14 +160,18 @@ { salineBolusStartRequested = FALSE; salineBolusAbortRequested = FALSE; - salineBolusAutoResumeUF = FALSE; bolusSalineVolumeDelivered = 0.0; bolusSalineVolumeDelivered_Safety = 0.0; bolusSalineMotorCount = 0; if ( currentSalineBolusState != SALINE_BOLUS_STATE_MAX_DELIVERED ) { currentSalineBolusState = SALINE_BOLUS_STATE_IDLE; } + if ( TRUE == salineBolusAutoResumeUF ) + { + salineBolusAutoResumeUF = FALSE; + currentUFState = UF_RUNNING_STATE; + } } /*********************************************************************//** @@ -226,12 +234,12 @@ { HEPARIN_STATE_T currentHeparinState = getHeparinState(); U32 preStop = getTreatmentParameterU32( TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME ); - U32 minRem = getTreatmentTimeRemainingSecs() / SEC_PER_MIN; + F32 minRem = (F32)getTreatmentTimeRemainingSecs() / (F32)SEC_PER_MIN; F32 bolusVol = getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ); F32 hepRate = getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_DISPENSE_RATE ); // Do not run syringe pump if no Heparin included in prescription or it was paused or if Heparin should be stopped at this stage of treatment - if ( ( minRem > preStop ) && ( HEPARIN_STATE_STOPPED == currentHeparinState ) ) + if ( ( minRem > (F32)preStop ) && ( HEPARIN_STATE_STOPPED == currentHeparinState ) ) { // If not done with bolus, start/resume bolus if ( ( bolusVol > 0.0 ) && ( getSyringePumpVolumeDelivered() < bolusVol ) ) @@ -241,7 +249,14 @@ // Otherwise, start/resume continuous delivery else { - startHeparinContinuous(); // TODO - check return status + if ( hepRate > 0.0 ) + { + startHeparinContinuous(); // TODO - check return status + } + else + { + setHeparinCompleted(); + } } } else @@ -329,14 +344,14 @@ { rejReason = REQUEST_REJECT_REASON_INVALID_TREATMENT_STATE; } - else if ( currSalineBolusState != SALINE_BOLUS_STATE_IDLE ) - { - rejReason = REQUEST_REJECT_REASON_SALINE_BOLUS_IN_PROGRESS; - } else if ( totalSalineVolumeDelivered >= (F32)MAX_SALINE_VOLUME_DELIVERED ) { rejReason = REQUEST_REJECT_REASON_SALINE_MAX_VOLUME_REACHED; } + else if ( currSalineBolusState != SALINE_BOLUS_STATE_IDLE ) + { + rejReason = REQUEST_REJECT_REASON_SALINE_BOLUS_IN_PROGRESS; + } else { accept = TRUE; @@ -612,10 +627,10 @@ { DIALYSIS_STATE_T result = DIALYSIS_UF_STATE; U32 preStop = getTreatmentParameterU32( TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME ); - U32 minRem = getTreatmentTimeRemainingSecs() / SEC_PER_MIN; + F32 minRem = (F32)getTreatmentTimeRemainingSecs() / (F32)SEC_PER_MIN; // Stop Heparin delivery if we have reached Heparin pre-stop point - if ( getTreatmentTimeRemainingSecs() < preStop ) + if ( minRem <= (F32)preStop ) { stopSyringePump(); setHeparinCompleted(); @@ -1063,7 +1078,7 @@ LOAD_CELL_ID_T loadCell = ( activeRes == DG_RESERVOIR_1 ? LOAD_CELL_RESERVOIR_1_PRIMARY : LOAD_CELL_RESERVOIR_2_PRIMARY ); F32 latestResVolume = getLoadCellWeight( loadCell ); #ifndef DISABLE_UF_ALARMS - F32 deltaVolume = latestResVolume - resFinalVolume[ activeRes ]; + F32 deltaVolume = latestResVolume - resLastVolume[ activeRes ]; // ensure volume change is not too excessive - indication that load cell was impacted by some kind of shock if ( fabs(deltaVolume) > MAX_ACTIVE_LOAD_CELL_CHANGE_G ) @@ -1137,4 +1152,22 @@ measUFVolumeFromPriorReservoirs += ( resFinalVolume[ inactiveRes ] - resStartVolume[ inactiveRes ] ); } +/*********************************************************************//** + * @brief + * The updateReservoirVolumes function updates the reservoir volumes based + * on new load cell readings. + * @details Inputs: none + * @details Outputs: resCurrVolume[], resLastVolume[] + * @param res1Vol new volume for reservoir 1 + * @param res2Vol new volume for reservoir 2 + * @return none + *************************************************************************/ +void updateReservoirVolumes( F32 res1Vol, F32 res2Vol ) +{ + resLastVolume[ DG_RESERVOIR_1 ] = resCurrVolume[ DG_RESERVOIR_1 ]; + resLastVolume[ DG_RESERVOIR_2 ] = resCurrVolume[ DG_RESERVOIR_2 ]; + resCurrVolume[ DG_RESERVOIR_1 ] = res1Vol; + resCurrVolume[ DG_RESERVOIR_2 ] = res2Vol; +} + /**@}*/