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.
This commit is contained in:
Joe Finney 2016-01-05 16:23:47 +00:00
parent 17632adafa
commit 3416e54a36
2 changed files with 5 additions and 8 deletions

View file

@ -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

View file

@ -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();