updates

Dependencies:   BLE_API mbed-dev-bin nRF51822

Fork of microbit-dal-eddystone by Martin Woolley

Files at this revision

API Documentation at this revision

Comitter:
LancasterUniversity
Date:
Wed Jul 13 12:17:53 2016 +0100
Parent:
20:ad2a5c7debf4
Child:
22:23d7b9a4b082
Commit message:
Synchronized with git rev 87f7233a
Author: Martin Woolley
Added BLE connect/disconnect events and fixed bug in MagnetometerService re: bearing characteristic

Changed in this revision

inc/bluetooth/ExternalEvents.h Show annotated file Show diff for this revision Revisions of this file
inc/drivers/MicroBitDisplay.h 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/bluetooth/MicroBitMagnetometerService.cpp Show annotated file Show diff for this revision Revisions of this file
source/drivers/MicroBitDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
source/drivers/MicroBitRadio.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/inc/bluetooth/ExternalEvents.h	Wed Jul 13 12:17:51 2016 +0100
+++ b/inc/bluetooth/ExternalEvents.h	Wed Jul 13 12:17:53 2016 +0100
@@ -33,6 +33,9 @@
 #define MICROBIT_ID_BLE             1000
 #define MICROBIT_ID_BLE_UART        1001
 
+#define MICROBIT_BLE_CONNECTED      1
+#define MICROBIT_BLE_DISCONNECTED   2
+
 #include "MESEvents.h"
 
-#endif
+#endif
\ No newline at end of file
--- a/inc/drivers/MicroBitDisplay.h	Wed Jul 13 12:17:51 2016 +0100
+++ b/inc/drivers/MicroBitDisplay.h	Wed Jul 13 12:17:53 2016 +0100
@@ -44,7 +44,7 @@
 //
 // Internal constants
 //
-#define MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR      1
+
 #define MICROBIT_DISPLAY_SPACING                1
 #define MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH    8
 #define MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS    -255
@@ -56,7 +56,6 @@
     ANIMATION_MODE_PRINT_TEXT,
     ANIMATION_MODE_SCROLL_IMAGE,
     ANIMATION_MODE_ANIMATE_IMAGE,
-    ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR,
     ANIMATION_MODE_PRINT_CHARACTER
 };
 
@@ -464,8 +463,6 @@
       * @param startingPosition the starting position on the display for the animation
       *                         to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
       *
-      * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
-      *
       * @return MICROBIT_OK, MICROBIT_BUSY if the screen is in use, or MICROBIT_INVALID_PARAMETER.
       *
       * @code
@@ -477,7 +474,7 @@
       * display.animateAsync(i,100,5);
       * @endcode
       */
-    int animateAsync(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, int autoClear = MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR);
+    int animateAsync(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS);
 
     /**
       * "Animates" the current image across the display with a given stride, finishing on the last frame of the animation.
@@ -491,8 +488,6 @@
       * @param startingPosition the starting position on the display for the animation
       *                         to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
       *
-      * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
-      *
       * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER.
       *
       * @code
@@ -504,7 +499,7 @@
       * display.animate(i,100,5);
       * @endcode
       */
-    int animate(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, int autoClear = MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR);
+    int animate(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS);
 
     /**
       * Configures the brightness of the display.
--- a/source/bluetooth/MicroBitBLEManager.cpp	Wed Jul 13 12:17:51 2016 +0100
+++ b/source/bluetooth/MicroBitBLEManager.cpp	Wed Jul 13 12:17:53 2016 +0100
@@ -109,6 +109,8 @@
   */
 static void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *reason)
 {
+    MicroBitEvent(MICROBIT_ID_BLE,MICROBIT_BLE_DISCONNECTED);
+    
     storeSystemAttributes(reason->handle);
 
     if (manager)
@@ -116,6 +118,14 @@
 }
 
 /**
+  * Callback when a BLE connection is established.
+  */
+static void bleConnectionCallback(const Gap::ConnectionCallbackParams_t *params)
+{
+    MicroBitEvent(MICROBIT_ID_BLE,MICROBIT_BLE_CONNECTED);
+}
+
+/**
   * Callback when a BLE SYS_ATTR_MISSING.
   */
 static void bleSysAttrMissingCallback(const GattSysAttrMissingCallbackParams *params)
@@ -267,6 +277,9 @@
     // automatically restart advertising after a device disconnects.
     ble->gap().onDisconnection(bleDisconnectionCallback);
     ble->gattServer().onSysAttrMissing(bleSysAttrMissingCallback);
+    
+    // generate an event when a Bluetooth connection is lost
+    ble->gap().onConnection(bleConnectionCallback);
 
     // Configure the stack to hold onto the CPU during critical timing events.
     // mbed-classic performs __disable_irq() calls in its timers that can cause
@@ -599,4 +612,4 @@
         for (int j=0; j<h+1; j++)
             display.image.setPixelValue(MICROBIT_DFU_HISTOGRAM_WIDTH-i-1, MICROBIT_DFU_HISTOGRAM_HEIGHT-j-1, 255);
     }
-}
+}
\ No newline at end of file
--- a/source/bluetooth/MicroBitMagnetometerService.cpp	Wed Jul 13 12:17:51 2016 +0100
+++ b/source/bluetooth/MicroBitMagnetometerService.cpp	Wed Jul 13 12:17:53 2016 +0100
@@ -74,7 +74,7 @@
     magnetometerPeriodCharacteristicHandle = magnetometerPeriodCharacteristic.getValueHandle();
 
     ble.gattServer().notify(magnetometerDataCharacteristicHandle,(uint8_t *)magnetometerDataCharacteristicBuffer, sizeof(magnetometerDataCharacteristicBuffer));
-    ble.gattServer().notify(magnetometerBearingCharacteristicHandle,(uint8_t *)&magnetometerBearingCharacteristicBuffer, sizeof(magnetometerDataCharacteristicBuffer));
+    ble.gattServer().notify(magnetometerBearingCharacteristicHandle,(uint8_t *)&magnetometerBearingCharacteristicBuffer, sizeof(magnetometerBearingCharacteristicBuffer));
     ble.gattServer().write(magnetometerPeriodCharacteristicHandle, (const uint8_t *)&magnetometerPeriodCharacteristicBuffer, sizeof(magnetometerPeriodCharacteristicBuffer));
 
     ble.onDataWritten(this, &MicroBitMagnetometerService::onDataWritten);
@@ -153,4 +153,4 @@
 
 const uint8_t  MicroBitMagnetometerServiceBearingUUID[] = {
     0xe9,0x5d,0x97,0x15,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
-};
+};
\ No newline at end of file
--- a/source/drivers/MicroBitDisplay.cpp	Wed Jul 13 12:17:51 2016 +0100
+++ b/source/drivers/MicroBitDisplay.cpp	Wed Jul 13 12:17:53 2016 +0100
@@ -287,7 +287,7 @@
         if (animationMode == ANIMATION_MODE_SCROLL_IMAGE)
             this->updateScrollImage();
 
-        if (animationMode == ANIMATION_MODE_ANIMATE_IMAGE || animationMode == ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR)
+        if (animationMode == ANIMATION_MODE_ANIMATE_IMAGE)
             this->updateAnimateImage();
 
         if(animationMode == ANIMATION_MODE_PRINT_CHARACTER)
@@ -384,11 +384,8 @@
     //wait until we have rendered the last position to give a continuous animation.
     if (scrollingImagePosition <= -scrollingImage.getWidth() + (MICROBIT_DISPLAY_WIDTH + scrollingImageStride) && scrollingImageRendered)
     {
-        if (animationMode == ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR)
-            this->clear();
-
         animationMode = ANIMATION_MODE_NONE;
-
+        this->clear();
         this->sendAnimationCompleteEvent();
         return;
     }
@@ -894,8 +891,6 @@
   * @param startingPosition the starting position on the display for the animation
   *                         to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
   *
-  * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
-  *
   * @return MICROBIT_OK, MICROBIT_BUSY if the screen is in use, or MICROBIT_INVALID_PARAMETER.
   *
   * @code
@@ -907,7 +902,7 @@
   * display.animateAsync(i,100,5);
   * @endcode
   */
-int MicroBitDisplay::animateAsync(MicroBitImage image, int delay, int stride, int startingPosition, int autoClear)
+int MicroBitDisplay::animateAsync(MicroBitImage image, int delay, int stride, int startingPosition)
 {
     //sanitise the delay value
     if(delay <= 0)
@@ -927,7 +922,7 @@
 
         animationDelay = stride == 0 ? 0 : delay;
         animationTick = delay-1;
-        animationMode = autoClear ? ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR : ANIMATION_MODE_ANIMATE_IMAGE;
+        animationMode = ANIMATION_MODE_ANIMATE_IMAGE;
     }
     else
     {
@@ -949,8 +944,6 @@
   * @param startingPosition the starting position on the display for the animation
   *                         to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
   *
-  * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
-  *
   * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER.
   *
   * @code
@@ -962,7 +955,7 @@
   * display.animate(i,100,5);
   * @endcode
   */
-int MicroBitDisplay::animate(MicroBitImage image, int delay, int stride, int startingPosition, int autoClear)
+int MicroBitDisplay::animate(MicroBitImage image, int delay, int stride, int startingPosition)
 {
     //sanitise the delay value
     if(delay <= 0)
@@ -976,7 +969,7 @@
     if (animationMode == ANIMATION_MODE_NONE)
     {
         // Start the effect.
-        this->animateAsync(image, delay, stride, startingPosition, autoClear);
+        this->animateAsync(image, delay, stride, startingPosition);
 
         // Wait for completion.
         //TODO: Put this in when we merge tight-validation
--- a/source/drivers/MicroBitRadio.cpp	Wed Jul 13 12:17:51 2016 +0100
+++ b/source/drivers/MicroBitRadio.cpp	Wed Jul 13 12:17:53 2016 +0100
@@ -99,7 +99,7 @@
 {
     this->id = id;
     this->status = 0;
-	this->group = MICROBIT_RADIO_DEFAULT_GROUP;
+	this->group = 0;
 	this->queueDepth = 0;
     this->rssi = 0;
     this->rxQueue = NULL;
@@ -279,7 +279,7 @@
     NRF_RADIO->BASE0 = MICROBIT_RADIO_BASE_ADDRESS;
 
     // Join the default group. This will configure the remaining byte in the RADIO hardware module.
-    setGroup(this->group);
+    setGroup(MICROBIT_RADIO_DEFAULT_GROUP);
 
     // The RADIO hardware module supports the use of multiple addresses, but as we're running anonymously, we only need one.
     // Configure the RADIO module to use the default address (address 0) for both send and receive operations.
@@ -356,9 +356,6 @@
     // deregister ourselves from the callback event used to empty the receive queue.
     fiber_remove_idle_component(this);
 
-    // record that the radio is now disabled
-    status &= ~MICROBIT_RADIO_STATUS_INITIALISED;
-
     return MICROBIT_OK;
 }