integrating eddystone into bluetooth package

This commit is contained in:
Peli de Halleux
2016-11-30 04:06:15 -08:00
parent f0947cddaa
commit be0984cc4a
15 changed files with 135 additions and 126 deletions

View File

@ -11,7 +11,6 @@ using namespace pxt;
namespace bluetooth {
MicroBitUARTService *uart = NULL;
/**
* Starts the Bluetooth accelerometer service
*/
@ -119,5 +118,30 @@ namespace bluetooth {
//% parts="bluetooth"
void onBluetoothDisconnected(Action body) {
registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, body);
}
}
const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10};
/**
* Advertise an Eddystone URL
* @param url the url to transmit. Must be no longer than the supported eddystone url length
* @param power power level between 0 and 7, e.g.: 7
*/
//% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel"
//% parts=bluetooth
//% help=bluetooth/advertise-url
void advertiseUrl(StringData* url, int power) {
int8_t level = CALIBRATED_POWERS[min(7, max(0, power))];
uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level);
}
/**
* Stops advertising Eddystone end points
*/
//% blockId=eddystone_stop_advertising block="eddystone stop advertising"
//% parts=bluetooth
//% help=bluetooth/stop-advertising
void stopAdvertising() {
uBit.bleManager.stopAdvertising();
}
}