test

Dependencies:   BLE_API mbed-dev-bin nRF51822

Fork of microbit-dal by Lancaster University

Revision:
55:6920de8ba10a
Parent:
43:0374ea4d2167
Child:
56:1311cac15dda
--- 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)
     {