Simple program to enable me to write to a 128x64 OLED display over BLE

Dependencies:   Adafruit_GFX BLE_API mbed nRF51822 SemVer

Files at this revision

API Documentation at this revision

Comitter:
rosterloh84
Date:
Mon Mar 30 13:23:29 2015 +0000
Parent:
0:d89c10040630
Commit message:
added version support and device info

Changed in this revision

SemVer.lib 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SemVer.lib	Mon Mar 30 13:23:29 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/rosterloh84/code/SemVer/#91466b3b925e
--- a/main.cpp	Mon Mar 30 10:06:34 2015 +0000
+++ b/main.cpp	Mon Mar 30 13:23:29 2015 +0000
@@ -6,19 +6,23 @@
  
 #include "mbed.h"
 #include "BLEDevice.h"
+#include "DeviceInformationService.h"
 #include "UARTService.h"
 
 #include "Adafruit_SSD1306.h"
+#include "SemVer.h"
 
 #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console;
                                * it will have an impact on code-size and power consumption. */
 
 #if NEED_CONSOLE_OUTPUT
-#define DEBUG(STR) { if (uartServicePtr) uartServicePtr->writeString(STR); }
+#define DEBUG(...) { if (uartServicePtr) uartServicePtr->writeString(__VA_ARGS__); }
 #else
 #define DEBUG(...) /* nothing */
 #endif /* #if NEED_CONSOLE_OUTPUT */
 
+SemVer version("1.0.0");
+
 BLEDevice  ble;
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
@@ -50,8 +54,9 @@
 
 UARTService *uartServicePtr;
 
-const char *deviceName = "BLE DISPLAY";
-
+const static char     DEVICE_NAME[] = "BLE DISPLAY";
+static const uint16_t uuid16_list[] = {GattService::UUID_DEVICE_INFORMATION_SERVICE};
+                    
 /**
  *  Callback to write to connected client and display
  */
@@ -138,14 +143,14 @@
     ble.onDisconnection(disconnectionCallback);
     ble.onDataWritten(onDataWritten);
     
+    DeviceInformationService deviceInfo(ble, "NORDIC", "NRF51-DK", DEVICE_NAME, "HW-00", version.getVersion().c_str());
+    
     /* setup advertising */
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)deviceName, strlen(deviceName));
-    /*ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
-                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));*/
-
-    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
+    ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(100));
     ble.startAdvertising();
 
     UARTService uartService(ble);