Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -r32763ee524dc476f47ba41ee6c2a8a0c65ebf1e1 -r8d31b2019ec67195f074853795d100a9eeb4b410 --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 32763ee524dc476f47ba41ee6c2a8a0c65ebf1e1) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 8d31b2019ec67195f074853795d100a9eeb4b410) @@ -49,7 +49,7 @@ /// 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.0F ///< Power level setting (PWM) in percentage for H12 air pump to fill (raise level) the air trap. +#define AIR_PUMP_MOTOR_FILL_PWM 24.0F ///< Power level setting (PWM) in percentage for H12 air pump to fill (raise level) the air trap. #define AIR_PUMP_MOTOR_LOWER_PWM 24.0F ///< Power level setting (PWM) in percentage for H12 air pump to lower the level of the air trap. /// ax2 + bx + c, x is long filtered venous pressure, a,b,c is quadratic coefficients @@ -92,8 +92,6 @@ static BOOL airTrapHasDetectedFaultMode; ///< Flag indicates air trap unit has handled transition to fault mode. -static BOOL airTrapFirstLowerEvent; ///< Flag for first lower event - // ********** private function prototypes ********** static AIR_TRAP_STATE_T handleAirTrapManualControlState( void ); @@ -140,7 +138,6 @@ airTrapLowerDelayStartTime = 0; airTrapLowerStartTime = 0; airTrapHasDetectedFaultMode = FALSE; - airTrapFirstLowerEvent = FALSE; } /*********************************************************************//** @@ -372,8 +369,10 @@ { pendingStartAirTrapController = FALSE; setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + result = AIR_TRAP_CLOSED_STATE; } @@ -397,6 +396,7 @@ if ( TRUE == pendingStopAirTrapController ) { pendingStopAirTrapController = FALSE; + result = AIR_TRAP_MANUAL_CONTROL_STATE; } @@ -406,24 +406,18 @@ if ( ( AIR_PUMP_STATE_OFF == getAirPumpState() ) && ( 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 - // if it is first lower event - if( TRUE == airTrapFirstLowerEvent ) - { - // use the long filtered H14 venous pressure based duty cycle before AP fill event stored in airTrapAirPumpLowerPowerLevel.data during fill - setAirPumpState( AIR_PUMP_STATE_ON, getAirPumpLowerPowerLevel() ); - airTrapFirstLowerEvent = FALSE; - } - else - { - // get long filtered H14 venous pressure before AP lower event for subsequent lower event - airTrapAirPumpLowerPowerLevel.data = getCalculatedAirPumpDutyCycle(); - setAirPumpState( AIR_PUMP_STATE_ON, getAirPumpLowerPowerLevel() ); - } + // open valve H13 to allow air to be pumped into air trap from atmosphere + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); + // get long filtered H14 venous pressure before AP lower event + airTrapAirPumpLowerPowerLevel.data = getCalculatedAirPumpDutyCycle(); + 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; } } @@ -432,15 +426,16 @@ else if ( ( airTrapWasFilledAtStartOfTreatement != TRUE ) || ( AIR_TRAP_LEVEL_AIR == getLevelSensorState( H17_LEVL ) ) ) { - // fill/raise duty cycle is always 60% + // fill/raise duty cycle is always 24% 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 + + // open valve H20 to allow air to be pumped out of air trap to atmosphere + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); + airTrapFillStartTime = getMSTimerCount(); + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, ON, 0 ); - // set flag for first lower event - airTrapFirstLowerEvent = TRUE; - // get long filtered H14 venous pressure and duty cycle before AP fill event for the first lower event - airTrapAirPumpLowerPowerLevel.data = getCalculatedAirPumpDutyCycle(); + result = AIR_TRAP_RAISE_LEVEL_STATE; } @@ -464,24 +459,30 @@ if ( TRUE == pendingStopAirTrapController ) { pendingStopAirTrapController = FALSE; + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + result = AIR_TRAP_MANUAL_CONTROL_STATE; } // Transition back to lower level state when air trap fill completed else if ( AIR_TRAP_LEVEL_FLUID == getRawLevelSensorState( H16_LEVL ) ) { airTrapWasFilledAtStartOfTreatement = TRUE; + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); - //airTrapAirPumpLowerPowerLevel.data = getCalculatedAirPumpDutyCycle(); + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); + // adjust the air trap lower delay start time after fill complete - // simulate that 9 sec is elapsed so that air pump will be turned on after 1 sec by decrementing current time in milli sec - 9000 mili sec + // simulate that 9 sec is elapsed so that air pump will be turned on after 1 sec by decrementing 9000 mili sec from current time in milli sec airTrapLowerDelayStartTime = u32DiffWithWrap( AIR_PUMP_ON_DELAY_ADJUST_AFTER_FILL, getMSTimerCount() ); airTrapLowerStartTime = getMSTimerCount(); signalInitiatePressureStabilization( USE_SHORT_STABILIZATION_PERIOD ); + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, OFF, 0 ); + result = AIR_TRAP_CLOSED_STATE; } @@ -507,6 +508,7 @@ pendingStopAirTrapController = FALSE; setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); 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 when air detected at upper level @@ -515,9 +517,12 @@ { 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 ); + result = AIR_TRAP_CLOSED_STATE; }