updates

Dependencies:   microbit2

Fork of eddystone_test by Martin Woolley

Committer:
wwbluetooth
Date:
Mon Jul 17 20:50:07 2017 +0000
Revision:
2:2e790f118a62
Parent:
0:580a61fd96a1
asdf

Who changed what in which revision?

UserRevisionLine numberNew 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
wwbluetooth 2:2e790f118a62 5 char URL[] = "https://goo.gl/QJpaKk";
wwbluetooth 2:2e790f118a62 6
wwbluetooth 2:2e790f118a62 7 // lvl : Pwr@ 1m : Pwr@ 0m
wwbluetooth 2:2e790f118a62 8 // 0 : -90 : -49
wwbluetooth 2:2e790f118a62 9 // 1 : -78 : -37
wwbluetooth 2:2e790f118a62 10 // 2 : -74 : -33
wwbluetooth 2:2e790f118a62 11 // 3 : -69 : -28
wwbluetooth 2:2e790f118a62 12 // 4 : -66 : -25
wwbluetooth 2:2e790f118a62 13 // 5 : -61 : -20
wwbluetooth 2:2e790f118a62 14 // 6 : -56 : -15
wwbluetooth 2:2e790f118a62 15 // 7 : -51 : -10
wwbluetooth 2:2e790f118a62 16
bluetooth_mdw 0:580a61fd96a1 17 const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10};
bluetooth_mdw 0:580a61fd96a1 18
bluetooth_mdw 0:580a61fd96a1 19 uint8_t advertising = 0;
bluetooth_mdw 0:580a61fd96a1 20 uint8_t tx_power_level = 6;
bluetooth_mdw 0:580a61fd96a1 21
bluetooth_mdw 0:580a61fd96a1 22 void startAdvertising() {
bluetooth_mdw 0:580a61fd96a1 23 uBit.bleManager.advertiseEddystoneUrl(URL, CALIBRATED_POWERS[tx_power_level-1], false);
bluetooth_mdw 0:580a61fd96a1 24 uBit.bleManager.setTransmitPower(tx_power_level);
bluetooth_mdw 0:580a61fd96a1 25 uBit.display.scroll("ADV");
bluetooth_mdw 0:580a61fd96a1 26 advertising = 1;
bluetooth_mdw 0:580a61fd96a1 27 }
bluetooth_mdw 0:580a61fd96a1 28
bluetooth_mdw 0:580a61fd96a1 29 void stopAdvertising() {
bluetooth_mdw 0:580a61fd96a1 30 uBit.bleManager.stopAdvertising();
bluetooth_mdw 0:580a61fd96a1 31 uBit.display.scroll("OFF");
bluetooth_mdw 0:580a61fd96a1 32 advertising = 0;
bluetooth_mdw 0:580a61fd96a1 33 }
bluetooth_mdw 0:580a61fd96a1 34
bluetooth_mdw 0:580a61fd96a1 35 void onButtonA(MicroBitEvent)
bluetooth_mdw 0:580a61fd96a1 36 {
bluetooth_mdw 0:580a61fd96a1 37 if (advertising == 1) {
bluetooth_mdw 0:580a61fd96a1 38 return;
bluetooth_mdw 0:580a61fd96a1 39 }
bluetooth_mdw 0:580a61fd96a1 40 startAdvertising();
wwbluetooth 2:2e790f118a62 41
bluetooth_mdw 0:580a61fd96a1 42 }
bluetooth_mdw 0:580a61fd96a1 43
bluetooth_mdw 0:580a61fd96a1 44 void onButtonB(MicroBitEvent)
bluetooth_mdw 0:580a61fd96a1 45 {
bluetooth_mdw 0:580a61fd96a1 46 if (advertising == 0) {
bluetooth_mdw 0:580a61fd96a1 47 return;
bluetooth_mdw 0:580a61fd96a1 48 }
bluetooth_mdw 0:580a61fd96a1 49 stopAdvertising();
bluetooth_mdw 0:580a61fd96a1 50 }
bluetooth_mdw 0:580a61fd96a1 51
bluetooth_mdw 0:580a61fd96a1 52 int main()
bluetooth_mdw 0:580a61fd96a1 53 {
wwbluetooth 2:2e790f118a62 54 // Initialise the micro:bit at runtime
bluetooth_mdw 0:580a61fd96a1 55 uBit.init();
bluetooth_mdw 0:580a61fd96a1 56
bluetooth_mdw 0:580a61fd96a1 57 uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA);
bluetooth_mdw 0:580a61fd96a1 58 uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB);
bluetooth_mdw 0:580a61fd96a1 59
wwbluetooth 2:2e790f118a62 60
wwbluetooth 2:2e790f118a62 61 uBit.bleManager.advertise(); //First Advertisment, adv name only
bluetooth_mdw 0:580a61fd96a1 62
bluetooth_mdw 0:580a61fd96a1 63 release_fiber();
bluetooth_mdw 0:580a61fd96a1 64 }