Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -rccfd15568f1e3d304320c2babb2fd4bcf0413304 -r8bd1ae47aa13a843aa8abd6321ddc050deacb4a6 --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision ccfd15568f1e3d304320c2babb2fd4bcf0413304) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 8bd1ae47aa13a843aa8abd6321ddc050deacb4a6) @@ -196,8 +196,10 @@ static S32 syringePumpLastPositions[ SYRINGE_PUMP_SPEED_CALC_BUFFER_LEN ]; ///< Last encoder positions for the syringe pump. static U32 syringePumpMotorSpeedCalcIdx; ///< Index into 1 second buffer of syringe pump encoder positions. static U32 syringePumpSpeedCalcTimerCounter; ///< Used to calculate measured rate from change in position over time. +#ifndef DISABLE_SYRINGE_PUMP_ALARMS static MOTOR_DIR_T syringePumpControllerMeasuredDirection; ///< Measured direction of syringe pump per controller. static MOTOR_DIR_T syringePumpEncoderMeasuredDirection; ///< Measured direction of syringe pump per encoder position relative to previous. +#endif static BOOL syringePumpRetractRequested; ///< Flag indicates a retract operation is requested. static BOOL syringePumpSeekRequested; ///< Flag indicates a plunger seek operation is requested. @@ -275,8 +277,10 @@ syringePumpVolumeStartPosition = 0; syringePumpHomePositionOffset = 0; syringePumpLastPosition = 0; +#ifndef DISABLE_SYRINGE_PUMP_ALARMS syringePumpControllerMeasuredDirection = MOTOR_DIR_FORWARD; syringePumpEncoderMeasuredDirection = MOTOR_DIR_FORWARD; +#endif syringePumpDataPublicationTimerCounter = 0; syringePumpSpeedCalcTimerCounter = 0; @@ -519,17 +523,29 @@ { syringePumpSetRate = SYRINGE_PUMP_PRIME_RATE; syringePumpPrimeRequested = TRUE; - // Reset volume and start pos before starting prime operation - syringePumpVolumeDelivered.data = 0.0; - syringePumpSafetyVolumeDelivered = 0.0; - syringePumpVolumeStartPosition = getSyringePumpPosition(); + resetHeparinVolumeDelivered(); } return syringePumpPrimeRequested; } /*********************************************************************//** * @brief + * The resetHeparinVolumeDelivered function resets the Heparin volume delivered. + * @details Inputs: none + * @details Outputs: syringePumpVolumeDelivered, syringePumpSafetyVolumeDelivered, + * syringePumpVolumeStartPosition + * @return none + *************************************************************************/ +void resetHeparinVolumeDelivered( void ) +{ + syringePumpVolumeDelivered.data = 0.0; + syringePumpSafetyVolumeDelivered = 0.0; + syringePumpVolumeStartPosition = getSyringePumpPosition(); +} + +/*********************************************************************//** + * @brief * The startHeparinBolus function requests Heparin bolus delivery. * @details Inputs: syringePumpState * @details Outputs: syringePumpSetRate, syringePumpBolusRequested @@ -550,10 +566,6 @@ { syringePumpSetRate = tgtRate; syringePumpBolusRequested = TRUE; - // Reset volume and start pos before starting bolus operation - syringePumpVolumeDelivered.data = 0.0; - syringePumpSafetyVolumeDelivered = 0.0; - syringePumpVolumeStartPosition = getSyringePumpPosition(); } } else @@ -930,6 +942,7 @@ static void execSyringePumpMonitor( void ) { F32 forceSensorBeforCal = 0.0; + BOOL prevSyringeDetected = isSyringeDetected(); // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) @@ -949,6 +962,11 @@ // Get latest ADC data and convert to V syringePumpMeasHome.data = ( (F32)getFPGASyringePumpADCChannel2() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; syringePumpMeasSyringeDetectionSwitch.data = ( (F32)getFPGASyringePumpADCChannel1() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; + // On transition from not detected to detected - clear syringe removed alarm condition + if ( ( prevSyringeDetected != TRUE ) && ( TRUE == isSyringeDetected() ) ) + { + clearAlarmCondition( ALARM_ID_HD_SYRINGE_PUMP_SYRINGE_REMOVED ); + } forceSensorBeforCal = ( (F32)getFPGASyringePumpADCChannel0() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; syringePumpMeasForce.data = pow(forceSensorBeforCal, 4) * forceSensorCalRecord.hdHeparinForceSensor.fourthOrderCoeff + @@ -965,10 +983,12 @@ calcSafetyVolumeDelivered(); // Calculate measured rate (mL/hr) calcMeasRate(); +#ifndef DISABLE_SYRINGE_PUMP_ALARMS // Get measured direction syringePumpControllerMeasuredDirection = ( ( getSyringePumpEncoderStatus() & SYRINGE_PUMP_ENCODER_DIRECTION_BIT ) != 0 ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); // Calculate direction from encoder position relative to last syringePumpEncoderMeasuredDirection = ( getSyringePumpPosition() - syringePumpLastPosition >= 0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); +#endif // Check if syringe pump is on while BP is off { @@ -1091,8 +1111,8 @@ * @brief * The handleSyringePumpInitState function handles the initialize state * of the syringe pump control state machine. - * @details Inputs: TBD - * @details Outputs: TBD + * @details Inputs: none + * @details Outputs: pump speed set to zero, ADC enabled, direction set to reverse * @return next state *************************************************************************/ static SYRINGE_PUMP_STATE_T handleSyringePumpInitState( void ) @@ -1113,8 +1133,10 @@ * @brief * The handleSyringePumpOffState function handles the off state * of the syringe pump control state machine. - * @details Inputs: TBD - * @details Outputs: TBD + * @details Inputs: syringePumpRetractRequested, syringePumpSeekRequested, + * syringePumpPrimeRequested, syringePumpBolusRequested, syringePumpContinuousRequested, + * syringePumpDACVrefSetRequested + * @details Outputs: Pump speed and direction set if pump command initiated * @return next state *************************************************************************/ static SYRINGE_PUMP_STATE_T handleSyringePumpOffState( void ) @@ -1306,6 +1328,7 @@ if ( TRUE == stopPump ) { stopSyringePump(); + retractSyringePump(); result = SYRINGE_PUMP_OFF_STATE; } @@ -1619,13 +1642,13 @@ static BOOL checkMeasRate( BOOL stopPump, F32 pctMargin ) { BOOL result = stopPump; +#ifndef DISABLE_SYRINGE_PUMP_ALARMS F32 rate = getSyringePumpMeasRate(); F32 max = MAX( rate, syringePumpSetRate ); F32 min = MIN( rate, syringePumpSetRate ); - F32 delta = max - min; F32 error = ( max > 0.0 ? ( 1.0 - fabs( min / max ) ) : 0.0 ); + F32 delta = max - min; -#ifndef DISABLE_SYRINGE_PUMP_ALARMS // Alarm on rate if off by more than 5% or 0.1 mL/hr, whichever is greater if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_SYRINGE_PUMP_SPEED_ERROR, ( ( error > pctMargin ) && ( delta > SYRINGE_PUMP_MAX_RATE_ERROR_ML_HR ) ) ) ) { @@ -1835,8 +1858,8 @@ ( (U32)getSyringePumpADCandDACStatus() << SHIFT_8_BITS_FOR_BYTE_SHIFT ) | ( (U32)getSyringePumpADCReadCounter() ); - broadcastSyringePumpData( data ); - broadcastHeparinData( data.syringePumpVolumeDelivered ); + broadcastData( MSG_ID_HD_SYRINGE_PUMP_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( SYRINGE_PUMP_DATA_PAYLOAD_T ) ); + broadcastData( MSG_ID_HD_HEPARIN_DATA_BROADCAST, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data.syringePumpVolumeDelivered, sizeof( F32 ) ); syringePumpDataPublicationTimerCounter = 0; } } @@ -1936,7 +1959,7 @@ * The testSyringePumpOperationRequest function requests a given syringe pump * operation. * @details Inputs: none - * @details Outputs: TBD + * @details Outputs: pump operation request is handled * @param opParams record containing the requested operation and its parameters * @return TRUE if override successful, FALSE if not *************************************************************************/