Bluetooth Low Energy template with prewritten functions and callbacks for BLE events.
source/main.cpp@0:dbe0ce913311, 2018-06-22 (annotated)
- Committer:
- jurica238814
- Date:
- Fri Jun 22 15:05:42 2018 +0200
- Revision:
- 0:dbe0ce913311
init commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jurica238814 | 0:dbe0ce913311 | 1 | /* |
| jurica238814 | 0:dbe0ce913311 | 2 | * aconno.de |
| jurica238814 | 0:dbe0ce913311 | 3 | * Simple program for aconno ble template demonstration |
| jurica238814 | 0:dbe0ce913311 | 4 | * |
| jurica238814 | 0:dbe0ce913311 | 5 | * Made by Jurica Resetar @ aconno |
| jurica238814 | 0:dbe0ce913311 | 6 | * ResetarJurica@gmail.com |
| jurica238814 | 0:dbe0ce913311 | 7 | * |
| jurica238814 | 0:dbe0ce913311 | 8 | */ |
| jurica238814 | 0:dbe0ce913311 | 9 | |
| jurica238814 | 0:dbe0ce913311 | 10 | #include "mbed.h" |
| jurica238814 | 0:dbe0ce913311 | 11 | #include "aconnoBLE.h" |
| jurica238814 | 0:dbe0ce913311 | 12 | #include "ble/BLE.h" |
| jurica238814 | 0:dbe0ce913311 | 13 | #include "BLEData.h" |
| jurica238814 | 0:dbe0ce913311 | 14 | #include "GapAdvertisingData.h" |
| jurica238814 | 0:dbe0ce913311 | 15 | #include "BLEConfig.h" |
| jurica238814 | 0:dbe0ce913311 | 16 | #include <list> |
| jurica238814 | 0:dbe0ce913311 | 17 | |
| jurica238814 | 0:dbe0ce913311 | 18 | advertisingFormat manufacturerSpecificData; |
| jurica238814 | 0:dbe0ce913311 | 19 | headerFormat header; |
| jurica238814 | 0:dbe0ce913311 | 20 | systemStateFormat systemState; |
| jurica238814 | 0:dbe0ce913311 | 21 | timestampFormat timestamp; |
| jurica238814 | 0:dbe0ce913311 | 22 | diagnoseFlagsFormat diagnoseFlags; |
| jurica238814 | 0:dbe0ce913311 | 23 | |
| jurica238814 | 0:dbe0ce913311 | 24 | int (*callback_)(int, int) = NULL; // pointer to a function |
| jurica238814 | 0:dbe0ce913311 | 25 | |
| jurica238814 | 0:dbe0ce913311 | 26 | int callbackFunction(int param1, int param2) |
| jurica238814 | 0:dbe0ce913311 | 27 | { |
| jurica238814 | 0:dbe0ce913311 | 28 | // Do some job |
| jurica238814 | 0:dbe0ce913311 | 29 | return 1; |
| jurica238814 | 0:dbe0ce913311 | 30 | } |
| jurica238814 | 0:dbe0ce913311 | 31 | |
| jurica238814 | 0:dbe0ce913311 | 32 | void primjer(int(*callback)(int, int)) |
| jurica238814 | 0:dbe0ce913311 | 33 | { |
| jurica238814 | 0:dbe0ce913311 | 34 | callback_(1, 2); |
| jurica238814 | 0:dbe0ce913311 | 35 | } |
| jurica238814 | 0:dbe0ce913311 | 36 | |
| jurica238814 | 0:dbe0ce913311 | 37 | int main() |
| jurica238814 | 0:dbe0ce913311 | 38 | { |
| jurica238814 | 0:dbe0ce913311 | 39 | //primjer(functionCallback); |
| jurica238814 | 0:dbe0ce913311 | 40 | |
| jurica238814 | 0:dbe0ce913311 | 41 | callback_ = callbackFunction; |
| jurica238814 | 0:dbe0ce913311 | 42 | primjer(callback_); |
| jurica238814 | 0:dbe0ce913311 | 43 | |
| jurica238814 | 0:dbe0ce913311 | 44 | BLE &ble = BLE::Instance(); |
| jurica238814 | 0:dbe0ce913311 | 45 | ble.init(bleInitComplete); |
| jurica238814 | 0:dbe0ce913311 | 46 | ble.gap().setTxPower(TX_POWER_dB); // Set TX power to TX_POWER |
| jurica238814 | 0:dbe0ce913311 | 47 | while (ble.hasInitialized() == false) { } |
| jurica238814 | 0:dbe0ce913311 | 48 | |
| jurica238814 | 0:dbe0ce913311 | 49 | while(1) |
| jurica238814 | 0:dbe0ce913311 | 50 | {} |
| jurica238814 | 0:dbe0ce913311 | 51 | } |