Index: firmware/App/Modes/TreatmentEnd.c =================================================================== diff -u -rec0ae6f3e8dd68564f9ae0d73dc996f58c86d115 -r74be223d47ea7bb0ac7d814e74d3627d830a5fac --- firmware/App/Modes/TreatmentEnd.c (.../TreatmentEnd.c) (revision ec0ae6f3e8dd68564f9ae0d73dc996f58c86d115) +++ firmware/App/Modes/TreatmentEnd.c (.../TreatmentEnd.c) (revision 74be223d47ea7bb0ac7d814e74d3627d830a5fac) @@ -5,13 +5,13 @@ * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * -* @file TreatmentEnd.c +* @file TreatmentEnd.c * -* @author (last) Sean Nash -* @date (last) 04-Feb-2021 +* @author (last) Sean Nash +* @date (last) 19-Aug-2021 * -* @author (original) Sean -* @date (original) 04-Feb-2021 +* @author (original) Sean Nash +* @date (original) 05-Feb-2021 * ***************************************************************************/ @@ -39,8 +39,10 @@ /// Max time to wait for user to initiate final rinseback. static const U32 TX_END_TIMEOUT_MS = ( ( 15 * 60 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); // TODO - get time from Systems -/// Maximum time in this mode before blood sitting warning given (in general task intervals). +/// Maximum time in this mode before blood sitting alarm given (in general task intervals). static const U32 MAX_TIME_BLOOD_SITTING = ( ( 5 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); +/// Maximum time in this mode before blood sitting warning given (in general task intervals). +static const U32 WARN_TIME_BLOOD_SITTING = ( ( 4 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); // ********** private data ********** @@ -109,7 +111,8 @@ { initTreatmentEnd(); - // TODO - stop any DG fill that may be in progress + // Stop any DG fill that may be in progress + cmdStopDGFill(); // Set valves setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); @@ -122,6 +125,7 @@ signalDialOutPumpHardStop(); stopSyringePump(); setBloodPumpTargetFlowRate( TX_END_BP_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + cmdStopDGTrimmerHeater(); // Continue air trap control startAirTrapControl(); @@ -143,6 +147,8 @@ *************************************************************************/ static void setupForTxEndWait4RinsebackState( void ) { + // No resume alarm action allowed + setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, FALSE ); // Open VBA and VBV valves to allow flow from saline bag and to patient venous line setValvePosition( VBA, VALVE_POSITION_B_OPEN ); setValvePosition( VBV, VALVE_POSITION_B_OPEN ); @@ -164,6 +170,8 @@ *************************************************************************/ static void setupForTxEndPausedState( void ) { + // Resume alarm action will take us back to TxEndWait4RinsebackState + setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, TRUE ); // Stop blood pump signalBloodPumpHardStop(); // Close arterial and venous lines @@ -216,12 +224,30 @@ { TREATMENT_END_STATE_T result = TREATMENT_END_WAIT_FOR_RINSEBACK_STATE; + // Set reservoir 2 as active so we can drain reservoir 1 ASAP // TODO - I think this should be handled by treatment reservoir mgmt state machine + if ( ( DG_MODE_GENE == getDGOpMode() ) && ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == getDGSubMode() ) ) + { + if ( getDGInactiveReservoir() != DG_RESERVOIR_1 ) + { + cmdSetDGActiveReservoir( DG_RESERVOIR_2 ); + } + else + { + cmdStartDGDrain( DRAIN_RESERVOIR_TO_VOLUME_ML, TRUE, FALSE ); + } + } + // Is alarm stop or user reconnect requested? if ( TRUE == doesAlarmStatusIndicateStop() ) { setupForTxEndPausedState(); result = TREATMENT_END_PAUSED_STATE; } + // Is treatment end requested? + else if ( TRUE == txEndAlarmEndTreatmentRequested ) + { + signalEndTreatment(); + } // Is final rinseback requested? else if ( ( TRUE == txEndRinsebackRequested ) || ( TRUE == txEndAlarmRinsebackRequested ) ) { @@ -269,9 +295,14 @@ else { // Ensure we do not sit in stopped state for too long + if ( bloodSittingTimerCtr > WARN_TIME_BLOOD_SITTING ) + { + activateAlarmNoData( ALARM_ID_END_OF_TREATMENT_ALARM ); + } if ( bloodSittingTimerCtr > MAX_TIME_BLOOD_SITTING ) { - activateAlarmNoData( ALARM_ID_TREATMENT_STOPPED_NO_RINSEBACK ); + // Raise the alarm + activateAlarmNoData( ALARM_ID_END_OF_TREATMENT_HIGH ); } }