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: microbit-eddystone
Fork of eddystone_test by
main.cpp@0:580a61fd96a1, 2017-02-08 (annotated)
- Committer:
- bluetooth_mdw
- Date:
- Wed Feb 08 07:49:44 2017 +0000
- Revision:
- 0:580a61fd96a1
Eddystone test using modified DAL
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bluetooth_mdw | 0:580a61fd96a1 | 1 | #include "MicroBit.h" |
| bluetooth_mdw | 0:580a61fd96a1 | 2 | |
| bluetooth_mdw | 0:580a61fd96a1 | 3 | MicroBit uBit; |
| bluetooth_mdw | 0:580a61fd96a1 | 4 | |
| bluetooth_mdw | 0:580a61fd96a1 | 5 | char URL[] = "https://goo.gl/TlUTF7"; |
| bluetooth_mdw | 0:580a61fd96a1 | 6 | const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10}; |
| bluetooth_mdw | 0:580a61fd96a1 | 7 | |
| bluetooth_mdw | 0:580a61fd96a1 | 8 | uint8_t advertising = 0; |
| bluetooth_mdw | 0:580a61fd96a1 | 9 | uint8_t tx_power_level = 6; |
| bluetooth_mdw | 0:580a61fd96a1 | 10 | |
| bluetooth_mdw | 0:580a61fd96a1 | 11 | void startAdvertising() { |
| bluetooth_mdw | 0:580a61fd96a1 | 12 | uBit.bleManager.advertiseEddystoneUrl(URL, CALIBRATED_POWERS[tx_power_level-1], false); |
| bluetooth_mdw | 0:580a61fd96a1 | 13 | uBit.bleManager.setTransmitPower(tx_power_level); |
| bluetooth_mdw | 0:580a61fd96a1 | 14 | uBit.display.scroll("ADV"); |
| bluetooth_mdw | 0:580a61fd96a1 | 15 | advertising = 1; |
| bluetooth_mdw | 0:580a61fd96a1 | 16 | } |
| bluetooth_mdw | 0:580a61fd96a1 | 17 | |
| bluetooth_mdw | 0:580a61fd96a1 | 18 | void stopAdvertising() { |
| bluetooth_mdw | 0:580a61fd96a1 | 19 | uBit.bleManager.stopAdvertising(); |
| bluetooth_mdw | 0:580a61fd96a1 | 20 | uBit.display.scroll("OFF"); |
| bluetooth_mdw | 0:580a61fd96a1 | 21 | advertising = 0; |
| bluetooth_mdw | 0:580a61fd96a1 | 22 | } |
| bluetooth_mdw | 0:580a61fd96a1 | 23 | |
| bluetooth_mdw | 0:580a61fd96a1 | 24 | void onButtonA(MicroBitEvent) |
| bluetooth_mdw | 0:580a61fd96a1 | 25 | { |
| bluetooth_mdw | 0:580a61fd96a1 | 26 | if (advertising == 1) { |
| bluetooth_mdw | 0:580a61fd96a1 | 27 | return; |
| bluetooth_mdw | 0:580a61fd96a1 | 28 | } |
| bluetooth_mdw | 0:580a61fd96a1 | 29 | startAdvertising(); |
| bluetooth_mdw | 0:580a61fd96a1 | 30 | } |
| bluetooth_mdw | 0:580a61fd96a1 | 31 | |
| bluetooth_mdw | 0:580a61fd96a1 | 32 | void onButtonB(MicroBitEvent) |
| bluetooth_mdw | 0:580a61fd96a1 | 33 | { |
| bluetooth_mdw | 0:580a61fd96a1 | 34 | if (advertising == 0) { |
| bluetooth_mdw | 0:580a61fd96a1 | 35 | return; |
| bluetooth_mdw | 0:580a61fd96a1 | 36 | } |
| bluetooth_mdw | 0:580a61fd96a1 | 37 | stopAdvertising(); |
| bluetooth_mdw | 0:580a61fd96a1 | 38 | } |
| bluetooth_mdw | 0:580a61fd96a1 | 39 | |
| bluetooth_mdw | 0:580a61fd96a1 | 40 | int main() |
| bluetooth_mdw | 0:580a61fd96a1 | 41 | { |
| bluetooth_mdw | 0:580a61fd96a1 | 42 | // Initialise the micro:bit runtime. |
| bluetooth_mdw | 0:580a61fd96a1 | 43 | uBit.init(); |
| bluetooth_mdw | 0:580a61fd96a1 | 44 | |
| bluetooth_mdw | 0:580a61fd96a1 | 45 | uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA); |
| bluetooth_mdw | 0:580a61fd96a1 | 46 | uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB); |
| bluetooth_mdw | 0:580a61fd96a1 | 47 | |
| bluetooth_mdw | 0:580a61fd96a1 | 48 | startAdvertising(); |
| bluetooth_mdw | 0:580a61fd96a1 | 49 | |
| bluetooth_mdw | 0:580a61fd96a1 | 50 | release_fiber(); |
| bluetooth_mdw | 0:580a61fd96a1 | 51 | } |
