Index: Accel.c =================================================================== diff -u -ra01190e166f07e7481334b3a15704e4e96e241d4 -raedb21f0b764ae1dd543c1ca0bc4bbf318dfdafd --- Accel.c (.../Accel.c) (revision a01190e166f07e7481334b3a15704e4e96e241d4) +++ Accel.c (.../Accel.c) (revision aedb21f0b764ae1dd543c1ca0bc4bbf318dfdafd) @@ -85,6 +85,9 @@ 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 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 @@ -124,6 +127,9 @@ accelMaxs[ axis ].ovInitData = 0.0; accelMaxs[ axis ].override = OVERRIDE_RESET; } + + tiltErrorDetected = FALSE; + shockErrorDetected = FALSE; } /*********************************************************************//** @@ -478,16 +484,26 @@ // 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; + tiltErrorDetected = FALSE; #ifdef _DG_ clearAlarm( ALARM_ID_DG_EXCESSIVE_TILT ); #else @@ -533,14 +549,24 @@ // 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