Matthew Chan / Mbed 2 deprecated BLE_GAP_Acceleration_Observer_Trial

Dependencies:   ADXL345_nRF51 BLE_API advertiser_data mbed nRF51822

Fork of BLE_GAP_Acceleration_Observer_2_Advertisers by Ames HCI IoT

Files at this revision

API Documentation at this revision

Comitter:
rgrover1
Date:
Tue May 12 10:28:21 2015 +0000
Child:
1:f9ff297c8c84
Commit message:
initial attempt at a demo for a BLE observer. Uses the new scanning APIs.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 12 10:28:21 2015 +0000
@@ -0,0 +1,59 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "mbed.h"
+#include "BLEDevice.h"
+
+BLEDevice  ble;
+DigitalOut led1(LED1);
+
+void periodicCallback(void)
+{
+    led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
+}
+
+void advertisementCallback(const Gap::address_t      peerAddr,
+                           int8_t                    rssi,
+                           bool                      isScanResponse,
+                           Gap::AdvertisementType_t  type,
+                           uint8_t                   advertisingDataLen,
+                           const uint8_t            *advertisingData) {
+    printf("Adv peerAddr: [%02x %02x %02x %02x %02x %02x] rssi %d, ScanResp: %u, AdvType: %u\r\n",
+           peerAddr[5], peerAddr[4], peerAddr[3], peerAddr[2], peerAddr[1], peerAddr[0], rssi, isScanResponse, type);
+#if DUMP_ADV_DATA
+    unsigned index = 0;
+    for (; index < advertisingDataLen; index++) {
+        printf("%02x ", advertisingData[index]);
+    }
+    printf("\r\n");
+#endif /* DUMP_ADV_DATA */
+}
+
+int main(void)
+{
+    led1 = 1;
+    Ticker ticker;
+    ticker.attach(periodicCallback, 1);
+
+    ble.init();
+
+    ble.setScanParams(500 /* scan interval */, 200 /* scan window */);
+    ble.startScan(advertisementCallback);
+
+    while (true) {
+        ble.waitForEvent();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue May 12 10:28:21 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058
\ No newline at end of file