diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2015-01-29 11:20:11 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2015-01-29 11:20:11 +0100 |
commit | af4ea653a341f3c25cfbb2e7ec4b633bf73913a7 (patch) | |
tree | 4a9e4a50a123c6c04f5e571bf39d900d46b90315 | |
parent | 9528470d8389840618275814c30e4f64a9e3efa7 (diff) | |
download | hourglass-af4ea653a341f3c25cfbb2e7ec4b633bf73913a7.tar.gz hourglass-af4ea653a341f3c25cfbb2e7ec4b633bf73913a7.tar.bz2 hourglass-af4ea653a341f3c25cfbb2e7ec4b633bf73913a7.zip |
accel: Ignore shake if horizon changed
-rw-r--r-- | accel.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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; } } |