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.
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
main.cpp@26:ab05e85743a9, 2016-12-11 (annotated)
- Committer:
- hux
- Date:
- Sun Dec 11 00:16:31 2016 +0000
- Revision:
- 26:ab05e85743a9
- Parent:
- 25:f3b44a34cf5d
- Child:
- 27:09ec26511db8
complete source uses now Blob!
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| screamer | 0:eb7f02ad28a7 | 1 | /* mbed Microcontroller Library |
| screamer | 0:eb7f02ad28a7 | 2 | * Copyright (c) 2006-2015 ARM Limited |
| screamer | 0:eb7f02ad28a7 | 3 | * |
| screamer | 0:eb7f02ad28a7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| screamer | 0:eb7f02ad28a7 | 5 | * you may not use this file except in compliance with the License. |
| screamer | 0:eb7f02ad28a7 | 6 | * You may obtain a copy of the License at |
| screamer | 0:eb7f02ad28a7 | 7 | * |
| screamer | 0:eb7f02ad28a7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| screamer | 0:eb7f02ad28a7 | 9 | * |
| screamer | 0:eb7f02ad28a7 | 10 | * Unless required by applicable law or agreed to in writing, software |
| screamer | 0:eb7f02ad28a7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| screamer | 0:eb7f02ad28a7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| screamer | 0:eb7f02ad28a7 | 13 | * See the License for the specific language governing permissions and |
| screamer | 0:eb7f02ad28a7 | 14 | * limitations under the License. |
| screamer | 0:eb7f02ad28a7 | 15 | */ |
| hux | 22:e82c7b8a6072 | 16 | |
| screamer | 0:eb7f02ad28a7 | 17 | #include "mbed.h" |
| screamer | 0:eb7f02ad28a7 | 18 | #include "ble/BLE.h" |
| hux | 22:e82c7b8a6072 | 19 | #include "bricks/blob.h" |
| hux | 22:e82c7b8a6072 | 20 | #include "bricks/blink.h" |
| screamer | 0:eb7f02ad28a7 | 21 | |
| hux | 22:e82c7b8a6072 | 22 | const char *idle = "x "; // 'idle' blinking sequence |
| hux | 24:7bd093ad7d63 | 23 | const char *advertise = "x xxx "; // 'advertise' blinking sequence |
| hux | 22:e82c7b8a6072 | 24 | const char *action = "x x x x x "; // 'action' blinking sequence |
| hux | 24:7bd093ad7d63 | 25 | const char *faulty = "x x xxx "; // 'fault' blinking sequence |
| hux | 24:7bd093ad7d63 | 26 | |
| hux | 24:7bd093ad7d63 | 27 | // Add a device name for human readability |
| screamer | 0:eb7f02ad28a7 | 28 | |
| hux | 26:ab05e85743a9 | 29 | const static char DEVICE_NAME[] = "T05P_Advertising"; |
| hux | 24:7bd093ad7d63 | 30 | |
| hux | 24:7bd093ad7d63 | 31 | // You have up to 26 bytes of advertising data to use. |
| hux | 24:7bd093ad7d63 | 32 | // Hex data example: {0x01,0x02,0x03,0x04,0x05} |
| hux | 24:7bd093ad7d63 | 33 | // Char data example: {"ChangeThisData"} |
| hux | 24:7bd093ad7d63 | 34 | |
| hux | 24:7bd093ad7d63 | 35 | const static uint8_t AdvData[] = {0x01,0x02,0x03,0x04,0x05}; |
| apalmieri | 13:227a0149b677 | 36 | |
| hux | 24:7bd093ad7d63 | 37 | //============================================================================== |
| hux | 24:7bd093ad7d63 | 38 | // Some Callbacks |
| hux | 24:7bd093ad7d63 | 39 | //============================================================================== |
| screamer | 0:eb7f02ad28a7 | 40 | |
| hux | 24:7bd093ad7d63 | 41 | void onDisconnect(Blob &blob) // Disconnection Callback |
| hux | 24:7bd093ad7d63 | 42 | { |
| hux | 25:f3b44a34cf5d | 43 | blob.start(); // start advertising |
| hux | 24:7bd093ad7d63 | 44 | blinking("advertise"); |
| hux | 24:7bd093ad7d63 | 45 | } |
| hux | 23:f06c9851c72c | 46 | |
| hux | 25:f3b44a34cf5d | 47 | |
| hux | 24:7bd093ad7d63 | 48 | void onError(Blob &blob) // Error Reporting Callback |
| hux | 24:7bd093ad7d63 | 49 | { |
| hux | 24:7bd093ad7d63 | 50 | (void) blob; // Avoid compiler warnings |
| hux | 24:7bd093ad7d63 | 51 | /* Initialization error handling should go here */ |
| hux | 24:7bd093ad7d63 | 52 | } |
| hux | 23:f06c9851c72c | 53 | |
| hux | 23:f06c9851c72c | 54 | |
| hux | 24:7bd093ad7d63 | 55 | void onSetup(Blob &blob) // Immediately After Initializing BLE |
| hux | 23:f06c9851c72c | 56 | { |
| hux | 23:f06c9851c72c | 57 | if (blob.error != BLE_ERROR_NONE) |
| hux | 23:f06c9851c72c | 58 | { |
| hux | 24:7bd093ad7d63 | 59 | onError(blob); |
| hux | 23:f06c9851c72c | 60 | return; |
| hux | 23:f06c9851c72c | 61 | } |
| apalmieri | 13:227a0149b677 | 62 | |
| hux | 26:ab05e85743a9 | 63 | blob.device(DEVICE_NAME); // setup device name |
| hux | 26:ab05e85743a9 | 64 | blob.disconnect(onDisconnect); // setup disconnect callback |
| hux | 24:7bd093ad7d63 | 65 | |
| hux | 26:ab05e85743a9 | 66 | blob.discoverable(); |
| hux | 26:ab05e85743a9 | 67 | blob.type("cu"); // connectable unidirected |
| screamer | 0:eb7f02ad28a7 | 68 | |
| hux | 26:ab05e85743a9 | 69 | blob.data(AdvData,sizeof(AdvData)); |
| hux | 26:ab05e85743a9 | 70 | blob.name("Humbo"); // add name to device |
| screamer | 0:eb7f02ad28a7 | 71 | |
| hux | 26:ab05e85743a9 | 72 | blob.start(100); // start advertising @ 100 msec interval |
| hux | 24:7bd093ad7d63 | 73 | blinking("advertise"); |
| hux | 23:f06c9851c72c | 74 | } |
| hux | 23:f06c9851c72c | 75 | |
| apalmieri | 13:227a0149b677 | 76 | |
| hux | 22:e82c7b8a6072 | 77 | int main(void) |
| hux | 22:e82c7b8a6072 | 78 | { |
| hux | 22:e82c7b8a6072 | 79 | Blob blob; |
| hux | 24:7bd093ad7d63 | 80 | blinking(idle); // idle blinking - everything is OK! |
| hux | 23:f06c9851c72c | 81 | |
| hux | 24:7bd093ad7d63 | 82 | blob.init(onSetup); // init BLE base layer, always do first |
| hux | 24:7bd093ad7d63 | 83 | blinking(advertise); // idle blinking - everything is OK! |
| hux | 24:7bd093ad7d63 | 84 | |
| hux | 24:7bd093ad7d63 | 85 | while (true) // Infinite loop waiting for BLE events */ |
| hux | 22:e82c7b8a6072 | 86 | { |
| hux | 24:7bd093ad7d63 | 87 | blob.sleep(); // low power waiting for BLE events |
| hux | 22:e82c7b8a6072 | 88 | } |
| hux | 22:e82c7b8a6072 | 89 | } |
