from bbc microbit library

Dependencies:   BLE_API mbed-dev-bin nRF51822

Dependents:   microbit

Fork of microbit-dal by Lancaster University

Files at this revision

API Documentation at this revision

Comitter:
LancasterUniversity
Date:
Wed Jul 13 12:18:35 2016 +0100
Parent:
55:6920de8ba10a
Child:
57:290a35cb9981
Commit message:
Synchronized with git rev a3615605
Author: James Devine
microbit-dal: suppressed warning when the information service is disabled.

Changed in this revision

inc/drivers/MicroBitAccelerometer.h Show annotated file Show diff for this revision Revisions of this file
module.json Show annotated file Show diff for this revision Revisions of this file
source/bluetooth/MicroBitBLEManager.cpp Show annotated file Show diff for this revision Revisions of this file
source/drivers/MicroBitAccelerometer.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/inc/drivers/MicroBitAccelerometer.h	Wed Jul 13 12:18:34 2016 +0100
+++ b/inc/drivers/MicroBitAccelerometer.h	Wed Jul 13 12:18:35 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              500
+#define MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE              1000
 #define MICROBIT_ACCELEROMETER_3G_TOLERANCE                 3072
 #define MICROBIT_ACCELEROMETER_6G_TOLERANCE                 6144
 #define MICROBIT_ACCELEROMETER_8G_TOLERANCE                 8192
-#define MICROBIT_ACCELEROMETER_GESTURE_DAMPING              5
-#define MICROBIT_ACCELEROMETER_SHAKE_DAMPING                20
+#define MICROBIT_ACCELEROMETER_GESTURE_DAMPING              10
+#define MICROBIT_ACCELEROMETER_SHAKE_DAMPING                10
 
 #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:34 2016 +0100
+++ b/module.json	Wed Jul 13 12:18:35 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+mb4",
+    "mbed-classic": "lancaster-university/mbed-classic#microbit_hfclk+mb5",
     "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/bluetooth/MicroBitBLEManager.cpp	Wed Jul 13 12:18:34 2016 +0100
+++ b/source/bluetooth/MicroBitBLEManager.cpp	Wed Jul 13 12:18:35 2016 +0100
@@ -336,6 +336,8 @@
 
 #if CONFIG_ENABLED(MICROBIT_BLE_DEVICE_INFORMATION_SERVICE)
     DeviceInformationService ble_device_information_service (*ble, MICROBIT_BLE_MANUFACTURER, MICROBIT_BLE_MODEL, serialNumber.toCharArray(), MICROBIT_BLE_HARDWARE_VERSION, MICROBIT_BLE_FIRMWARE_VERSION, MICROBIT_BLE_SOFTWARE_VERSION);
+#else
+    (void)serialNumber;
 #endif
 
 #if CONFIG_ENABLED(MICROBIT_BLE_EVENT_SERVICE)
--- 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)
     {