Simple bluetooth low energy service, featuring three characteristics - two sliders and one button
Fork of Nucleo_BLE_DemoApp by
Diff: DemoAppService.cpp
- Revision:
- 1:fd7adeffebbe
- Parent:
- 0:866f2c528c01
- Child:
- 2:510cac0a0250
diff -r 866f2c528c01 -r fd7adeffebbe DemoAppService.cpp --- a/DemoAppService.cpp Sun May 10 15:41:38 2015 +0000 +++ b/DemoAppService.cpp Wed May 27 18:39:23 2015 +0000 @@ -1,5 +1,12 @@ #include "DemoAppService.h" + +#include "mbed.h" +#include "BLEDevice.h" +#include "DeviceInformationService.h" +#include "UARTService.h" +#include "Utils.h" + const uint8_t DemoAppService::ServiceUUID[LENGTH_OF_LONG_UUID] = { 0x6E, 0x40, 0x00, 0x10, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, @@ -18,4 +25,48 @@ const uint8_t DemoAppService::slider2CharacteristicUUID[LENGTH_OF_LONG_UUID] = { 0x6E, 0x40, 0x00, 0x13, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, -}; \ No newline at end of file +}; + +static BLEDevice *ble; + +/* Callback called when the device is disconnected */ +static void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) +{ + DEBUG("Disconnected!\n\r"); + DEBUG("Restarting the advertising process\n\r"); + + ble->startAdvertising(); + //connected = false; +} + +/* Callback called when the device is connected */ +static void connectionCallback(Gap::Handle_t handle, const Gap::ConnectionParams_t *reason) +{ + DEBUG("Connected\r\n"); + + //connected = true; +} + +const static char DEVICE_NAME[] = "BlueNRG_UART"; +DemoAppService *startDemoBLE(const char* name){ + ble = new BLEDevice(); + ble->init(); +/* Set callback functions */ + ble->onDisconnection(disconnectionCallback); + ble->onConnection(connectionCallback); + + DeviceInformationService deviceInfo(*ble, "ST", "Nucleo", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); + /* setup advertising */ + ble->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); + ble->setAdvertisingType (GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + + //ble->accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME , (const uint8_t *)"BlueNRG_UART" , sizeof("BlueNRG_UART") - 1); + //ble->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); + ble->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME , (uint8_t *)name , strlen(name)+1); + + /* Start advertising */ + ble->setAdvertisingInterval(160); + ble->startAdvertising(); + + return new DemoAppService(*ble); +} \ No newline at end of file