Simple bluetooth low energy service, featuring three characteristics - two sliders and one button

Fork of Nucleo_BLE_DemoApp by Cortex Challenge Team

DemoAppService.cpp

Committer:
berlingeradam
Date:
2015-05-27
Revision:
1:fd7adeffebbe
Parent:
0:866f2c528c01
Child:
2:510cac0a0250

File content as of revision 1:fd7adeffebbe:

#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,
};

const uint8_t DemoAppService::buttonCharacteristicUUID[LENGTH_OF_LONG_UUID] = {
    0x6E, 0x40, 0x00, 0x11, 0xB5, 0xA3, 0xF3, 0x93,
    0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
};

const uint8_t DemoAppService::slider1CharacteristicUUID[LENGTH_OF_LONG_UUID] = {
    0x6E, 0x40, 0x00, 0x12, 0xB5, 0xA3, 0xF3, 0x93,
    0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
};

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,
};

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);
}