Index: Accel.c =================================================================== diff -u -re7142fcfe4ff86ed1786148f46ab5dbd6d2c4021 -rd48491fcff5810d1134b9737de77daa436a63586 --- Accel.c (.../Accel.c) (revision e7142fcfe4ff86ed1786148f46ab5dbd6d2c4021) +++ Accel.c (.../Accel.c) (revision d48491fcff5810d1134b9737de77daa436a63586) @@ -84,7 +84,10 @@ static U32 accelReadingsCount = 0; ///< number of samples in flow rolling average buffer static F32 accelAvgVector[ NUM_OF_ACCEL_AXES ]; ///< Filtered accelerometer vector for tilt static F32 accelTilt[ NUM_OF_ACCEL_AXES ]; ///< Axis angles for tilt determination (filtered and converted to degrees) -static U32 accelTiltErrorTimerCounter = 0; ///< used for persistence requirement on tilt error +static U32 accelTiltErrorTimerCounter = 0; ///< used for persistence requirement on tilt error + +static BOOL tiltErrorDetected; ///< Flag indicates a tilt error has been detected and tilt must now come below alarm clear threshold to clear alarm. +static BOOL shockErrorDetected; ///< Flag indicates a shock error has been detected and g-force must now come below alarm clear threshold to clear alarm. static ACCELEROMETER_SELF_TEST_STATE_T accelSelfTestState = ACCELEROMETER_SELF_TEST_STATE_START; ///< current accelerometer self-test state @@ -123,7 +126,10 @@ accelMaxs[ axis ].ovData = 0.0; accelMaxs[ axis ].ovInitData = 0.0; accelMaxs[ axis ].override = OVERRIDE_RESET; - } + } + + tiltErrorDetected = FALSE; + shockErrorDetected = FALSE; } /*********************************************************************//** @@ -477,17 +483,27 @@ { // excessive tilt must persist before triggering alarm if ( ++accelTiltErrorTimerCounter > MAX_TILT_PERSISTENCE ) - { + { + tiltErrorDetected = TRUE; #ifdef _DG_ SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_EXCESSIVE_TILT, x, y ) #else SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_EXCESSIVE_TILT, x, y ) #endif } + } + else if ( ( TRUE == tiltErrorDetected ) && ( fabs( x ) > MAX_TILT_ANGLE_TO_CLEAR_ALARM ) && ( fabs( y ) > MAX_TILT_ANGLE_TO_CLEAR_ALARM ) ) + { +#ifdef _DG_ + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_EXCESSIVE_TILT, x, y ) +#else + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_EXCESSIVE_TILT, x, y ) +#endif } else if ( ( fabs( x ) <= MAX_TILT_ANGLE_TO_CLEAR_ALARM ) && ( fabs( y ) <= MAX_TILT_ANGLE_TO_CLEAR_ALARM ) ) { - accelTiltErrorTimerCounter = 0; + accelTiltErrorTimerCounter = 0; + tiltErrorDetected = FALSE; #ifdef _DG_ clearAlarmCondition( ALARM_ID_DG_EXCESSIVE_TILT ); #else @@ -532,15 +548,25 @@ // has system just experienced an excessive shock? if ( maxAll > MAX_SHOCK_ACCELERATION ) - { + { + shockErrorDetected = TRUE; #ifdef _DG_ SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) #else SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) #endif } + else if ( ( TRUE == shockErrorDetected ) && ( maxAll > MAX_SHOCK_TO_CLEAR_ALARM ) ) + { +#ifdef _DG_ + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) +#else + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) +#endif + } else if ( maxAll <= MAX_SHOCK_TO_CLEAR_ALARM ) { + shockErrorDetected = FALSE; #ifdef _DG_ clearAlarmCondition( ALARM_ID_DG_SHOCK ); #else