From 3416e54a3640c11efb425c1dfb168a18b9b65e1e Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Tue, 5 Jan 2016 16:23:47 +0000 Subject: [PATCH] microbit: increase sensitivity of freefall detection Freefall now detected when the net force on the device drops below 0.4g, rather than 0.2g as previously defined. This improves sensitivity, without generating false positives under common use. Also correction of minor typos / layout errors. --- inc/MicroBitAccelerometer.h | 2 +- source/MicroBitAccelerometer.cpp | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/inc/MicroBitAccelerometer.h b/inc/MicroBitAccelerometer.h index d566dc7..b826708 100644 --- a/inc/MicroBitAccelerometer.h +++ b/inc/MicroBitAccelerometer.h @@ -61,7 +61,7 @@ */ #define MICROBIT_ACCELEROMETER_REST_TOLERANCE 200 #define MICROBIT_ACCELEROMETER_TILT_TOLERANCE 200 -#define MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE 200 +#define MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE 400 #define MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE 1000 #define MICROBIT_ACCELEROMETER_3G_TOLERANCE 3072 #define MICROBIT_ACCELEROMETER_6G_TOLERANCE 6144 diff --git a/source/MicroBitAccelerometer.cpp b/source/MicroBitAccelerometer.cpp index f22f18b..3c0f587 100644 --- a/source/MicroBitAccelerometer.cpp +++ b/source/MicroBitAccelerometer.cpp @@ -237,8 +237,7 @@ int MicroBitAccelerometer::update() * * @return the sum of the square of the acceleration of the device across all axes. */ - int -MicroBitAccelerometer::instantaneousAccelerationSquared() +int MicroBitAccelerometer::instantaneousAccelerationSquared() { // Use pythagoras theorem to determine the combined force acting on the device. return (int)sample.x*(int)sample.x + (int)sample.y*(int)sample.y + (int)sample.z*(int)sample.z; @@ -250,8 +249,7 @@ MicroBitAccelerometer::instantaneousAccelerationSquared() * * @return A best guess of the current posture of the device, based on instantaneous data. */ - BasicGesture -MicroBitAccelerometer::instantaneousPosture() +BasicGesture MicroBitAccelerometer::instantaneousPosture() { int force = instantaneousAccelerationSquared(); bool shakeDetected = false; @@ -297,7 +295,7 @@ MicroBitAccelerometer::instantaneousPosture() return GESTURE_SHAKE; if (force < MICROBIT_ACCELEROMETER_FREEFALL_THRESHOLD) - return FREEFALL; + return GESTURE_FREEFALL; if (force > MICROBIT_ACCELEROMETER_3G_THRESHOLD) return GESTURE_3G; @@ -330,8 +328,7 @@ MicroBitAccelerometer::instantaneousPosture() return GESTURE_NONE; } - void -MicroBitAccelerometer::updateGesture() +void MicroBitAccelerometer::updateGesture() { // Determine what it looks like we're doing based on the latest sample... BasicGesture g = instantaneousPosture();