Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -r9df8618dfd95d3af354e6cbb590ebe6f6fd7ccdd -rbb114842e73659f097bb8b8ec0d670bfa4f8cb73 --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 9df8618dfd95d3af354e6cbb590ebe6f6fd7ccdd) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision bb114842e73659f097bb8b8ec0d670bfa4f8cb73) @@ -20,7 +20,6 @@ #include "AirTrap.h" #include "BloodFlow.h" #include "Buttons.h" -#include "DGInterface.h" #include "Dialysis.h" #include "DialInFlow.h" #include "DialOutFlow.h" @@ -53,6 +52,8 @@ #define MIN_SALINE_BOLUS_VOLUME_PCT 0.8 ///< Minimum saline bolus volume measured by independent means (as % of target). #define MAX_SALINE_BOLUS_VOLUME_PCT 1.2 ///< Maximum saline bolus volume measured by independent means (as % of target). +#define MAX_ACTIVE_LOAD_CELL_CHANGE_G 50.0 ///< Maximum delta between new and previous measured UF volume. + // ********** private data ********** static DIALYSIS_STATE_T currentDialysisState; ///< Current state of the dialysis sub-mode state machine. @@ -96,8 +97,6 @@ static UF_STATE_T handleUFStartState( DIALYSIS_STATE_T *dialysisState ); static UF_STATE_T handleUFPausedState( DIALYSIS_STATE_T *dialysisState ); static UF_STATE_T handleUFRunningState( DIALYSIS_STATE_T *dialysisState ); -static UF_STATE_T handleUFOffState( DIALYSIS_STATE_T *dialysisState ); -static UF_STATE_T handleUFCompletedState( DIALYSIS_STATE_T *dialysisState ); static SALINE_BOLUS_STATE_T handleSalineBolusIdleState( DIALYSIS_STATE_T *dialysisState ); static SALINE_BOLUS_STATE_T handleSalineBolusWait4Pumps2Stop( DIALYSIS_STATE_T *dialysisState ); @@ -126,8 +125,6 @@ refUFVolume = 0.0; measUFVolume = 0.0; - resFinalVolume[ DG_RESERVOIR_1 ] = 0.0; - resFinalVolume[ DG_RESERVOIR_2 ] = 0.0; measUFVolumeFromPriorReservoirs = 0.0; uFTimeMS = 0; @@ -578,17 +575,9 @@ currentUFState = handleUFRunningState( &result ); break; - case UF_OFF_STATE: - currentUFState = handleUFOffState( &result ); - break; - - case UF_COMPLETED_STATE: - currentUFState = handleUFCompletedState( &result ); - break; - default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_DIALYSIS_INVALID_UF_STATE, currentUFState ) - currentUFState = UF_COMPLETED_STATE; + currentUFState = UF_PAUSED_STATE; break; } @@ -648,16 +637,9 @@ { UF_STATE_T result; - if ( maxUFVolumeML < NEARLY_ZERO ) - { - result = UF_OFF_STATE; - } - else - { - lastUFTimeStamp = getMSTimerCount(); - uFTimeMS = 0; - result = UF_RUNNING_STATE; - } + lastUFTimeStamp = getMSTimerCount(); + uFTimeMS = 0; + result = UF_RUNNING_STATE; return result; } @@ -736,42 +718,9 @@ // If we have reached target UF volume, UF is complete if ( measUFVolume >= maxUFVolumeML ) { - result = UF_COMPLETED_STATE; + setUFRate = 0.0; } - // Handle saline bolus start request from user - else if ( TRUE == salineBolusStartRequested ) - { - if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) - { - // Since we were doing UF prior to saline bolus, we want to auto-resume when done - salineBolusAutoResumeUF = TRUE; - // Go to UF paused state - result = UF_PAUSED_STATE; - // Go to saline bolus state - *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; - } - else - { - salineBolusStartRequested = FALSE; - } - } - return result; -} - -/*********************************************************************//** - * @brief - * The handleUFCompletedOrOffState function handles the UF Off state - * of the ultrafiltration state machine. - * @details Inputs: none - * @details Outputs: UF volumes updated and provided to DPo pump controller. - * @param dialysisState next dialysis state - * @return next ultrafiltration state - *************************************************************************/ -static UF_STATE_T handleUFOffState( DIALYSIS_STATE_T *dialysisState ) -{ - UF_STATE_T result = UF_OFF_STATE; - // Calculate UF volumes and provide to dialysate outlet pump controller updateUFVolumes(); @@ -795,40 +744,6 @@ /*********************************************************************//** * @brief - * The handleUFCompletedState function handles the UF Completed - * state of the ultrafiltration state machine. This is a terminal state. - * @details Inputs: none - * @details Outputs: UF volumes updated and provided to DPo pump controller. - * @param dialysisState next dialysis state - * @return next ultrafiltration state - *************************************************************************/ -static UF_STATE_T handleUFCompletedState( DIALYSIS_STATE_T *dialysisState ) -{ - UF_STATE_T result = UF_COMPLETED_STATE; - - // Calculate UF volumes and provide to dialysate outlet pump controller - updateUFVolumes(); - - // Handle saline bolus start request from user - if ( TRUE == salineBolusStartRequested ) - { - salineBolusAutoResumeUF = FALSE; - // Go to saline bolus state - if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) - { - *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; - } - else - { - salineBolusStartRequested = FALSE; - } - } - - return result; -} - -/*********************************************************************//** - * @brief * The handleSalineBolusIdleState function handles the idle state of the * saline bolus state machine. * @details Inputs: none @@ -1105,11 +1020,23 @@ { DG_RESERVOIR_ID_T activeRes = getDGActiveReservoir(); F32 latestResVolume = getReservoirWeightSmallFilter( activeRes ); +#ifndef DISABLE_UF_ALARMS + F32 deltaVolume = latestResVolume - resFinalVolume[ activeRes ]; - // Calculate UF volumes and provide to dialysate outlet pump controller - measUFVolume = measUFVolumeFromPriorReservoirs + ( latestResVolume - resStartVolume[ activeRes ] ); - resFinalVolume[ activeRes ] = latestResVolume; - setDialOutUFVolumes( refUFVolume, measUFVolume ); + // 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 ) + { + ALARM_ID_T deltaAlarm = ( getDGActiveReservoir() == DG_RESERVOIR_1 ? ALARM_ID_HD_LOAD_CELL_ACCELERATION_RES_1_ALARM : ALARM_ID_HD_LOAD_CELL_ACCELERATION_RES_2_ALARM ); + SET_ALARM_WITH_1_F32_DATA( deltaAlarm, deltaVolume ); + } + else +#endif + { + // Calculate UF volumes and provide to dialysate outlet pump controller + measUFVolume = measUFVolumeFromPriorReservoirs + ( latestResVolume - resStartVolume[ activeRes ] ); + resFinalVolume[ activeRes ] = latestResVolume; + setDialOutUFVolumes( refUFVolume, measUFVolume ); + } } /*********************************************************************//** @@ -1119,15 +1046,16 @@ * is the inactive reservoir) in order to get a more stable volume. * @details Inputs: active reservoir, load cell reading from inactive reservoir * @details Outputs: resStartVolume[] + * @param reservoirID reservoir ID to update the baseline volume. * @return none *************************************************************************/ -void setStartReservoirVolume( void ) +void setStartReservoirVolume( DG_RESERVOIR_ID_T reservoirID ) { - DG_RESERVOIR_ID_T inactiveRes = getDGInactiveReservoir(); - F32 resVolume = getReservoirWeightLargeFilter( inactiveRes ); + F32 resVolume = getReservoirWeightLargeFilter( reservoirID ); // Set starting baseline volume for next reservoir before we switch to it - resStartVolume[ inactiveRes ] = resVolume; + resStartVolume[ reservoirID ] = resVolume; + resFinalVolume[ reservoirID ] = resVolume; } /*********************************************************************//** @@ -1141,8 +1069,7 @@ *************************************************************************/ void signalReservoirsSwitched( void ) { - DG_RESERVOIR_ID_T activeRes = getDGActiveReservoir(); - DG_RESERVOIR_ID_T inactiveRes = ( activeRes == DG_RESERVOIR_1 ? DG_RESERVOIR_2 : DG_RESERVOIR_1 ); + DG_RESERVOIR_ID_T inactiveRes = getDGInactiveReservoir(); // Update UF volume from prior reservoirs per tentative res volume for last reservoir measUFVolumeFromPriorReservoirs += ( resFinalVolume[ inactiveRes ] - resStartVolume[ inactiveRes ] );