Index: firmware/App/Modes/StateTxBloodPrime.c =================================================================== diff -u -ra6d020a7797cf7fb721867eb33c8b7957da8decb -rfa48af23c2b1cf940c485ad2602fdd186e775a0e --- firmware/App/Modes/StateTxBloodPrime.c (.../StateTxBloodPrime.c) (revision a6d020a7797cf7fb721867eb33c8b7957da8decb) +++ firmware/App/Modes/StateTxBloodPrime.c (.../StateTxBloodPrime.c) (revision fa48af23c2b1cf940c485ad2602fdd186e775a0e) @@ -17,6 +17,7 @@ #include "AirTrap.h" #include "BloodFlow.h" +#include "Buttons.h" #include "ModeTreatment.h" #include "TxParams.h" #include "OperationModes.h" @@ -59,6 +60,7 @@ static U32 bloodPrimeRampControlTimerCtr; ///< Timer counter for determining interval for controlling BP ramp. static U32 bloodPrimePublishTimerCtr; ///< Timer counter for determining interval for blood prime status to be published. +static U32 lastBloodPrimeFlowRate_mL_min; ///< Timer counter for determining for last blood prime status. /// Interval (in task intervals) at which to publish blood prime data to CAN bus. static OVERRIDE_U32_T bloodPrimePublishInterval = { BLOOD_PRIME_DATA_PUBLISH_INTERVAL, BLOOD_PRIME_DATA_PUBLISH_INTERVAL, BLOOD_PRIME_DATA_PUBLISH_INTERVAL, 0 }; @@ -231,66 +233,111 @@ // Update blood prime volume delivered so far cumulativeBloodPrimeVolume_mL.data += ( getMeasuredBloodFlowRate() * BLOOD_PRIME_FLOW_INTEGRATOR ); - if ( TRUE == getTestConfigStatus( TEST_CONFIG_SKIP_BLOOD_PRIME ) ) - { - // If the skip blood prime is enabled, set the cumulative volume to the target blood prime volume - cumulativeBloodPrimeVolume_mL.data = bloodPrimeTargetVolume_mL; - } - // Has blood prime completed? if ( getBloodPrimeVolume() >= bloodPrimeTargetVolume_mL ) { initBloodPrime(); // Reset blood prime so that we start anew next time we transition to this sub-mode setBloodIsPrimed( TRUE ); // Signal treatment mode that blood prime is completed signalBloodPrimeToDialysis(); // Signal treatment mode that it's time to start dialysis + } + + else if ( getMeasuredBloodFlowRate() >= getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ) ) + { result = BLOOD_PRIME_RUN_STATE; } - else + + // User requested pause + else if ( TRUE == isStopButtonPressed() ) { - // ramp blood pump on ramp interval - if ( ++bloodPrimeRampControlTimerCtr >= BLOOD_PRIME_RAMPING_INTERVAL ) - { - U32 setBPRate = getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); + lastBloodPrimeFlowRate_mL_min = getMeasuredBloodFlowRate(); + setBloodPumpTargetFlowRate(0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - bloodPrimeRampControlTimerCtr = 0; - bloodPrimeRampFlowRate_mL_min += bloodPrimeRampStep_mL; - setBloodPumpTargetFlowRate( (U32)bloodPrimeRampFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - } + // Close arterial & venous valves + setValvePosition( H1_VALV, VALVE_POSITION_A_INSERT_EJECT ); + setValvePosition( H19_VALV, VALVE_POSITION_A_INSERT_EJECT ); + result = BLOOD_PRIME_PAUSED_STATE; } + else if ( getMeasuredBloodFlowRate() >= getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ) ) + { + result = BLOOD_PRIME_RUN_STATE; + } + return result; } /*********************************************************************//** * @brief * The handleBloodPrimeRunState function handles the blood prime run * state operations. - * @details \b Inputs: flags - * @details \b Outputs: flags handled + * @details \b Inputs: cumulativeBloodPrimevolume_mL + * @details \b Outputs: cumulativeBloodPrimevolume_mL * @return next blood prime state *************************************************************************/ static BLOOD_PRIME_STATE_T handleBloodPrimeRunState( void ) { - BLOOD_PRIME_STATE_T result = BLOOD_PRIME_RUN_STATE; + BLOOD_PRIME_STATE_T result = BLOOD_PRIME_RUN_STATE; - cumulativeBloodPrimeVolume_mL.data += ( getMeasuredBloodFlowRate() * BLOOD_PRIME_FLOW_INTEGRATOR ); + // Update blood prime volume delivered so far + cumulativeBloodPrimeVolume_mL.data += ( getMeasuredBloodFlowRate() * BLOOD_PRIME_FLOW_INTEGRATOR ); - return result; + if ( getBloodPrimeVolume() >= bloodPrimeTargetVolume_mL ) + { + initBloodPrime(); // Reset blood prime so that we start anew next time we transition to this sub-mode + setBloodIsPrimed( TRUE ); // Signal treatment mode that blood prime is completed + signalBloodPrimeToDialysis(); // Signal treatment mode that it's time to start dialysis + } + + // User if request stop/pause + else if ( TRUE == isStopButtonPressed() ) + { + lastBloodPrimeFlowRate_mL_min = getMeasuredBloodFlowRate(); + // Turn pump OFF + setBloodPumpTargetFlowRate(0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + + // Close arterial & venous pinch valves + setValvePosition( H1_VALV, VALVE_POSITION_A_INSERT_EJECT ); + setValvePosition( H19_VALV, VALVE_POSITION_A_INSERT_EJECT ); + result = BLOOD_PRIME_PAUSED_STATE; + } + + return result; } /*********************************************************************//** * @brief * The handleBloodPrimePausedState function handles the blood prime paused * state operations. - * @details \b Inputs: flags + * @details \b Inputs: getCurrentOperationMode * @details \b Outputs: flags handled * @return none *************************************************************************/ static BLOOD_PRIME_STATE_T handleBloodPrimePausedState( void ) { - BLOOD_PRIME_STATE_T result = BLOOD_PRIME_PAUSED_STATE; + BLOOD_PRIME_STATE_T result = BLOOD_PRIME_PAUSED_STATE; - return result; + // Transition back to treatment + if ( getCurrentOperationMode() == MODE_TREA ) + { + // Re-open arterial & venous valves + setValvePosition( H1_VALV, VALVE_POSITION_B_OPEN ); + setValvePosition( H19_VALV, VALVE_POSITION_B_OPEN ); + + // Restart pump at previous flow rate + setBloodPumpTargetFlowRate( lastBloodPrimeFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + + // Next state + if ( getMeasuredBloodFlowRate() < getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ) ) + { + result = BLOOD_PRIME_RAMP_STATE; + } + else + { + result = BLOOD_PRIME_RUN_STATE; + } + } + + return result; } /*********************************************************************//** Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rf289a9279e8e924fd11411df6a71ac6727b800bc -rfa48af23c2b1cf940c485ad2602fdd186e775a0e --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision f289a9279e8e924fd11411df6a71ac6727b800bc) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision fa48af23c2b1cf940c485ad2602fdd186e775a0e) @@ -181,7 +181,6 @@ { MSG_ID_TD_EJECTOR_OPT_SENSOR_OVERRIDE_REQUEST, &testEjectorOpticalSensorOverride }, { MSG_ID_TD_BLOOD_PRIME_VOLUME_OVERRIDE, &testBloodPrimeVolumeOverride }, { MSG_ID_TD_BLOOD_PRIME_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testBloodPrimePublishIntervalOverride }, - { MSG_ID_TD_ENABLE_VENOUS_BUBBLE_ALARM, &testEnableVenousBubbleAlarm }, }; #define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLER_LOOKUP) / sizeof(MSG_HANDLER_LOOKUP_T))