From af4ea653a341f3c25cfbb2e7ec4b633bf73913a7 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 29 Jan 2015 11:20:11 +0100 Subject: accel: Ignore shake if horizon changed --- accel.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'accel.c') diff --git a/accel.c b/accel.c index f3f0ce2..9f38e8e 100644 --- a/accel.c +++ b/accel.c @@ -25,7 +25,7 @@ /* offset for horizon detection */ #define ACCEL_1G_OFF (5) /* threshold starting shake detection */ -#define ACCEL_SHAKE_START (70) +#define ACCEL_SHAKE_START (90) /* difference prev and current value to get the current one registered as peak */ #define ACCEL_SHAKE_REGISTER (120) /* 100ms for 100Hz data rate */ @@ -42,6 +42,7 @@ static uint8_t shakeCount = 0; static uint8_t shakeTimeout = 0; static int16_t prevShakeVal = 0; static uint8_t peakCount = 0; +static horizon shakeHorizon = HORIZON_NONE; /* horizon position */ /* current */ @@ -100,7 +101,12 @@ void accelStart () { static void accelProcessShake () { if (shakeTimeout > 0) { --shakeTimeout; - if (sign (prevShakeVal) != sign (zvalnormal) && + if (horizonSign != shakeHorizon) { + /* ignore if horizon changed */ + shakeTimeout = 0; + prevShakeVal = 0; + peakCount = 0; + } else if (sign (prevShakeVal) != sign (zvalnormal) && abs (prevShakeVal - zvalnormal) >= ACCEL_SHAKE_REGISTER) { ++peakCount; shakeTimeout = ACCEL_SHAKE_TIMEOUT; @@ -124,6 +130,7 @@ static void accelProcessShake () { shakeTimeout = ACCEL_SHAKE_TIMEOUT; peakCount = 1; prevShakeVal = zvalnormal; + shakeHorizon = horizonSign; } } -- cgit v1.2.3