Example program for BLE devices using updated Puck library.
Fork of location-puck by
main.cpp@4:4324d5acd5d8, 2014-06-19 (annotated)
- Committer:
- cristea
- Date:
- Thu Jun 19 10:14:27 2014 +0000
- Revision:
- 4:4324d5acd5d8
- Parent:
- 3:4cb285fb29e7
- Child:
- 5:8ccb1cd6694d
Add Bluetooth skeleton
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cristea | 0:f4fbeaabdff5 | 1 | #include <mbed.h> |
cristea | 4:4324d5acd5d8 | 2 | #include <nRF51822n.h> |
cristea |
3:4cb285fb29e7 | 3 | #define DEBUG 1 |
cristea | 0:f4fbeaabdff5 | 4 | |
cristea |
3:4cb285fb29e7 | 5 | #ifdef DEBUG |
cristea | 4:4324d5acd5d8 | 6 | Serial pc(USBTX, USBRX); |
cristea |
3:4cb285fb29e7 | 7 | #define LOG(args...) pc.printf(args) |
cristea |
3:4cb285fb29e7 | 8 | #else |
cristea |
3:4cb285fb29e7 | 9 | #define LOG(args...) |
cristea |
3:4cb285fb29e7 | 10 | #endif |
cristea | 0:f4fbeaabdff5 | 11 | |
cristea |
3:4cb285fb29e7 | 12 | nRF51822n nrf; |
cristea |
3:4cb285fb29e7 | 13 | DigitalOut led1(p1); |
cristea | 4:4324d5acd5d8 | 14 | DigitalOut advertisingStateLed(p30); |
cristea |
2:67d603617000 | 15 | |
cristea |
3:4cb285fb29e7 | 16 | GapAdvertisingData advData; |
cristea |
3:4cb285fb29e7 | 17 | GapAdvertisingData scanResponse; |
cristea | 4:4324d5acd5d8 | 18 | GapAdvertisingParams advParams(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
cristea |
2:67d603617000 | 19 | |
cristea | 4:4324d5acd5d8 | 20 | int main(void) { |
cristea |
3:4cb285fb29e7 | 21 | |
cristea |
3:4cb285fb29e7 | 22 | nrf.init(); |
cristea |
3:4cb285fb29e7 | 23 | nrf.reset(); |
cristea |
3:4cb285fb29e7 | 24 | |
cristea |
3:4cb285fb29e7 | 25 | advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
cristea |
3:4cb285fb29e7 | 26 | advData.addData(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
cristea |
3:4cb285fb29e7 | 27 | (uint8_t*)"phlemz", sizeof("phlemz") - 1); |
cristea |
3:4cb285fb29e7 | 28 | advData.addAppearance(GapAdvertisingData::UNKNOWN); |
cristea | 4:4324d5acd5d8 | 29 | nrf.getGap().setAdvertisingData(advData, scanResponse); |
cristea |
3:4cb285fb29e7 | 30 | |
cristea |
3:4cb285fb29e7 | 31 | nrf.getGap().startAdvertising(advParams); |
cristea |
3:4cb285fb29e7 | 32 | |
cristea |
3:4cb285fb29e7 | 33 | for(;;) { |
cristea |
3:4cb285fb29e7 | 34 | led1 = !led1; |
cristea |
3:4cb285fb29e7 | 35 | wait(1); |
cristea | 0:f4fbeaabdff5 | 36 | } |
cristea |
1:345039810771 | 37 | } |