Index: firmware/App/Modes/Rinseback.c =================================================================== diff -u -r49dba1e95bb3763b4c150e7a80b84a65264a7ca8 -r61c515bc5b8a9494ca25dbfcc2394f3a7b7c57e7 --- firmware/App/Modes/Rinseback.c (.../Rinseback.c) (revision 49dba1e95bb3763b4c150e7a80b84a65264a7ca8) +++ firmware/App/Modes/Rinseback.c (.../Rinseback.c) (revision 61c515bc5b8a9494ca25dbfcc2394f3a7b7c57e7) @@ -38,9 +38,9 @@ // ********** private definitions ********** #define TARGET_RINSEBACK_VOLUME_ML 300.0 ///< Target rinseback volume to deliver back to the patient (in mL). -#define RINSEBACK_FLOW_RATE_ADJ_ML_MIN 25.0 ///< Adjustment amount (in mL/min) to apply when user requests increase/decrease in flow rate. -#define MIN_RINSEBACK_FLOW_RATE_ML_MIN 50.0 ///< Minimum rinseback flow rate (in mL/min). -#define MAX_RINSEBACK_FLOW_RATE_ML_MIN 150.0 ///< Maximum rinseback flow rate (in mL/min). +#define RINSEBACK_FLOW_RATE_ADJ_ML_MIN 25 ///< Adjustment amount (in mL/min) to apply when user requests increase/decrease in flow rate. +#define MIN_RINSEBACK_FLOW_RATE_ML_MIN 50 ///< Minimum rinseback flow rate (in mL/min). +#define MAX_RINSEBACK_FLOW_RATE_ML_MIN 150 ///< Maximum rinseback flow rate (in mL/min). static const F32 RINSEBACK_FLOW_INTEGRATOR = 1.0 / (F32)( SEC_PER_MIN * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); @@ -139,8 +139,8 @@ // Set valves to safe state setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); - setValvePosition( VBA, VALVE_POSITION_B_OPEN ); - setValvePosition( VBV, VALVE_POSITION_B_OPEN ); + setValvePosition( VBA, VALVE_POSITION_C_CLOSE ); + setValvePosition( VBV, VALVE_POSITION_C_CLOSE ); // Ensure all pumps except DPi stopped signalBloodPumpHardStop(); @@ -165,7 +165,6 @@ { case RINSEBACK_STOP_INIT_STATE: rinsebackState = handleRinsebackStopInitState(); - //setBloodIsPrimed( FALSE ); TODO - call in handler when transition to RB run break; case RINSEBACK_RUN_STATE: @@ -206,6 +205,26 @@ { RINSEBACK_STATE_T result = RINSEBACK_STOP_INIT_STATE; + if ( TRUE == startRinsebackRequested ) + { + // 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 ); + // Start blood pump at rinseback flow rate + setBloodPumpTargetFlowRate( getTreatmentParameterU32( TREATMENT_PARAM_RINSEBACK_FLOW_RATE ), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + // From moment we start rinseback, we consider blood side of dialyzer no longer fully primed + setBloodIsPrimed( FALSE ); + result = RINSEBACK_RUN_STATE; + } + else if ( TRUE == backToTreatmentRequested ) + { + // TODO - signal treatment mode to go back to treatment stop state + } + else if ( TRUE == endTreatmentRequested ) + { + // TODO - signal treatment mode to go to treatment end state + } + return result; } @@ -225,7 +244,7 @@ cumulativeRinsebackVolume_mL += ( getMeasuredBloodFlowRate() * RINSEBACK_FLOW_INTEGRATOR ); // Has rinseback completed? - if ( cumulativeRinsebackVolume_mL <= TARGET_RINSEBACK_VOLUME_ML ) + if ( cumulativeRinsebackVolume_mL >= TARGET_RINSEBACK_VOLUME_ML ) { setRinsebackIsCompleted( TRUE ); result = RINSEBACK_STOP_STATE; @@ -238,14 +257,32 @@ // Otherwise, continue rinseback else { // Has user requested rate change? - if ( ( TRUE == incrRinsebackFlowRateRequested ) || ( TRUE == incrRinsebackFlowRateRequested ) ) + if ( ( TRUE == incrRinsebackFlowRateRequested ) || ( TRUE == decrRinsebackFlowRateRequested ) ) { - // TODO - update rate if within limits + U32 rbRate = getTreatmentParameterU32( TREATMENT_PARAM_RINSEBACK_FLOW_RATE ); + + if ( TRUE == incrRinsebackFlowRateRequested ) + { + rbRate += RINSEBACK_FLOW_RATE_ADJ_ML_MIN; + } + else + { + rbRate -= RINSEBACK_FLOW_RATE_ADJ_ML_MIN; + } + if ( ( rbRate >= MIN_RINSEBACK_FLOW_RATE_ML_MIN ) && ( rbRate <= MAX_RINSEBACK_FLOW_RATE_ML_MIN ) ) + { + setTreatmentParameterU32( TREATMENT_PARAM_RINSEBACK_FLOW_RATE, rbRate ); + } } + + // TODO - monitor max time or independent volume as safety check for rinseback operation } return result; } +#define RINSEBACK_FLOW_RATE_ADJ_ML_MIN 25 ///< Adjustment amount (in mL/min) to apply when user requests increase/decrease in flow rate. +#define MIN_RINSEBACK_FLOW_RATE_ML_MIN 50 ///< Minimum rinseback flow rate (in mL/min). +#define MAX_RINSEBACK_FLOW_RATE_ML_MIN 150 ///< Maximum rinseback flow rate (in mL/min). /*********************************************************************//** * @brief @@ -418,7 +455,7 @@ static BOOL handleIncrRinsebackUserAction( REQUEST_REJECT_REASON_CODE_T *rejReason ) { BOOL result = FALSE; - F32 rbRate = (F32)getTreatmentParameterU32( TREATMENT_PARAM_RINSEBACK_FLOW_RATE ); + U32 rbRate = getTreatmentParameterU32( TREATMENT_PARAM_RINSEBACK_FLOW_RATE ); if ( ( rbRate + RINSEBACK_FLOW_RATE_ADJ_ML_MIN ) <= MAX_RINSEBACK_FLOW_RATE_ML_MIN ) {