Small Demo demonstrating BLE Advertising

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Files at this revision

API Documentation at this revision

Comitter:
hux
Date:
Sat May 19 15:53:19 2018 +0000
Parent:
28:114eaad388c1
Commit message:
Published

Changed in this revision

BLE_API.lib Show annotated file Show diff for this revision Revisions of this file
Readme.md Show annotated file Show diff for this revision Revisions of this file
X_NUCLEO_IDB0XA1.lib Show annotated file Show diff for this revision Revisions of this file
bricks/blink.cpp Show annotated file Show diff for this revision Revisions of this file
bricks/blink.h Show annotated file Show diff for this revision Revisions of this file
bricks/blob.h Show annotated file Show diff for this revision Revisions of this file
bricks/target.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF51822.lib Show diff for this revision Revisions of this file
--- a/BLE_API.lib	Sun Jan 08 23:13:25 2017 +0000
+++ b/BLE_API.lib	Sat May 19 15:53:19 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#bfc5b9b6ecf5
+http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#65474dc93927
--- a/Readme.md	Sun Jan 08 23:13:25 2017 +0000
+++ b/Readme.md	Sat May 19 15:53:19 2018 +0000
@@ -1,5 +1,5 @@
-N05_Advertising
+S05_Advertising
 
 Tested Platforms:
-   Nordic nRF51822-DK
+   NUCLEO L476RG
    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDB0XA1.lib	Sat May 19 15:53:19 2018 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/ST/code/X_NUCLEO_IDB0XA1/#fa98703ece8e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bricks/blink.cpp	Sat May 19 15:53:19 2018 +0000
@@ -0,0 +1,82 @@
+// blink.cpp - send a morse pattern to LED1
+//
+// Function morse() is one way for running LED1 with a blinking sequence using
+// a busy wait, until the sequence is completed.
+//
+//    morse(" x xxx x    ");        send one time morse sequence, interval = 0.2
+//    morse(" x xxx x    ",0.5);    send one time morse sequence, interval = 0.5
+//
+// Function morse() got the additional feature to stop an ongoing timer based
+// blinking sequence.
+//    
+// The alternative is to setup an ever repeating blink sequence via LED1 using
+// function blink(), which is non waiting.
+//
+//    blink(" x xxx x    ");        repeating blink sequence, interval = 0.2
+//    blink(" x xxx x    ",0.5);    repeating blink sequence, interval = 0.5
+//    blink(0);                     stops blinking sequence
+//
+
+#include "bricks/target.h"
+#include "bricks/blink.h"
+
+#ifndef LED_INVERTED
+#   define LED_ON  1
+#   define LED_OFF 0
+#else
+#   define LED_ON  0
+#   define LED_OFF 1
+#endif
+
+   static DigitalOut led(LED1);         // LED1, being used for morse sequence
+   static Ticker ticker;                // triggers periodic callbacks
+   static const char *pointer = 0;      // 0 means morse activity disabled
+   static const char *sequence = 0;     // next morse sequence for repeats
+       
+
+   void morse(const char *pattern, double interval)
+   {
+       pointer = 0;                     // disable ticker based blinking
+       sequence = 0;                    // set also empty sequence
+       
+       for (; *pattern; pattern++)
+       {
+          led = (*pattern == ' ') ? LED_OFF : LED_ON;
+          wait(interval);               // busy waiting for interval time
+       }
+   }
+          
+// callback for LED1 ticker controlled blinking   
+           
+   static void callback(void)
+   {
+       if (pointer != 0)
+      {
+         if (*pointer == 0)
+         {
+            pointer = sequence;         // reset pointer to followup sequence
+         }
+        
+         if (*pointer)
+         {
+            led = (*pointer++ == ' ') ? LED_OFF : LED_ON;
+         }
+      }
+   }
+   
+   void blink(const char *pattern, const char* next, double interval)
+   {
+      pointer = 0;                      // stop current activities
+      led = LED_OFF;                    // reset led with LED_OFF
+      
+      sequence = next;                  // init morse sequence   
+         
+      ticker.attach(callback,interval); // next LED state after every interval
+      pointer = pattern;                // enable callback activty
+   }  
+
+   void blink(const char *pattern, double interval)
+   {
+       blink(pattern,pattern,interval);
+   }
+   
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bricks/blink.h	Sat May 19 15:53:19 2018 +0000
@@ -0,0 +1,44 @@
+// blink.h - blinking sequences for LED1
+#ifndef _BLINK_H_
+#define _BLINK_H_
+
+#include <mbed.h>
+#include "bricks/o.h"
+
+#  define BLINK_SEQUENCE_IDLE         "x       "
+#  define BLINK_SEQUENCE_ADVERTISE    "x xxx       "
+#  define BLINK_SEQUENCE_CONNECTED    "  xxx       "
+#  define BLINK_SEQUENCE_ACTION       "x x x x x       "
+#  define BLINK_SEQUENCE_ERROR        "x x x x xxx "
+#  define BLINK_SEQUENCE_TRANSITION   "x x x   "
+
+   void morse(const char *pattern, double periode = 0.2);
+   void blink(const char *pattern, const char* next, double interval = 0.2);
+   void blink(const char *pattern, double periode = 0.2);
+
+   inline void blinkIdle(O&o)          // 'idle' blink sequence
+   {
+      blink(BLINK_SEQUENCE_IDLE);
+   }
+
+   inline void blinkAdvertise(O&o)     // 'advertise' blink sequence
+   {
+      blink(BLINK_SEQUENCE_ADVERTISE);
+   }
+   
+   inline void blinkConnected(O&o)     // 'connected' blink sequence
+   {
+      blink(BLINK_SEQUENCE_TRANSITION, BLINK_SEQUENCE_CONNECTED);
+   }
+
+   inline void blinkAction(O&o)        // 'action' blink sequence
+   {
+      blink(BLINK_SEQUENCE_ACTION, BLINK_SEQUENCE_IDLE);
+   }
+
+   inline void blinkError(O&o)         // 'error' blink sequence
+   {
+      blink(BLINK_SEQUENCE_ERROR);
+   }
+
+#endif // _BLINK_H_
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bricks/blob.h	Sat May 19 15:53:19 2018 +0000
@@ -0,0 +1,59 @@
+// blob.h - 'BLOBs' are BLuetooth OBjects
+#ifndef _BLOB_H_
+#define _BLOB_H_
+
+#include "ble/BLE.h"
+#include "ble/Gap.h"
+
+#define _ICCC BLE::InitializationCompleteCallbackContext   // pure short hand
+#define _GDCP Gap::DisconnectionCallbackParams_t           // pure short hand
+#define _GCCP Gap::ConnectionCallbackParams_t              // pure short hand
+#define _GWCP GattWriteCallbackParams                      // pure short hand
+
+   class Blob : public BLE
+   {
+      public:
+         const _ICCC *pComplete;              // params to _ICCC context
+         const _GCCP *pConnect;               // params to _GCCP context
+         const _GDCP *pDisconnect;            // params to _GDPC context
+         const _GWCP *pWritten;               // params to _GWCP context
+         
+      public: // construction
+         Blob() : BLE() // standard constructor
+         {
+            pComplete = 0;  pDisconnect = 0;
+         }
+   };
+
+
+// Setup Advertising Name (syntactic sugar)
+
+   inline void name(Blob &o, const char *str)
+   {
+      o.gap().accumulateAdvertisingPayload(
+        GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)str, strlen(str)+1);
+   }
+
+
+// Setup Device Name (syntactic sugar)
+
+   inline void device(Blob &o, const char *text)
+   {
+      o.gap().setDeviceName((const uint8_t *)text);
+   }
+
+
+// Setup Advertising Data (syntactic sugar)
+
+   inline void data(Blob &o, const uint8_t *buf, size_t buflen)
+   {
+      o.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, buf, buflen);
+   }
+
+   inline void data(Blob &o, const char *text)
+   {
+      size_t len = strlen(text);
+      data(o,(const uint8_t*)text,len);
+   }
+   
+#endif // _BLOB_H_
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bricks/target.h	Sat May 19 15:53:19 2018 +0000
@@ -0,0 +1,19 @@
+// bricks/target.h - define target specifics
+
+#ifndef _BRICKS_TARGET_H_
+#define _BRICKS_TARGET_H_
+
+// platform specific defines - comment out platforms which are not used
+// We work only with two kinds of platform:
+//
+//    a) a NUCLEO platform from STMicroelectronics
+//    b) a nRF51 platform from Nordic Semiconductor
+//
+// If we have not a nRF51 target then we coclude it is a NUCLEO target. This is
+// not really clean, but under above assumptions it works so far!
+
+#ifdef TARGET_NRF51822 
+#   define LED_INVERTED          // inverted LED for nRF51 targets
+#endif
+
+#endif // _BRICKS_TARGET_H_
--- a/main.cpp	Sun Jan 08 23:13:25 2017 +0000
+++ b/main.cpp	Sat May 19 15:53:19 2018 +0000
@@ -1,5 +1,5 @@
-// N05_Advertising: Tutorial for demonstration of simple advertising
-// Program has been tested on nRF51822-DK
+// S05_Advertising: Tutorial for demonstration of simple advertising
+// Program has been tested on NUCLEO-L476RG
  
 #include "bricks/bricks.h"
 
@@ -33,7 +33,7 @@
    void cbSetup(O&o)                   // setup calback (after BLE init)
    {
       device(o,DEVICE_NAME);           // setup device name
-      name(o,"N05#1.0 Advertise");     // add name to device
+      name(o,"S05#1.0 Advertise");     // add name to device
       data(o,AdvData,sizeof(AdvData)); // advertising user data
 
       onDisconnect(o,cbDisconnect);    // setup disconnection callback
--- a/mbed.bld	Sun Jan 08 23:13:25 2017 +0000
+++ b/mbed.bld	Sat May 19 15:53:19 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/2e9cc70d1897
\ No newline at end of file
--- a/nRF51822.lib	Sun Jan 08 23:13:25 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#3cc0718d98d0