PUBLISH HelloBlue
Dependencies: BLE_API mbed nRF51822
Fork of HelloBlue by
main.cpp@1:b84d6e0b404e, 2015-01-28 (annotated)
- Committer:
- waynek
- Date:
- Wed Jan 28 17:44:09 2015 +0000
- Revision:
- 1:b84d6e0b404e
- Parent:
- 0:a89b73f690c1
- Child:
- 2:4f0d8bf09690
removed redundant DFUService declaration.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
waynek | 0:a89b73f690c1 | 1 | #include "mbed.h" |
waynek | 0:a89b73f690c1 | 2 | #include "BLEDevice.h" |
waynek | 0:a89b73f690c1 | 3 | |
waynek | 1:b84d6e0b404e | 4 | // DFUService is already included & automatically advertised by the mbed lib dependancies (currently) |
waynek | 0:a89b73f690c1 | 5 | |
waynek | 0:a89b73f690c1 | 6 | const static char DEVICE_NAME[] = "HelloBlue"; |
waynek | 0:a89b73f690c1 | 7 | |
waynek | 0:a89b73f690c1 | 8 | BLEDevice ble; |
waynek | 0:a89b73f690c1 | 9 | |
waynek | 0:a89b73f690c1 | 10 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) |
waynek | 0:a89b73f690c1 | 11 | { |
waynek | 0:a89b73f690c1 | 12 | ble.startAdvertising(); // restart advertising |
waynek | 0:a89b73f690c1 | 13 | } |
waynek | 0:a89b73f690c1 | 14 | |
waynek | 0:a89b73f690c1 | 15 | int main(void) |
waynek | 0:a89b73f690c1 | 16 | { |
waynek | 0:a89b73f690c1 | 17 | ble.init(); |
waynek | 0:a89b73f690c1 | 18 | ble.onDisconnection(disconnectionCallback); |
waynek | 0:a89b73f690c1 | 19 | |
waynek | 0:a89b73f690c1 | 20 | /* Setup advertising. */ |
waynek | 0:a89b73f690c1 | 21 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
waynek | 0:a89b73f690c1 | 22 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); |
waynek | 0:a89b73f690c1 | 23 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
waynek | 0:a89b73f690c1 | 24 | ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000)); |
waynek | 0:a89b73f690c1 | 25 | ble.startAdvertising(); |
waynek | 0:a89b73f690c1 | 26 | |
waynek | 0:a89b73f690c1 | 27 | while (true) { |
waynek | 0:a89b73f690c1 | 28 | ble.waitForEvent(); |
waynek | 0:a89b73f690c1 | 29 | } |
waynek | 0:a89b73f690c1 | 30 | } |
waynek | 0:a89b73f690c1 | 31 |