Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SDP_Version3 by
Diff: BLE_Init.h
- Revision:
- 4:caab577334f0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BLE_Init.h Sun Feb 26 02:33:32 2017 +0000
@@ -0,0 +1,60 @@
+#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();
+
+}
\ No newline at end of file
