iotio

Fork of Nucleo_BLE_DemoApp by Cortex Challenge Team

Committer:
berlingeradam
Date:
Wed May 27 18:39:23 2015 +0000
Revision:
1:fd7adeffebbe
Parent:
0:866f2c528c01
Child:
2:510cac0a0250
Factory function for easy initialization

Who changed what in which revision?

UserRevisionLine numberNew contents of line
berlingeradam 0:866f2c528c01 1 #include "DemoAppService.h"
berlingeradam 0:866f2c528c01 2
berlingeradam 1:fd7adeffebbe 3
berlingeradam 1:fd7adeffebbe 4 #include "mbed.h"
berlingeradam 1:fd7adeffebbe 5 #include "BLEDevice.h"
berlingeradam 1:fd7adeffebbe 6 #include "DeviceInformationService.h"
berlingeradam 1:fd7adeffebbe 7 #include "UARTService.h"
berlingeradam 1:fd7adeffebbe 8 #include "Utils.h"
berlingeradam 1:fd7adeffebbe 9
berlingeradam 0:866f2c528c01 10 const uint8_t DemoAppService::ServiceUUID[LENGTH_OF_LONG_UUID] = {
berlingeradam 0:866f2c528c01 11 0x6E, 0x40, 0x00, 0x10, 0xB5, 0xA3, 0xF3, 0x93,
berlingeradam 0:866f2c528c01 12 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
berlingeradam 0:866f2c528c01 13 };
berlingeradam 0:866f2c528c01 14
berlingeradam 0:866f2c528c01 15 const uint8_t DemoAppService::buttonCharacteristicUUID[LENGTH_OF_LONG_UUID] = {
berlingeradam 0:866f2c528c01 16 0x6E, 0x40, 0x00, 0x11, 0xB5, 0xA3, 0xF3, 0x93,
berlingeradam 0:866f2c528c01 17 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
berlingeradam 0:866f2c528c01 18 };
berlingeradam 0:866f2c528c01 19
berlingeradam 0:866f2c528c01 20 const uint8_t DemoAppService::slider1CharacteristicUUID[LENGTH_OF_LONG_UUID] = {
berlingeradam 0:866f2c528c01 21 0x6E, 0x40, 0x00, 0x12, 0xB5, 0xA3, 0xF3, 0x93,
berlingeradam 0:866f2c528c01 22 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
berlingeradam 0:866f2c528c01 23 };
berlingeradam 0:866f2c528c01 24
berlingeradam 0:866f2c528c01 25 const uint8_t DemoAppService::slider2CharacteristicUUID[LENGTH_OF_LONG_UUID] = {
berlingeradam 0:866f2c528c01 26 0x6E, 0x40, 0x00, 0x13, 0xB5, 0xA3, 0xF3, 0x93,
berlingeradam 0:866f2c528c01 27 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
berlingeradam 1:fd7adeffebbe 28 };
berlingeradam 1:fd7adeffebbe 29
berlingeradam 1:fd7adeffebbe 30 static BLEDevice *ble;
berlingeradam 1:fd7adeffebbe 31
berlingeradam 1:fd7adeffebbe 32 /* Callback called when the device is disconnected */
berlingeradam 1:fd7adeffebbe 33 static void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
berlingeradam 1:fd7adeffebbe 34 {
berlingeradam 1:fd7adeffebbe 35 DEBUG("Disconnected!\n\r");
berlingeradam 1:fd7adeffebbe 36 DEBUG("Restarting the advertising process\n\r");
berlingeradam 1:fd7adeffebbe 37
berlingeradam 1:fd7adeffebbe 38 ble->startAdvertising();
berlingeradam 1:fd7adeffebbe 39 //connected = false;
berlingeradam 1:fd7adeffebbe 40 }
berlingeradam 1:fd7adeffebbe 41
berlingeradam 1:fd7adeffebbe 42 /* Callback called when the device is connected */
berlingeradam 1:fd7adeffebbe 43 static void connectionCallback(Gap::Handle_t handle, const Gap::ConnectionParams_t *reason)
berlingeradam 1:fd7adeffebbe 44 {
berlingeradam 1:fd7adeffebbe 45 DEBUG("Connected\r\n");
berlingeradam 1:fd7adeffebbe 46
berlingeradam 1:fd7adeffebbe 47 //connected = true;
berlingeradam 1:fd7adeffebbe 48 }
berlingeradam 1:fd7adeffebbe 49
berlingeradam 1:fd7adeffebbe 50 const static char DEVICE_NAME[] = "BlueNRG_UART";
berlingeradam 1:fd7adeffebbe 51 DemoAppService *startDemoBLE(const char* name){
berlingeradam 1:fd7adeffebbe 52 ble = new BLEDevice();
berlingeradam 1:fd7adeffebbe 53 ble->init();
berlingeradam 1:fd7adeffebbe 54 /* Set callback functions */
berlingeradam 1:fd7adeffebbe 55 ble->onDisconnection(disconnectionCallback);
berlingeradam 1:fd7adeffebbe 56 ble->onConnection(connectionCallback);
berlingeradam 1:fd7adeffebbe 57
berlingeradam 1:fd7adeffebbe 58 DeviceInformationService deviceInfo(*ble, "ST", "Nucleo", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
berlingeradam 1:fd7adeffebbe 59 /* setup advertising */
berlingeradam 1:fd7adeffebbe 60 ble->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
berlingeradam 1:fd7adeffebbe 61 ble->setAdvertisingType (GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
berlingeradam 1:fd7adeffebbe 62
berlingeradam 1:fd7adeffebbe 63 //ble->accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME , (const uint8_t *)"BlueNRG_UART" , sizeof("BlueNRG_UART") - 1);
berlingeradam 1:fd7adeffebbe 64 //ble->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
berlingeradam 1:fd7adeffebbe 65 ble->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME , (uint8_t *)name , strlen(name)+1);
berlingeradam 1:fd7adeffebbe 66
berlingeradam 1:fd7adeffebbe 67 /* Start advertising */
berlingeradam 1:fd7adeffebbe 68 ble->setAdvertisingInterval(160);
berlingeradam 1:fd7adeffebbe 69 ble->startAdvertising();
berlingeradam 1:fd7adeffebbe 70
berlingeradam 1:fd7adeffebbe 71 return new DemoAppService(*ble);
berlingeradam 1:fd7adeffebbe 72 }