test

Dependencies:   BLE_API mbed-dev-bin nRF51822

Fork of microbit-dal by Lancaster University

Revision:
56:1311cac15dda
Parent:
55:6920de8ba10a
Child:
65:f7ebabf23e15
--- a/source/drivers/MicroBitAccelerometer.cpp	Wed Jul 13 12:18:34 2016 +0100
+++ b/source/drivers/MicroBitAccelerometer.cpp	Wed Jul 13 12:18:35 2016 +0100
@@ -348,37 +348,23 @@
         shake.z = !shake.z;
     }
 
-    if (shakeDetected && shake.count < MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD)
-    {
-        shake.count++;
-  
-        if (shake.count == 1)
-            shake.timer = 0;
+    if (shakeDetected && shake.count < MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD && ++shake.count == MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD)
+        shake.shaken = 1;
 
-        if (shake.count == MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD)
-            shake.shaken = 1;
-    }
-
-    if (shake.count > 0)
+    if (++shake.timer >= MICROBIT_ACCELEROMETER_SHAKE_DAMPING)
     {
-        shake.timer++;
-
-        if (shake.timer >= MICROBIT_ACCELEROMETER_SHAKE_DAMPING)
+        shake.timer = 0;
+        if (shake.count > 0)
         {
-            shake.timer = 0;
-            if (shake.count > 0)
-                shake.count--;
+            if(--shake.count == 0)
+                shake.shaken = 0;
         }
     }
 
     // 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;
@@ -447,12 +433,6 @@
     // 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)
     {