Let me know what you think
Dependencies: BLE_API mbed nRF51822
Fork of SDP_Version3_Abdul by
BLE_Init.h
00001 #include "mbed.h" 00002 #include "ble/BLE.h" 00003 #include "MMA8452Q.h" 00004 #include "AcclerationService.h" 00005 #include "ReedSwitchService.h" 00006 00007 00008 const static char DEVICE_NAME[] = "BLE_Bike"; //Name of BLE Device 00009 static const uint16_t uuid16_list[] = {ReedSwitchService::REED_SWITCH_SERVICE_UUID, //UUID's of Services 00010 AccelerationService::ACCELERATION_SERVICE_UUID}; 00011 00012 static ReedSwitchService *reedSwitchServicePtr; 00013 static AccelerationService *accelerationServicePtr; 00014 00015 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) 00016 { 00017 BLE::Instance().gap().startAdvertising(); 00018 } 00019 00020 /** 00021 * This function is called when the ble initialization process has failed 00022 */ 00023 void onBleInitError(BLE &ble, ble_error_t error) 00024 { 00025 } 00026 00027 /** 00028 * Callback triggered when the ble initialization process has finished 00029 */ 00030 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) 00031 { 00032 BLE& ble = params->ble; 00033 ble_error_t error = params->error; 00034 00035 if (error != BLE_ERROR_NONE) { 00036 /* In case of error, forward the error handling to onBleInitError */ 00037 onBleInitError(ble, error); 00038 return; 00039 } 00040 00041 /* Ensure that it is the default instance of BLE */ 00042 if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { 00043 return; 00044 } 00045 00046 ble.gap().onDisconnection(disconnectionCallback); 00047 00048 /* Setup primary service */ 00049 reedSwitchServicePtr = new ReedSwitchService(ble, false /* initial value for button pressed */); 00050 accelerationServicePtr = new AccelerationService(ble); 00051 00052 /* setup advertising */ 00053 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); 00054 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); 00055 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); 00056 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); 00057 ble.gap().setAdvertisingInterval(100); /* 1000ms. */ 00058 ble.gap().startAdvertising(); 00059 00060 }
Generated on Thu Jul 21 2022 03:56:02 by
1.7.2
