Eddystone test using modified DAL
Dependencies: BLE_API mbed-dev-bin nRF51822
Dependents: microbit-eddystone
Fork of microbit-dal by
inc/bluetooth/MicroBitBLEManager.h@74:a8f5674a0079, 2017-02-08 (annotated)
- Committer:
- bluetooth_mdw
- Date:
- Wed Feb 08 07:49:17 2017 +0000
- Revision:
- 74:a8f5674a0079
- Parent:
- 3:d86a4ddc1867
Eddystone URL test using modified DAL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
1:8aa5cdb4ab67 | 1 | /* |
Jonathan Austin |
1:8aa5cdb4ab67 | 2 | The MIT License (MIT) |
Jonathan Austin |
1:8aa5cdb4ab67 | 3 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
Jonathan Austin |
1:8aa5cdb4ab67 | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
Jonathan Austin |
1:8aa5cdb4ab67 | 6 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
Jonathan Austin |
1:8aa5cdb4ab67 | 8 | copy of this software and associated documentation files (the "Software"), |
Jonathan Austin |
1:8aa5cdb4ab67 | 9 | to deal in the Software without restriction, including without limitation |
Jonathan Austin |
1:8aa5cdb4ab67 | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Jonathan Austin |
1:8aa5cdb4ab67 | 11 | and/or sell copies of the Software, and to permit persons to whom the |
Jonathan Austin |
1:8aa5cdb4ab67 | 12 | Software is furnished to do so, subject to the following conditions: |
Jonathan Austin |
1:8aa5cdb4ab67 | 13 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 14 | The above copyright notice and this permission notice shall be included in |
Jonathan Austin |
1:8aa5cdb4ab67 | 15 | all copies or substantial portions of the Software. |
Jonathan Austin |
1:8aa5cdb4ab67 | 16 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Jonathan Austin |
1:8aa5cdb4ab67 | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Jonathan Austin |
1:8aa5cdb4ab67 | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
Jonathan Austin |
1:8aa5cdb4ab67 | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
Jonathan Austin |
1:8aa5cdb4ab67 | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 23 | DEALINGS IN THE SOFTWARE. |
Jonathan Austin |
1:8aa5cdb4ab67 | 24 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 25 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 26 | #ifndef MICROBIT_BLE_MANAGER_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 27 | #define MICROBIT_BLE_MANAGER_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 28 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 29 | #include "mbed.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 30 | #include "MicroBitConfig.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 31 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 32 | /* |
Jonathan Austin |
1:8aa5cdb4ab67 | 33 | * The underlying Nordic libraries that support BLE do not compile cleanly with the stringent GCC settings we employ |
Jonathan Austin |
1:8aa5cdb4ab67 | 34 | * If we're compiling under GCC, then we suppress any warnings generated from this code (but not the rest of the DAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 35 | * The ARM cc compiler is more tolerant. We don't test __GNUC__ here to detect GCC as ARMCC also typically sets this |
Jonathan Austin |
1:8aa5cdb4ab67 | 36 | * as a compatability option, but does not support the options used... |
Jonathan Austin |
1:8aa5cdb4ab67 | 37 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 38 | #if !defined(__arm) |
Jonathan Austin |
1:8aa5cdb4ab67 | 39 | #pragma GCC diagnostic push |
Jonathan Austin |
1:8aa5cdb4ab67 | 40 | #pragma GCC diagnostic ignored "-Wunused-parameter" |
Jonathan Austin |
1:8aa5cdb4ab67 | 41 | #endif |
Jonathan Austin |
1:8aa5cdb4ab67 | 42 | #include "ble/BLE.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 43 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 44 | /* |
Jonathan Austin |
1:8aa5cdb4ab67 | 45 | * Return to our predefined compiler settings. |
Jonathan Austin |
1:8aa5cdb4ab67 | 46 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 47 | #if !defined(__arm) |
Jonathan Austin |
1:8aa5cdb4ab67 | 48 | #pragma GCC diagnostic pop |
Jonathan Austin |
1:8aa5cdb4ab67 | 49 | #endif |
Jonathan Austin |
1:8aa5cdb4ab67 | 50 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 51 | #include "ble/services/DeviceInformationService.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 52 | #include "MicroBitDFUService.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 53 | #include "MicroBitEventService.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 54 | #include "MicroBitLEDService.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 55 | #include "MicroBitAccelerometerService.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 56 | #include "MicroBitMagnetometerService.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 57 | #include "MicroBitButtonService.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 58 | #include "MicroBitIOPinService.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 59 | #include "MicroBitTemperatureService.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 60 | #include "ExternalEvents.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 61 | #include "MicroBitButton.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 62 | #include "MicroBitStorage.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 63 | |
bluetooth_mdw | 74:a8f5674a0079 | 64 | #define MICROBIT_BLE_PAIR_REQUEST 0x01 |
bluetooth_mdw | 74:a8f5674a0079 | 65 | #define MICROBIT_BLE_PAIR_COMPLETE 0x02 |
bluetooth_mdw | 74:a8f5674a0079 | 66 | #define MICROBIT_BLE_PAIR_PASSCODE 0x04 |
bluetooth_mdw | 74:a8f5674a0079 | 67 | #define MICROBIT_BLE_PAIR_SUCCESSFUL 0x08 |
Jonathan Austin |
1:8aa5cdb4ab67 | 68 | |
bluetooth_mdw | 74:a8f5674a0079 | 69 | #define MICROBIT_BLE_PAIRING_TIMEOUT 90 |
bluetooth_mdw | 74:a8f5674a0079 | 70 | #define MICROBIT_BLE_POWER_LEVELS 8 |
bluetooth_mdw | 74:a8f5674a0079 | 71 | #define MICROBIT_BLE_MAXIMUM_BONDS 4 |
bluetooth_mdw | 74:a8f5674a0079 | 72 | #define MICROBIT_BLE_ENABLE_BONDING true |
bluetooth_mdw | 74:a8f5674a0079 | 73 | |
bluetooth_mdw | 74:a8f5674a0079 | 74 | #define MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL 400 |
bluetooth_mdw | 74:a8f5674a0079 | 75 | #define MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER 0xF0 |
Jonathan Austin |
1:8aa5cdb4ab67 | 76 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 77 | extern const int8_t MICROBIT_BLE_POWER_LEVEL[]; |
Jonathan Austin |
1:8aa5cdb4ab67 | 78 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 79 | struct BLESysAttribute |
Jonathan Austin |
1:8aa5cdb4ab67 | 80 | { |
bluetooth_mdw | 74:a8f5674a0079 | 81 | uint8_t sys_attr[8]; |
Jonathan Austin |
1:8aa5cdb4ab67 | 82 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 83 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 84 | struct BLESysAttributeStore |
Jonathan Austin |
1:8aa5cdb4ab67 | 85 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 86 | BLESysAttribute sys_attrs[MICROBIT_BLE_MAXIMUM_BONDS]; |
Jonathan Austin |
1:8aa5cdb4ab67 | 87 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 88 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 89 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 90 | * Class definition for the MicroBitBLEManager. |
Jonathan Austin |
1:8aa5cdb4ab67 | 91 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 92 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 93 | class MicroBitBLEManager : MicroBitComponent |
Jonathan Austin |
1:8aa5cdb4ab67 | 94 | { |
bluetooth_mdw | 74:a8f5674a0079 | 95 | public: |
bluetooth_mdw | 74:a8f5674a0079 | 96 | static MicroBitBLEManager *manager; |
Jonathan Austin |
1:8aa5cdb4ab67 | 97 | |
bluetooth_mdw | 74:a8f5674a0079 | 98 | // The mbed abstraction of the BlueTooth Low Energy (BLE) hardware |
bluetooth_mdw | 74:a8f5674a0079 | 99 | BLEDevice *ble; |
Jonathan Austin |
1:8aa5cdb4ab67 | 100 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 101 | //an instance of MicroBitStorage used to store sysAttrs from softdevice |
bluetooth_mdw | 74:a8f5674a0079 | 102 | MicroBitStorage *storage; |
Jonathan Austin |
1:8aa5cdb4ab67 | 103 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 104 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 105 | * Constructor. |
Jonathan Austin |
1:8aa5cdb4ab67 | 106 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 107 | * Configure and manage the micro:bit's Bluetooth Low Energy (BLE) stack. |
Jonathan Austin |
1:8aa5cdb4ab67 | 108 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 109 | * @param _storage an instance of MicroBitStorage used to persist sys attribute information. (This is required for compatability with iOS). |
Jonathan Austin |
1:8aa5cdb4ab67 | 110 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 111 | * @note The BLE stack *cannot* be brought up in a static context (the software simply hangs or corrupts itself). |
Jonathan Austin |
1:8aa5cdb4ab67 | 112 | * Hence, the init() member function should be used to initialise the BLE stack. |
Jonathan Austin |
1:8aa5cdb4ab67 | 113 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 114 | MicroBitBLEManager(MicroBitStorage &_storage); |
Jonathan Austin |
1:8aa5cdb4ab67 | 115 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 116 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 117 | * Constructor. |
Jonathan Austin |
1:8aa5cdb4ab67 | 118 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 119 | * Configure and manage the micro:bit's Bluetooth Low Energy (BLE) stack. |
Jonathan Austin |
1:8aa5cdb4ab67 | 120 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 121 | * @note The BLE stack *cannot* be brought up in a static context (the software simply hangs or corrupts itself). |
Jonathan Austin |
1:8aa5cdb4ab67 | 122 | * Hence, the init() member function should be used to initialise the BLE stack. |
Jonathan Austin |
1:8aa5cdb4ab67 | 123 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 124 | MicroBitBLEManager(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 125 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 126 | /** |
bluetooth_mdw | 74:a8f5674a0079 | 127 | * getInstance |
bluetooth_mdw | 74:a8f5674a0079 | 128 | * |
bluetooth_mdw | 74:a8f5674a0079 | 129 | * Allows other objects to easily obtain a pointer to the single instance of this object. By rights the constructor should be made |
bluetooth_mdw | 74:a8f5674a0079 | 130 | * private to properly implement the singleton pattern. |
bluetooth_mdw | 74:a8f5674a0079 | 131 | * |
bluetooth_mdw | 74:a8f5674a0079 | 132 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 133 | static MicroBitBLEManager *getInstance(); |
bluetooth_mdw | 74:a8f5674a0079 | 134 | |
bluetooth_mdw | 74:a8f5674a0079 | 135 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 136 | * Post constructor initialisation method as the BLE stack cannot be brought |
Jonathan Austin |
1:8aa5cdb4ab67 | 137 | * up in a static context. |
Jonathan Austin |
1:8aa5cdb4ab67 | 138 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 139 | * @param deviceName The name used when advertising |
Jonathan Austin |
1:8aa5cdb4ab67 | 140 | * @param serialNumber The serial number exposed by the device information service |
Jonathan Austin |
1:8aa5cdb4ab67 | 141 | * @param messageBus An instance of an EventModel, used during pairing. |
Jonathan Austin |
1:8aa5cdb4ab67 | 142 | * @param enableBonding If true, the security manager enabled bonding. |
Jonathan Austin |
1:8aa5cdb4ab67 | 143 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 144 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 145 | * bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true); |
Jonathan Austin |
1:8aa5cdb4ab67 | 146 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 147 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 148 | void init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, bool enableBonding); |
Jonathan Austin |
1:8aa5cdb4ab67 | 149 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 150 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 151 | * Change the output power level of the transmitter to the given value. |
Jonathan Austin |
1:8aa5cdb4ab67 | 152 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 153 | * @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest. |
Jonathan Austin |
1:8aa5cdb4ab67 | 154 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 155 | * @return MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the value is out of range. |
Jonathan Austin |
1:8aa5cdb4ab67 | 156 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 157 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 158 | * // maximum transmission power. |
Jonathan Austin |
1:8aa5cdb4ab67 | 159 | * bleManager.setTransmitPower(7); |
Jonathan Austin |
1:8aa5cdb4ab67 | 160 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 161 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 162 | int setTransmitPower(int power); |
Jonathan Austin |
1:8aa5cdb4ab67 | 163 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 164 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 165 | * Enter pairing mode. This is mode is called to initiate pairing, and to enable FOTA programming |
Jonathan Austin |
1:8aa5cdb4ab67 | 166 | * of the micro:bit in cases where BLE is disabled during normal operation. |
Jonathan Austin |
1:8aa5cdb4ab67 | 167 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 168 | * @param display An instance of MicroBitDisplay used when displaying pairing information. |
Jonathan Austin |
1:8aa5cdb4ab67 | 169 | * @param authorizationButton The button to use to authorise a pairing request. |
Jonathan Austin |
1:8aa5cdb4ab67 | 170 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 171 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 172 | * // initiate pairing mode |
Jonathan Austin |
1:8aa5cdb4ab67 | 173 | * bleManager.pairingMode(uBit.display, uBit.buttonA); |
Jonathan Austin |
1:8aa5cdb4ab67 | 174 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 175 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 176 | void pairingMode(MicroBitDisplay &display, MicroBitButton &authorisationButton); |
Jonathan Austin |
1:8aa5cdb4ab67 | 177 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 178 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 179 | * When called, the micro:bit will begin advertising for a predefined period, |
Jonathan Austin |
1:8aa5cdb4ab67 | 180 | * MICROBIT_BLE_ADVERTISING_TIMEOUT seconds to bonded devices. |
Jonathan Austin |
1:8aa5cdb4ab67 | 181 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 182 | void advertise(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 183 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 184 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 185 | * Determines the number of devices currently bonded with this micro:bit. |
Jonathan Austin |
1:8aa5cdb4ab67 | 186 | * @return The number of active bonds. |
Jonathan Austin |
1:8aa5cdb4ab67 | 187 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 188 | int getBondCount(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 189 | |
bluetooth_mdw | 74:a8f5674a0079 | 190 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 191 | * A request to pair has been received from a BLE device. |
Jonathan Austin |
1:8aa5cdb4ab67 | 192 | * If we're in pairing mode, display the passkey to the user. |
Jonathan Austin |
1:8aa5cdb4ab67 | 193 | * Also, purge the bonding table if it has reached capacity. |
Jonathan Austin |
1:8aa5cdb4ab67 | 194 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 195 | * @note for internal use only. |
Jonathan Austin |
1:8aa5cdb4ab67 | 196 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 197 | void pairingRequested(ManagedString passKey); |
Jonathan Austin |
1:8aa5cdb4ab67 | 198 | |
bluetooth_mdw | 74:a8f5674a0079 | 199 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 200 | * A pairing request has been sucessfully completed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 201 | * If we're in pairing mode, display a success or failure message. |
Jonathan Austin |
1:8aa5cdb4ab67 | 202 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 203 | * @note for internal use only. |
Jonathan Austin |
1:8aa5cdb4ab67 | 204 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 205 | void pairingComplete(bool success); |
Jonathan Austin |
1:8aa5cdb4ab67 | 206 | |
bluetooth_mdw | 74:a8f5674a0079 | 207 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 208 | * Periodic callback in thread context. |
Jonathan Austin |
1:8aa5cdb4ab67 | 209 | * We use this here purely to safely issue a disconnect operation after a pairing operation is complete. |
Jonathan Austin |
1:8aa5cdb4ab67 | 210 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 211 | void idleTick(); |
bluetooth_mdw | 74:a8f5674a0079 | 212 | |
bluetooth_mdw | 74:a8f5674a0079 | 213 | /** |
bluetooth_mdw | 74:a8f5674a0079 | 214 | * Stops any currently running BLE advertisements |
bluetooth_mdw | 74:a8f5674a0079 | 215 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 216 | void stopAdvertising(); |
bluetooth_mdw | 74:a8f5674a0079 | 217 | #if CONFIG_ENABLED(MICROBIT_BLE_EDDYSTONE_URL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 218 | |
bluetooth_mdw | 74:a8f5674a0079 | 219 | /** |
bluetooth_mdw | 74:a8f5674a0079 | 220 | * Set the content of Eddystone URL frames |
bluetooth_mdw | 74:a8f5674a0079 | 221 | * |
bluetooth_mdw | 74:a8f5674a0079 | 222 | * @param url The url to broadcast |
bluetooth_mdw | 74:a8f5674a0079 | 223 | * |
bluetooth_mdw | 74:a8f5674a0079 | 224 | * @param calibratedPower the transmission range of the beacon (Defaults to: 0xF0 ~10m). |
bluetooth_mdw | 74:a8f5674a0079 | 225 | * |
bluetooth_mdw | 74:a8f5674a0079 | 226 | * @param connectable true to keep bluetooth connectable for other services, false otherwise. (Defaults to true) |
bluetooth_mdw | 74:a8f5674a0079 | 227 | * |
bluetooth_mdw | 74:a8f5674a0079 | 228 | * @param interval the rate at which the micro:bit will advertise url frames. (Defaults to MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL) |
bluetooth_mdw | 74:a8f5674a0079 | 229 | * |
bluetooth_mdw | 74:a8f5674a0079 | 230 | * @note The calibratedPower value ranges from -100 to +20 to a resolution of 1. The calibrated power should be binary encoded. |
bluetooth_mdw | 74:a8f5674a0079 | 231 | * More information can be found at https://github.com/google/eddystone/tree/master/eddystone-uid#tx-power |
bluetooth_mdw | 74:a8f5674a0079 | 232 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 233 | int advertiseEddystoneUrl(const char *url, int8_t calibratedPower = MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER, bool connectable = true, uint16_t interval = MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL); |
Jonathan Austin |
1:8aa5cdb4ab67 | 234 | |
bluetooth_mdw | 74:a8f5674a0079 | 235 | /** |
bluetooth_mdw | 74:a8f5674a0079 | 236 | * Set the content of Eddystone URL frames, but accepts a ManagedString as a url. |
bluetooth_mdw | 74:a8f5674a0079 | 237 | * |
bluetooth_mdw | 74:a8f5674a0079 | 238 | * @param url The url to broadcast |
bluetooth_mdw | 74:a8f5674a0079 | 239 | * |
bluetooth_mdw | 74:a8f5674a0079 | 240 | * @param calibratedPower the transmission range of the beacon (Defaults to: 0xF0 ~10m). |
bluetooth_mdw | 74:a8f5674a0079 | 241 | * |
bluetooth_mdw | 74:a8f5674a0079 | 242 | * @param connectable true to keep bluetooth connectable for other services, false otherwise. (Defaults to true) |
bluetooth_mdw | 74:a8f5674a0079 | 243 | * |
bluetooth_mdw | 74:a8f5674a0079 | 244 | * @param interval the rate at which the micro:bit will advertise url frames. (Defaults to MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL) |
bluetooth_mdw | 74:a8f5674a0079 | 245 | * |
bluetooth_mdw | 74:a8f5674a0079 | 246 | * @note The calibratedPower value ranges from -100 to +20 to a resolution of 1. The calibrated power should be binary encoded. |
bluetooth_mdw | 74:a8f5674a0079 | 247 | * More information can be found at https://github.com/google/eddystone/tree/master/eddystone-uid#tx-power |
bluetooth_mdw | 74:a8f5674a0079 | 248 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 249 | int advertiseEddystoneUrl(ManagedString url, int8_t calibratedPower = MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER, bool connectable = true, uint16_t interval = MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL); |
bluetooth_mdw | 74:a8f5674a0079 | 250 | #endif |
Jonathan Austin |
1:8aa5cdb4ab67 | 251 | |
bluetooth_mdw | 74:a8f5674a0079 | 252 | #if CONFIG_ENABLED(MICROBIT_BLE_EDDYSTONE_UID) |
bluetooth_mdw | 74:a8f5674a0079 | 253 | /** |
bluetooth_mdw | 74:a8f5674a0079 | 254 | * Set the content of Eddystone UID frames |
bluetooth_mdw | 74:a8f5674a0079 | 255 | * |
bluetooth_mdw | 74:a8f5674a0079 | 256 | * @param uid_namespace: the uid namespace. Must 10 bytes long. |
bluetooth_mdw | 74:a8f5674a0079 | 257 | * |
bluetooth_mdw | 74:a8f5674a0079 | 258 | * @param uid_instance: the uid instance value. Must 6 bytes long. |
bluetooth_mdw | 74:a8f5674a0079 | 259 | * |
bluetooth_mdw | 74:a8f5674a0079 | 260 | * @param calibratedPower the transmission range of the beacon (Defaults to: 0xF0 ~10m). |
bluetooth_mdw | 74:a8f5674a0079 | 261 | * |
bluetooth_mdw | 74:a8f5674a0079 | 262 | * @param connectable true to keep bluetooth connectable for other services, false otherwise. (Defaults to true) |
bluetooth_mdw | 74:a8f5674a0079 | 263 | * |
bluetooth_mdw | 74:a8f5674a0079 | 264 | * @param interval the rate at which the micro:bit will advertise url frames. (Defaults to MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL) |
bluetooth_mdw | 74:a8f5674a0079 | 265 | * |
bluetooth_mdw | 74:a8f5674a0079 | 266 | * @note The calibratedPower value ranges from -100 to +20 to a resolution of 1. The calibrated power should be binary encoded. |
bluetooth_mdw | 74:a8f5674a0079 | 267 | * More information can be found at https://github.com/google/eddystone/tree/master/eddystone-uid#tx-power |
bluetooth_mdw | 74:a8f5674a0079 | 268 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 269 | int advertiseEddystoneUid(const char* uid_namespace, const char* uid_instance, int8_t calibratedPower = MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER, bool connectable = true, uint16_t interval = MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL); |
bluetooth_mdw | 74:a8f5674a0079 | 270 | #endif |
Jonathan Austin |
1:8aa5cdb4ab67 | 271 | |
bluetooth_mdw | 74:a8f5674a0079 | 272 | private: |
bluetooth_mdw | 74:a8f5674a0079 | 273 | /** |
bluetooth_mdw | 74:a8f5674a0079 | 274 | * Displays the device's ID code as a histogram on the provided MicroBitDisplay instance. |
bluetooth_mdw | 74:a8f5674a0079 | 275 | * |
bluetooth_mdw | 74:a8f5674a0079 | 276 | * @param display The display instance used for displaying the histogram. |
bluetooth_mdw | 74:a8f5674a0079 | 277 | */ |
bluetooth_mdw | 74:a8f5674a0079 | 278 | void showNameHistogram(MicroBitDisplay &display); |
bluetooth_mdw | 74:a8f5674a0079 | 279 | |
bluetooth_mdw | 74:a8f5674a0079 | 280 | #define MICROBIT_BLE_DISCONNECT_AFTER_PAIRING_DELAY 500 |
bluetooth_mdw | 74:a8f5674a0079 | 281 | unsigned long pairing_completed_at_time; |
bluetooth_mdw | 74:a8f5674a0079 | 282 | |
bluetooth_mdw | 74:a8f5674a0079 | 283 | int pairingStatus; |
bluetooth_mdw | 74:a8f5674a0079 | 284 | ManagedString passKey; |
bluetooth_mdw | 74:a8f5674a0079 | 285 | ManagedString deviceName; |
Jonathan Austin |
1:8aa5cdb4ab67 | 286 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 287 | |
bluetooth_mdw | 74:a8f5674a0079 | 288 | #endif |