Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -r036a75d76ab01912646a480b935d97187a231a19 -r79a1bc916aaa25b696385e9b292bf6262bab6113 --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 036a75d76ab01912646a480b935d97187a231a19) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 79a1bc916aaa25b696385e9b292bf6262bab6113) @@ -49,6 +49,9 @@ /// Air pump on delay after fill adjustment static const U32 AIR_PUMP_ON_DELAY_ADJUST_AFTER_FILL = ( AIR_PUMP_ON_DELAY_TIME_MS - ( 1 * MS_PER_SECOND ) ); +#define AIR_PUMP_MOTOR_FILL_PWM 60 ///< Power level setting (PWM) for H12 air pump to fill (raise level) the air trap. +#define AIR_PUMP_MOTOR_LOWER_PWM 250 ///< Power level setting (PWM) for H12 air pump to lower the level of the air trap. + /// Defined states for the air trap controller state machine. typedef enum AirTrap_States { @@ -67,6 +70,9 @@ static U32 airTrapDataPublicationTimerCounter; ///< Used to schedule air trap data publication to CAN bus. static OVERRIDE_U32_T airTrapDataPublishInterval; ///< Interval (in ms) at which to publish air trap data to CAN bus. +static OVERRIDE_U32_T airTrapAirPumpRaisePowerLevel; ///< Air pump power level to use when raising the air trap blood level. +static OVERRIDE_U32_T airTrapAirPumpLowerPowerLevel; ///< Air pump power level to use when lowering the air trap blood level. + static BOOL pendingStartAirTrapController; ///< Flag indicates an air trap controller start request is pending. static BOOL pendingStopAirTrapController; ///< Flag indicates an air trap controller stop request is pending. @@ -84,6 +90,8 @@ static AIR_TRAP_STATE_T handleAirTrapClosedState( void ); static AIR_TRAP_STATE_T handleAirTrapRaiseLevelState( void ); static AIR_TRAP_STATE_T handleAirTrapLowerlevelState( void ); +static U08 getAirPumpRaisePowerLevel( void ); +static U08 getAirPumpLowerPowerLevel( void ); static void publishAirTrapData( void ); /*********************************************************************//** @@ -101,11 +109,19 @@ // Initialize controller variables resetAirTrap(); - airTrapDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; - airTrapDataPublishInterval.data = AIR_TRAP_DATA_PUB_INTERVAL; - airTrapDataPublishInterval.ovData = AIR_TRAP_DATA_PUB_INTERVAL; - airTrapDataPublishInterval.ovInitData = AIR_TRAP_DATA_PUB_INTERVAL; - airTrapDataPublishInterval.override = OVERRIDE_RESET; + airTrapDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + airTrapDataPublishInterval.data = AIR_TRAP_DATA_PUB_INTERVAL; + airTrapDataPublishInterval.ovData = AIR_TRAP_DATA_PUB_INTERVAL; + airTrapDataPublishInterval.ovInitData = AIR_TRAP_DATA_PUB_INTERVAL; + airTrapDataPublishInterval.override = OVERRIDE_RESET; + airTrapAirPumpRaisePowerLevel.data = AIR_PUMP_MOTOR_FILL_PWM; + airTrapAirPumpRaisePowerLevel.ovData = AIR_PUMP_MOTOR_FILL_PWM; + airTrapAirPumpRaisePowerLevel.ovInitData = AIR_PUMP_MOTOR_FILL_PWM; + airTrapAirPumpRaisePowerLevel.override = OVERRIDE_RESET; + airTrapAirPumpLowerPowerLevel.data = AIR_PUMP_MOTOR_LOWER_PWM; + airTrapAirPumpLowerPowerLevel.ovData = AIR_PUMP_MOTOR_LOWER_PWM; + airTrapAirPumpLowerPowerLevel.ovInitData = AIR_PUMP_MOTOR_LOWER_PWM; + airTrapAirPumpLowerPowerLevel.override = OVERRIDE_RESET; airTrapFillStartTime = 0; airTrapLowerDelayStartTime = 0; airTrapLowerStartTime = 0; @@ -238,7 +254,9 @@ // if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_AIR_TRAP_LEVELING_ALARM ) != SW_CONFIG_ENABLE_VALUE ) #endif { +#ifndef TEST_UI_ONLY activateAlarmNoData( ALARM_ID_TD_AIR_TRAP_FILL_DURING_TREATMENT ); +#endif } } } @@ -348,19 +366,19 @@ ( TRUE == didTimeout( airTrapLowerDelayStartTime, AIR_PUMP_ON_DELAY_TIME_MS ) ) ) { set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); // open valve H13 to allow air to be pumped into air trap from atmosphere - setAirPumpState( AIR_PUMP_STATE_ON, AIR_PUMP_MOTOR_LOWER_PWM ); + setAirPumpState( AIR_PUMP_STATE_ON, getAirPumpLowerPowerLevel() ); airTrapLowerStartTime = getMSTimerCount(); signalInitiatePressureStabilization( USE_SHORT_STABILIZATION_PERIOD ); SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_LOWER, ON, 0 ); result = AIR_TRAP_LOWER_LEVEL_STATE; } } - // Raise air trap level once at start of treatment (blood priming) or when air detected at upper level - else if ( ( TRUE == airTrapWasFilledAtStartOfTreatement ) || - ( AIR_TRAP_LEVEL_AIR == getLevelSensorState( H16_LEVL ) ) ) + // Raise air trap level once at start of treatment (blood priming) or when air detected at lower level + else if ( ( airTrapWasFilledAtStartOfTreatement != TRUE ) || + ( AIR_TRAP_LEVEL_AIR == getLevelSensorState( H17_LEVL ) ) ) { - setAirPumpState( AIR_PUMP_STATE_ON, AIR_PUMP_MOTOR_FILL_PWM ); + setAirPumpState( AIR_PUMP_STATE_ON, getAirPumpRaisePowerLevel() ); set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); // open valve H20 to allow air to be pumped out of air trap to atmosphere airTrapFillStartTime = getMSTimerCount(); SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, ON, 0 ); @@ -391,16 +409,17 @@ set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); result = AIR_TRAP_MANUAL_CONTROL_STATE; } - // Transition back to closed state when air trap fill completed + // Transition back to lower level state when air trap fill completed else if ( AIR_TRAP_LEVEL_FLUID == getRawLevelSensorState( H16_LEVL ) ) { airTrapWasFilledAtStartOfTreatement = TRUE; - setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); - airTrapLowerDelayStartTime = calcTimeBetween( AIR_PUMP_ON_DELAY_ADJUST_AFTER_FILL, getMSTimerCount() ); - signalLowVenousPressureCheck(); - SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, OFF, 0 ); - result = AIR_TRAP_CLOSED_STATE; + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); // open valve H13 to allow air to be pumped into air trap from atmosphere + setAirPumpState( AIR_PUMP_STATE_ON, getAirPumpLowerPowerLevel() ); + airTrapLowerStartTime = getMSTimerCount(); + signalInitiatePressureStabilization( USE_SHORT_STABILIZATION_PERIOD ); + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_LOWER, ON, 0 ); + result = AIR_TRAP_LOWER_LEVEL_STATE; } return result; @@ -431,14 +450,14 @@ set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); result = AIR_TRAP_MANUAL_CONTROL_STATE; } - // Transition back to closed state when air trap lower level operation completed + // Transition back to closed state when air trap lower level operation completed when air detected at upper level else if ( ( TRUE == didTimeout( airTrapLowerStartTime, airPumpStopTime ) ) || ( AIR_TRAP_LEVEL_AIR == getRawLevelSensorState( H16_LEVL ) ) ) - { setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); airTrapLowerDelayStartTime = getMSTimerCount(); + signalLowVenousPressureCheck(); SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_LOWER, OFF, 0 ); // if lower level operation times out, alarm if ( TRUE == didTimeout( airTrapLowerStartTime, airPumpStopTime ) ) @@ -453,6 +472,36 @@ /*********************************************************************//** * @brief + * The getAirPumpRaisePowerLevel function gets the air pump power level to + * use for raising the blood level in the air trap. + * @details \b Inputs: airTrapAirPumpRaisePowerLevel + * @details \b Outputs: none + * @return air pump power level for raising air trap blood level + *************************************************************************/ +static U08 getAirPumpRaisePowerLevel( void ) +{ + U08 result = getU08OverrideValue( &airTrapAirPumpRaisePowerLevel ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getAirPumpLowerPowerLevel function gets the air pump power level to + * use for lowering the blood level in the air trap. + * @details \b Inputs: airTrapAirPumpLowerPowerLevel + * @details \b Outputs: none + * @return air pump power level for lowering air trap blood level + *************************************************************************/ +static U08 getAirPumpLowerPowerLevel( void ) +{ + U08 result = getU08OverrideValue( &airTrapAirPumpLowerPowerLevel ); + + return result; +} + +/*********************************************************************//** + * @brief * The publishAirTrapData function constructs and sends the air trap data * broadcast message. * @details \b Message \b Sent: MSG_ID_TD_AIR_TRAP_DATA to publish air trap data @@ -503,5 +552,71 @@ return result; } +/*********************************************************************//** + * @brief + * The testSetAirTrapControl function sets the air trap to start or end + * auto level control. + * @details \b Inputs: none + * @details \b Outputs: airTrapDataPublishInterval + * @param message Override message from Dialin which includes the interval + * (in ms) to override the air trap broadcast interval to. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testSetAirTrapControl( MESSAGE_T *message ) +{ + BOOL result = FALSE; + BOOL startControl = FALSE; + + if ( ( TRUE == isTestingActivated() ) && ( sizeof( BOOL ) == message->hdr.payloadLen ) ) + { + result = TRUE; + memcpy( &startControl, message->payload, sizeof( BOOL ) ); + if ( TRUE == startControl ) + { + startAirTrapControl(); + } + else + { + endAirTrapControl(); + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testAirPumpPowerRaiseOverride function overrides the air pump power + * level used to raise the air trap level. + * @details \b Inputs: none + * @details \b Outputs: airTrapAirPumpRaisePowerLevel + * @param message Override message from Dialin which includes the power level + * to override the air pump to when raising air trap level. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testAirPumpPowerRaiseOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &airTrapAirPumpRaisePowerLevel, AIR_PUMP_MOTOR_OFF, AIR_PUMP_MOTOR_MAX_PWM ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testAirPumpPowerLowerOverride function overrides the air pump power + * level used to lower the air trap level. + * @details \b Inputs: none + * @details \b Outputs: airTrapAirPumpLowerPowerLevel + * @param message Override message from Dialin which includes the power level + * to override the air pump to when lowering air trap level. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testAirPumpPowerLowerOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &airTrapAirPumpLowerPowerLevel, AIR_PUMP_MOTOR_OFF, AIR_PUMP_MOTOR_MAX_PWM ); + + return result; +} + /**@}*/