![](/media/cache/profiles/f8936fbd065f5b9fdb3149eaba9665df.50x50_q85.jpg)
Simple program to enable me to write to a 128x64 OLED display over BLE
Dependencies: Adafruit_GFX BLE_API mbed nRF51822 SemVer
Diff: main.cpp
- Revision:
- 1:9e9c52d8270a
- Parent:
- 0:d89c10040630
diff -r d89c10040630 -r 9e9c52d8270a main.cpp --- 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);