Index: firmware/App/Modes/ModePostTreat.c =================================================================== diff -u -r2b79e2d880e3ed9867321835388011726d0a2e52 -r33ea3b3735927186de3e5cf174ad9925c34ba14b --- firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 2b79e2d880e3ed9867321835388011726d0a2e52) +++ firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 33ea3b3735927186de3e5cf174ad9925c34ba14b) @@ -62,11 +62,10 @@ // ********** private data ********** static BOOL patientDisconnectionConfirmed; ///< Flag indicates user confirms patient disconnection. +static bool patientDisconnectHandled; ///< Flag indicates patient disconnect actions have been handled static BOOL disposableRemovalConfirmed; ///< Flag indicates user confirms disposable removal. static BOOL rinseConcentrateLines; ///< FLag indicates to rinse concentrate lines. static BOOL isThisFirstDrain; ///< Flag to indicate whether this is the first time the reservoir is drained. -static BOOL drainDGDePrimeActive; ///< FLag to indicate DePrime DG Dialysate lines active -static U32 drainDGDePrimeStarttime; ///< DG DePrime start time static BOOL dgCommandSent; ///< Flag indicates whether a DG command has been already sent. static HD_POST_TREATMENT_STATE_T currentPostTreatmentState; ///< Current state of post-treatment mode state machine. static DRAIN_STATE_T currentDrainReservoirState; ///< Current drain reservoir state. @@ -103,15 +102,14 @@ void initPostTreatmentMode( void ) { patientDisconnectionConfirmed = FALSE; + patientDisconnectHandled = FALSE; disposableRemovalConfirmed = FALSE; rinseConcentrateLines = FALSE; isThisFirstDrain = TRUE; dgCommandSent = FALSE; currentPostTreatmentState = HD_POST_TREATMENT_DRAIN_RESERVOIRS_STATE; currentDrainReservoirState = DRAIN_DG_DEPRIME_STATE; postTreatmentPublishTimerCounter = 0; - drainDGDePrimeActive = FALSE; - drainDGDePrimeStarttime = 0; // Reset treatment log data memset( &treatmentLogData, 0x0, sizeof( TREATMENT_LOG_DATA_PAYLOAD_T ) ); @@ -353,6 +351,40 @@ /*********************************************************************//** * @brief + * The checkPostTreatmentPatientDisconnect function checks UI patient + * disconnect and handles valve release, pump homing, door requirement. + * @details Inputs: patientDisconnectionConfirmed + * @details Outputs: home pumps, open valves, retract syringe, door closed requirement. + * @return none + *************************************************************************/ +static void checkPostTreatmentPatientDisconnect( void ) +{ + VALVE_T valve; + + if ( ( TRUE == patientDisconnectionConfirmed ) && ( FALSE == patientDisconnectHandled ) ) + { + // home valves and pumps while front door is still closed. + homeBloodPump(); + homeDialInPump(); + homeDialOutPump(); + for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) + { + setValvePosition( valve, VALVE_POSITION_A_INSERT_EJECT ); + } + if ( ( getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ) > 0.0 ) || + ( getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_DISPENSE_RATE ) > 0.0 ) ) + { + retractSyringePump(); + } + doorClosedRequired( FALSE, FALSE ); + // NOTE: patientDisconnectionConfirmed is NOT reset because + // Patient Disconnect State needs it to move to next state + patientDisconnectHandled = TRUE; + } +} + +/*********************************************************************//** + * @brief * The handlePostTreatmentDrainReservoirsState function executes drain reservoirs * operation state machine and transition to next state once completed. * @details Inputs: currentDrainReservoirState @@ -369,9 +401,9 @@ { // Done with draining the reservoirs state = HD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE; - doorClosedRequired( FALSE, FALSE ); setCurrentSubState( NO_SUB_STATE ); } + checkPostTreatmentPatientDisconnect(); return state; } @@ -392,6 +424,7 @@ if ( ( STATE_CLOSED == frontDoor ) && ( STATE_CLOSED == pumpTrack ) ) { + checkPostTreatmentPatientDisconnect(); #ifndef _RELEASE_ if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_UI_INTERACTION ) ) { @@ -402,6 +435,7 @@ if ( TRUE == patientDisconnectionConfirmed ) { patientDisconnectionConfirmed = FALSE; + patientDisconnectHandled = FALSE; state = HD_POST_TREATMENT_DISPOSABLE_REMOVAL_STATE; } } @@ -541,8 +575,8 @@ * The handleDrainDePrimeDGDialysateLinesState function de-primes the return * dialysate line so that it will not leak when user disconnects the line * from the DG. - * @details Inputs: drainDGDePrimeActive - * @details Outputs: drainDGDePrimeActive + * @details Inputs: none + * @details Outputs: none * @return next state *************************************************************************/ static DRAIN_STATE_T handleDrainDePrimeDGDialysateLinesState( void ) @@ -551,44 +585,13 @@ if ( ( ( DG_MODE_GENE == getDGOpMode() ) && ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == getDGSubMode() ) ) || ( DG_MODE_FAUL == getDGOpMode() ) ) { - if ( FALSE == drainDGDePrimeActive ) + if ( getDGOpMode() != DG_MODE_FAUL ) { - // First entry - Run DPi slow reverse, VDi, VDo closed in init, DPo Off in init. - setDialInPumpTargetFlowRate( DIP_DRAIN_DG_FLOW_RATE_ML_MIN, MOTOR_DIR_REVERSE, PUMP_CONTROL_MODE_OPEN_LOOP ); - drainDGDePrimeStarttime = getMSTimerCount(); - drainDGDePrimeActive = TRUE; + state = DRAIN_RESERVOIR_SWITCH_STATE; } - } - if ( TRUE == drainDGDePrimeActive ) - { - // Thereafter, check for time elapsed - if ( TRUE == didTimeout( drainDGDePrimeStarttime, DIP_DRAIN_DG_RUNTIME_MS ) ) + else { - VALVE_T valve; - - drainDGDePrimeActive = FALSE; - signalDialInPumpHardStop( ); - if ( getDGOpMode() != DG_MODE_FAUL ) - { - state = DRAIN_RESERVOIR_SWITCH_STATE; - } - else - { - state = DRAIN_RESERVOIR_COMPLETE_STATE; - } - // home valves and pumps while front door is still closed. - homeBloodPump(); - homeDialInPump(); - homeDialOutPump(); - for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) - { - setValvePosition( valve, VALVE_POSITION_A_INSERT_EJECT ); - } - if ( ( getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ) > 0.0 ) || - ( getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_DISPENSE_RATE ) > 0.0 ) ) - { - retractSyringePump(); - } + state = DRAIN_RESERVOIR_COMPLETE_STATE; } }