No changes
Dependencies: BLE_API mbed nRF51822
Fork of SDP_Version3_Abdul by
BLE_Init.h
- Committer:
- galism
- Date:
- 2017-02-26
- Revision:
- 4:caab577334f0
File content as of revision 4:caab577334f0:
#include "mbed.h" #include "ble/BLE.h" #include "MMA8452Q.h" #include "AcclerationService.h" #include "ReedSwitchService.h" const static char DEVICE_NAME[] = "BLE_Bike"; //Name of BLE Device static const uint16_t uuid16_list[] = {ReedSwitchService::REED_SWITCH_SERVICE_UUID, //UUID's of Services AccelerationService::ACCELERATION_SERVICE_UUID}; static ReedSwitchService *reedSwitchServicePtr; static AccelerationService *accelerationServicePtr; void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { BLE::Instance().gap().startAdvertising(); } /** * This function is called when the ble initialization process has failed */ void onBleInitError(BLE &ble, ble_error_t error) { } /** * Callback triggered when the ble initialization process has finished */ void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) { BLE& ble = params->ble; ble_error_t error = params->error; if (error != BLE_ERROR_NONE) { /* In case of error, forward the error handling to onBleInitError */ onBleInitError(ble, error); return; } /* Ensure that it is the default instance of BLE */ if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { return; } ble.gap().onDisconnection(disconnectionCallback); /* Setup primary service */ reedSwitchServicePtr = new ReedSwitchService(ble, false /* initial value for button pressed */); accelerationServicePtr = new AccelerationService(ble); /* setup advertising */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(100); /* 1000ms. */ ble.gap().startAdvertising(); }