Index: firmware/App/Modes/TreatmentEnd.c =================================================================== diff -u -redd44135869db32d23a0c809f6107b153c34d3bd -r8d3dbd25627fb7e993409eb47b2575e0430afddd --- firmware/App/Modes/TreatmentEnd.c (.../TreatmentEnd.c) (revision edd44135869db32d23a0c809f6107b153c34d3bd) +++ firmware/App/Modes/TreatmentEnd.c (.../TreatmentEnd.c) (revision 8d3dbd25627fb7e993409eb47b2575e0430afddd) @@ -20,6 +20,7 @@ #include "DialInFlow.h" #include "DialOutFlow.h" #include "ModeTreatment.h" +#include "ModeTreatmentParams.h" #include "OperationModes.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" @@ -36,8 +37,6 @@ /// Interval at which treatment end progress is to be published to UI. #define TREATMENT_END_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) -/// Target flow rate for blood while waiting for user to initiate final rinseback. -#define TX_END_BP_FLOW_RATE_ML_MIN 150 /// Max time to wait for user to initiate final rinseback. static const U32 TX_END_TIMEOUT_MS = ( ( 10 * 60 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); @@ -54,6 +53,8 @@ static BOOL txEndRinsebackRequested; ///< Flag indicates user requesting final rinseback. static BOOL txEndDrainCmdSent; ///< Flag indicates DG Drain command has been sent. static U32 treatmentEndPublishTimerCtr; ///< Timer counter for determining interval for treatment end status to be published. +static BOOL airTrapFillInProgress; ///< Flag indicates an air trap fill is in progress. +static U32 txEndTargetBloodFlowMLPM; ///< Treatment end target blood flow in mL/min. // ********** private function prototypes ********** @@ -84,20 +85,31 @@ treatmentEndPublishTimerCtr = 0; txEndDrainCmdSent = FALSE; resetTreatmentEndFlags(); + airTrapFillInProgress = FALSE; // set to false initially - so keep after call to reset function + txEndTargetBloodFlowMLPM = getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); + + // The default for the blood flow is from the treatment parameters target flow but if the institutional + // record for the target flow is not 0 it takes the precedence + if ( getNVInstitutionalRecordTxEndBloodFlowMLPM() != 0 ) + { + txEndTargetBloodFlowMLPM = getNVInstitutionalRecordTxEndBloodFlowMLPM(); + } } /*********************************************************************//** * @brief * The resetTreatmentEndFlags function resets the treatment end request flags. * @details Inputs: none - * @details Outputs: Treatment end request flags reset to FALSE. + * @details Outputs: txEndAlarmRinsebackRequested, txEndAlarmEndTreatmentRequested, + * txEndRinsebackRequested, airTrapFillInProgress * @return none *************************************************************************/ static void resetTreatmentEndFlags( void ) { txEndAlarmRinsebackRequested = FALSE; txEndAlarmEndTreatmentRequested = FALSE; txEndRinsebackRequested = FALSE; + airTrapFillInProgress = isAirTrapFillInProgress(); } /*********************************************************************//** @@ -137,9 +149,8 @@ * @brief * The setupForTxEndWait4RinsebackState function sets actuators appropriately * for treatment end wait for rinseback state. - * @details Inputs: none - * @details Outputs: arterial and venous lines opened, blood pump started, - * and air trap leveling control is started. + * @details Inputs: txEndTargetBloodFlowMLPM + * @details Outputs: bloodSittingTimerCtr * @return none *************************************************************************/ static void setupForTxEndWait4RinsebackState( void ) @@ -149,7 +160,7 @@ setValvePosition( VBA, VALVE_POSITION_B_OPEN ); setValvePosition( VBV, VALVE_POSITION_B_OPEN ); // Start blood pump at Tx End slow flow rate - setBloodPumpTargetFlowRate( TX_END_BP_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + setBloodPumpTargetFlowRate( txEndTargetBloodFlowMLPM, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); bloodSittingTimerCtr = 0; // Continue air trap leveling control startAirTrapControl(); @@ -225,7 +236,8 @@ * The handleTxEndWait4RinsebackState function handles the treatment end * wait for rinseback state operations. * @details Inputs: txEndDrainCmdSent, txEndAlarmEndTreatmentRequested, - * txEndRinsebackRequested, txEndAlarmRinsebackRequested, txEndTimerCtr + * txEndRinsebackRequested, txEndAlarmRinsebackRequested, txEndTimerCtr, + * airTrapFillInProgress, txEndTargetBloodFlowMLPM * @details Outputs: txEndDrainCmdSent * @return next treatment end wait for rinseback state *************************************************************************/ @@ -271,6 +283,22 @@ { signalGoToRinseback(); } + // if an air trap fill has started, set BP rate and VBV state accordingly + else if ( ( airTrapFillInProgress != TRUE ) && ( TRUE == isAirTrapFillInProgress() ) ) + { + // set BP to air trap fill rate if air trap fill has been initiated + setBloodPumpTargetFlowRate( AIR_TRAP_FILL_BLOOD_FLOW_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + // close VBV for fill + setValvePosition( VBV, VALVE_POSITION_C_CLOSE ); + } + // re-open VBV and restore BP rate after air trap fill + else if ( ( TRUE == airTrapFillInProgress ) && ( isAirTrapFillInProgress() != TRUE ) ) + { + // re-open VBV after fill + setValvePosition( VBV, VALVE_POSITION_B_OPEN ); + // restore BP to Tx End blood flow rate + setBloodPumpTargetFlowRate( txEndTargetBloodFlowMLPM, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + } return result; }