Index: firmware/App/Modes/TreatmentStop.c =================================================================== diff -u -r0a4dcd288d4347b85baaa0b07da568b6add5eac7 -r75e1ae332d1446dddf9b8d4ce6e8317449c57d67 --- firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 0a4dcd288d4347b85baaa0b07da568b6add5eac7) +++ firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 75e1ae332d1446dddf9b8d4ce6e8317449c57d67) @@ -7,8 +7,8 @@ * * @file TreatmentStop.c * -* @author (last) Dara Navaei -* @date (last) 10-Aug-2022 +* @author (last) Michael Garthwaite +* @date (last) 19-Jan-2023 * * @author (original) Sean * @date (original) 15-Jan-2020 @@ -37,8 +37,6 @@ /// Treatment stop status broadcast interval. #define TREATMENT_STOP_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) -/// Target flow rate for re-circulation of saline on blood-side circuit. -#define RECIRC_BP_FLOW_RATE_ML_MIN 100 // ********** private data ********** @@ -71,7 +69,7 @@ *************************************************************************/ void initTreatmentStop( void ) { - currentTxStopState = TREATMENT_STOP_RECIRC_STATE; + currentTxStopState = TREATMENT_STOP_RECIRC_STATE; // Assume blood and dialysate will recirculate initially - will stop pump(s) as appropriate in state machine bloodSittingTimerCtr = 0; stopPublishTimerCtr = TREATMENT_STOP_DATA_PUBLISH_INTERVAL; } @@ -102,9 +100,6 @@ setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, TRUE ); - // Ensure syringe pump is stopped - stopSyringePump(); - // Set Dialysate valves to bypass filter for recirculation setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); @@ -160,12 +155,23 @@ *************************************************************************/ static void setupForBloodRecirculationState( void ) { + PUMP_CONTROL_MODE_T mode = PUMP_CONTROL_MODE_CLOSED_LOOP; + +#ifndef _RELEASE_ + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_BLOOD_PUMP_OPEN_LOOP ) ) + { + mode = PUMP_CONTROL_MODE_OPEN_LOOP; + } +#endif + doorClosedRequired( TRUE, TRUE ); // Open VBA and VBV valves to patient for blood recirculation setValvePosition( VBA, VALVE_POSITION_B_OPEN ); setValvePosition( VBV, VALVE_POSITION_B_OPEN ); - // Start blood pump at re-circulate flow rate - setBloodPumpTargetFlowRate( RECIRC_BP_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + // Start blood pump at prescribed flow rate + setBloodPumpTargetFlowRate( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ), MOTOR_DIR_FORWARD, mode ); + // Start Heparin pump as appropriate + startHeparinPump(); // Start air trap leveling control startAirTrapControl(); // Reset blood sitting timer, it is now circulating @@ -201,6 +207,8 @@ { // Stop blood pump signalBloodPumpHardStop(); + // Stop syringe pump + stopSyringePump(); // Close arterial and venous lines setValvePosition( VBA, VALVE_POSITION_C_CLOSE ); setValvePosition( VBV, VALVE_POSITION_C_CLOSE ); @@ -218,6 +226,8 @@ *************************************************************************/ void execTreatmentStop( void ) { + TREATMENT_STOP_STATE_T priorSubState = currentTxStopState; + // Execute treatment stop sub-mode state machine switch ( currentTxStopState ) { @@ -242,6 +252,10 @@ break; } + if ( priorSubState != currentTxStopState ) + { + SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_SUB_STATE_CHANGE, priorSubState, currentTxStopState ); + } // Broadcast treatment stop status publishTreatmentStopData(); } @@ -261,36 +275,34 @@ BOOL dialysateRecircBlocked = isDialysateRecircBlocked(); // Both unblocked and not in recirculate both state - if ( (TREATMENT_STOP_RECIRC_STATE != state) && ( FALSE == dialysateRecircBlocked ) - && ( FALSE == bloodRecircBlocked ) ) + if ( ( TREATMENT_STOP_RECIRC_STATE != state ) && ( FALSE == dialysateRecircBlocked ) && ( FALSE == bloodRecircBlocked ) ) { setupForBloodRecirculationState(); setupForDialysateRecirculationState(); result = TREATMENT_STOP_RECIRC_STATE; } // Both blocked and not in stopped state - if ( (TREATMENT_STOP_NO_RECIRC_STATE != state) && ( TRUE == dialysateRecircBlocked ) - && ( TRUE == bloodRecircBlocked ) ) + if ( ( TREATMENT_STOP_NO_RECIRC_STATE != state ) && ( TRUE == dialysateRecircBlocked ) && ( TRUE == bloodRecircBlocked ) ) { setupForBloodRecirculationStopState(); setupForDialysateRecirculationStopState(); result = TREATMENT_STOP_NO_RECIRC_STATE; } // Dialysate recirculation blocked and not in blood recirc state - if ( ( TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE != state ) - && ( TRUE == dialysateRecircBlocked ) - && ( FALSE == bloodRecircBlocked ) ) + if ( ( TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE != state ) && + ( TRUE == dialysateRecircBlocked ) && + ( FALSE == bloodRecircBlocked ) ) { setupForDialysateRecirculationStopState(); result = TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE; } // Blood recirculation blocked and not in dialysate recirc state - if ( ( TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE != state ) - && ( TRUE == bloodRecircBlocked ) - && ( FALSE == dialysateRecircBlocked ) ) + if ( ( TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE != state ) && + ( TRUE == bloodRecircBlocked ) && + ( FALSE == dialysateRecircBlocked ) ) { setupForBloodRecirculationStopState(); result = TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE; @@ -402,6 +414,7 @@ bloodSittingTimerCtr = 0; } } + /*********************************************************************//** * @brief * The getCurrentTreatmentStopState function returns the current state of the