Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -r2e6c750c202b7361d79488ce383e34f380e75413 -r108abddcbf729f7435073116191cd3903261df8f --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 2e6c750c202b7361d79488ce383e34f380e75413) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 108abddcbf729f7435073116191cd3903261df8f) @@ -175,7 +175,7 @@ setDialOutUFVolumes( refUFVolume, measUFVolume ); setBloodPumpTargetFlowRate( setBloodFlowRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); setDialInPumpTargetFlowRate( setDialysateFlowRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - setDialOutPumpTargetRate( setDialysateFlowRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + setDialOutPumpTargetRate( setDialysateFlowRate + FLOAT_TO_INT_WITH_ROUND( setUFRate ), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); // TODO - Heparin pump } @@ -198,6 +198,64 @@ /*********************************************************************//** * @brief + * The pauseUF function pauses ultrafiltration. + * @details + * Inputs : currentDialysisState, currentUFState + * Outputs : currentUFState, outlet pump set point + * @return TRUE if pause successful, FALSE if not + *************************************************************************/ +BOOL pauseUF( void ) +{ + BOOL result = FALSE; + + if ( ( DIALYSIS_UF_STATE == currentDialysisState ) && ( UF_RUNNING_STATE == currentUFState ) ) + { + // set outlet pump to dialysate rate + result = setDialOutPumpTargetRate( setDialysateFlowRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + + if ( TRUE == result ) + { + // go to UF paused state + currentUFState = UF_PAUSED_STATE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The resumeUF function resumes ultrafiltration. + * @details + * Inputs : currentDialysisState, currentUFState + * Outputs : currentUFState, outlet pump set point + * @return TRUE if resume successful, FALSE if not + *************************************************************************/ +BOOL resumeUF( void ) +{ + BOOL result = FALSE; + + if ( ( DIALYSIS_UF_STATE == currentDialysisState ) && ( UF_PAUSED_STATE == currentUFState ) ) + { + S32 inletPumpRate = getTargetDialInFlowRate(); + + // set outlet pump to dialysate rate + set UF rate + result = setDialOutPumpTargetRate( setDialysateFlowRate + FLOAT_TO_INT_WITH_ROUND( setUFRate ), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + + if ( TRUE == result ) + { + // restart UF time accumulation for reference volume calculation + lastUFTimeStamp = getMSTimerCount(); + // go to UF paused state + currentUFState = UF_RUNNING_STATE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief * The execDialysis function executes the Dialysis sub-mode state machine. * @details * Inputs : currentDialysisState @@ -331,7 +389,7 @@ // TODO - test code - remove later if ( TRUE == isStopButtonPressed() ) { - lastUFTimeStamp = getMSTimerCount(); // restart UF time accumulation + resumeUF(); result = UF_RUNNING_STATE; } @@ -370,6 +428,7 @@ // TODO - test code - remove later if ( TRUE == isStopButtonPressed() ) { + pauseUF(); result = UF_PAUSED_STATE; }