Eddystone test with modified DAL
Dependencies: microbit-eddystone
Revision 0:580a61fd96a1, committed 2017-02-08
- Comitter:
- bluetooth_mdw
- Date:
- Wed Feb 08 07:49:44 2017 +0000
- Child:
- 1:b6a1fb1d68fc
- Commit message:
- Eddystone test using modified DAL
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
microbit.lib | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Feb 08 07:49:44 2017 +0000 @@ -0,0 +1,51 @@ +#include "MicroBit.h" + +MicroBit uBit; + +char URL[] = "https://goo.gl/TlUTF7"; +const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10}; + +uint8_t advertising = 0; +uint8_t tx_power_level = 6; + +void startAdvertising() { + uBit.bleManager.advertiseEddystoneUrl(URL, CALIBRATED_POWERS[tx_power_level-1], false); + uBit.bleManager.setTransmitPower(tx_power_level); + uBit.display.scroll("ADV"); + advertising = 1; +} + +void stopAdvertising() { + uBit.bleManager.stopAdvertising(); + uBit.display.scroll("OFF"); + advertising = 0; +} + +void onButtonA(MicroBitEvent) +{ + if (advertising == 1) { + return; + } + startAdvertising(); +} + +void onButtonB(MicroBitEvent) +{ + if (advertising == 0) { + return; + } + stopAdvertising(); +} + +int main() +{ + // Initialise the micro:bit runtime. + uBit.init(); + + uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA); + uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB); + + startAdvertising(); + + release_fiber(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/microbit.lib Wed Feb 08 07:49:44 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/Lancaster-University/code/microbit/#72a0174d5b1c