Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
Revision 55:6920de8ba10a, committed 2016-07-13
- Comitter:
- LancasterUniversity
- Date:
- Wed Jul 13 12:18:34 2016 +0100
- Parent:
- 54:77d0b27f4f26
- Child:
- 56:1311cac15dda
- Commit message:
- Synchronized with git rev e53abf30
Author: Joe Finney
microbit: Updates to shake gesture recogniser to increase sensitivity [issue #145]
- Code cleanup of shake recogniser
- Increased sensitivity of shake gesture
- SHAKE event now raised on each shake detected
Changed in this revision
--- a/inc/drivers/MicroBitAccelerometer.h Wed Jul 13 12:18:33 2016 +0100 +++ b/inc/drivers/MicroBitAccelerometer.h Wed Jul 13 12:18:34 2016 +0100 @@ -97,12 +97,12 @@ #define MICROBIT_ACCELEROMETER_REST_TOLERANCE 200 #define MICROBIT_ACCELEROMETER_TILT_TOLERANCE 200 #define MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE 400 -#define MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE 1000 +#define MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE 500 #define MICROBIT_ACCELEROMETER_3G_TOLERANCE 3072 #define MICROBIT_ACCELEROMETER_6G_TOLERANCE 6144 #define MICROBIT_ACCELEROMETER_8G_TOLERANCE 8192 -#define MICROBIT_ACCELEROMETER_GESTURE_DAMPING 10 -#define MICROBIT_ACCELEROMETER_SHAKE_DAMPING 10 +#define MICROBIT_ACCELEROMETER_GESTURE_DAMPING 5 +#define MICROBIT_ACCELEROMETER_SHAKE_DAMPING 20 #define MICROBIT_ACCELEROMETER_REST_THRESHOLD (MICROBIT_ACCELEROMETER_REST_TOLERANCE * MICROBIT_ACCELEROMETER_REST_TOLERANCE) #define MICROBIT_ACCELEROMETER_FREEFALL_THRESHOLD (MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE * MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE)
--- a/module.json Wed Jul 13 12:18:33 2016 +0100
+++ b/module.json Wed Jul 13 12:18:34 2016 +0100
@@ -14,7 +14,7 @@
"author": "Joe Finney <j.finney@lancaster.ac.uk (mailto:j.finney@lancaster.ac.uk) >",
"homepage": "https://github.com/lancaster-university/microbit-dal/",
"dependencies": {
- "mbed-classic": "lancaster-university/mbed-classic#microbit_hfclk+mb5",
+ "mbed-classic": "lancaster-university/mbed-classic#microbit_hfclk+mb4",
"ble": "lancaster-university/BLE_API#v2.5.0+mb3",
"ble-nrf51822": "lancaster-university/nrf51822#v2.5.0+mb6",
"nrf51-sdk": "lancaster-university/nrf51-sdk#v2.2.0+mb4"
--- a/source/drivers/MicroBitAccelerometer.cpp Wed Jul 13 12:18:33 2016 +0100
+++ b/source/drivers/MicroBitAccelerometer.cpp Wed Jul 13 12:18:34 2016 +0100
@@ -348,23 +348,37 @@
shake.z = !shake.z;
}
- if (shakeDetected && shake.count < MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD && ++shake.count == MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD)
- shake.shaken = 1;
-
- if (++shake.timer >= MICROBIT_ACCELEROMETER_SHAKE_DAMPING)
+ if (shakeDetected && shake.count < MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD)
{
- shake.timer = 0;
- if (shake.count > 0)
+ shake.count++;
+
+ if (shake.count == 1)
+ shake.timer = 0;
+
+ if (shake.count == MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD)
+ shake.shaken = 1;
+ }
+
+ if (shake.count > 0)
+ {
+ shake.timer++;
+
+ if (shake.timer >= MICROBIT_ACCELEROMETER_SHAKE_DAMPING)
{
- if(--shake.count == 0)
- shake.shaken = 0;
+ shake.timer = 0;
+ if (shake.count > 0)
+ shake.count--;
}
}
// Shake events take the highest priority, as under high levels of change, other events
// are likely to be transient.
if (shake.shaken)
+ {
+ shake.shaken = 0;
+ shake.count = 0;
return MICROBIT_ACCELEROMETER_EVT_SHAKE;
+ }
if (instantaneousAccelerationSquared() < MICROBIT_ACCELEROMETER_FREEFALL_THRESHOLD)
return MICROBIT_ACCELEROMETER_EVT_FREEFALL;
@@ -433,6 +447,12 @@
// Determine what it looks like we're doing based on the latest sample...
uint16_t g = instantaneousPosture();
+ if (g == MICROBIT_ACCELEROMETER_EVT_SHAKE)
+ {
+ MicroBitEvent e(MICROBIT_ID_GESTURE, MICROBIT_ACCELEROMETER_EVT_SHAKE);
+ return;
+ }
+
// Perform some low pass filtering to reduce jitter from any detected effects
if (g == currentGesture)
{
