From b1fcc51bc82e087b0540ffc077cf779c190ab61c Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 29 Nov 2016 09:21:23 -0800 Subject: [PATCH 1/8] preparing support for eddystone --- docs/reference.md | 8 +++++--- docs/reference/eddystone.md | 28 ++++++++++++++++++++++++++ libs/eddystone/eddystone.cpp | 31 +++++++++++++++++++++++++++++ libs/eddystone/eddystone.ts | 13 ++++++++++++ libs/eddystone/enums.d.ts | 5 +++++ libs/eddystone/pxt.json | 38 ++++++++++++++++++++++++++++++++++++ libs/eddystone/shims.d.ts | 23 ++++++++++++++++++++++ pxtarget.json | 3 ++- 8 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 docs/reference/eddystone.md create mode 100644 libs/eddystone/eddystone.cpp create mode 100644 libs/eddystone/eddystone.ts create mode 100644 libs/eddystone/enums.d.ts create mode 100644 libs/eddystone/pxt.json create mode 100644 libs/eddystone/shims.d.ts diff --git a/docs/reference.md b/docs/reference.md index c5bdd08e..aca07c1e 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -29,19 +29,21 @@ control.inBackground(() => { }); ``` -## Bluetooth - +## bluetooth and Eddystone + ```namespaces devices.tellCameraTo(MesCameraEvent.TakePhoto); bluetooth.onBluetoothConnected(() => {}); +eddystone.advertiseUrl("https://pxt.io", 6); ``` ```package radio devices bluetooth +eddystone ``` ### See Also -[basic](/reference/basic), [input](/reference/input), [music](/reference/music), [led](/reference/led), [Math (blocks)](/blocks/math), [String](/reference/types/string), [game](/reference/game), [images](/reference/images), [pins](/reference/pins), [serial](/reference/serial), [control](/reference/control), [radio](/reference/radio), [devices](/reference/devices), [bluetooth](/reference/bluetooth) +[basic](/reference/basic), [input](/reference/input), [music](/reference/music), [led](/reference/led), [Math (blocks)](/blocks/math), [String](/reference/types/string), [game](/reference/game), [images](/reference/images), [pins](/reference/pins), [serial](/reference/serial), [control](/reference/control), [radio](/reference/radio), [devices](/reference/devices), [bluetooth](/reference/bluetooth), [eddystone](/reference/eddystone) diff --git a/docs/reference/eddystone.md b/docs/reference/eddystone.md new file mode 100644 index 00000000..d1a6f267 --- /dev/null +++ b/docs/reference/eddystone.md @@ -0,0 +1,28 @@ +# Eddystone + +Support for Eddystone beacons. + +```cards +eddystone.advertiseUrl("https://pxt.io/", 6); +eddystone.stopAdvertising(); +``` + +### Advanced + +Bluetooth beacons are used to indicate proximity to a place or object of interest. +Beacons use Bluetooth advertising to broadcast a small amount of data, which can be received and acted upon by anyone in range +with a suitable device and software, typically a smartphone and application. + +There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data. +iBeacon is Apple's beacon message format. Eddystone comes from Google. + +More information at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ + +### See Also + +[eddystone.advertiseUrl](/reference/eddystone/advertise-url), +[eddystone.stopAdvertising](/reference/eddystone/stop-advertising), + +```package +eddystone +``` diff --git a/libs/eddystone/eddystone.cpp b/libs/eddystone/eddystone.cpp new file mode 100644 index 00000000..879a0a84 --- /dev/null +++ b/libs/eddystone/eddystone.cpp @@ -0,0 +1,31 @@ +#include "pxt.h" +#include "Microbit.h" +#include "MicroBitEddystone.h" + +using namespace pxt; + +/** +* Support for Eddystone beacons +*/ +//% color=#0082FB weight=19 +namespace eddystone { + const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10}; + + /** + * Advertise an Eddystone URL + */ + //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" + void advertiseUrl(StringData* url, int powerLevel) { + int power = CALIBRATED_POWERS[min(7, max(0, powerLevel))]; + ManagedString murl(url) + uBit.bleManager.advertiseEddystoneUrl(murl, power, false); + } + + /** + * Stops advertising Eddystone end points + */ + //% blockId=eddystone_stop_advertising block="eddystone stop advertising" + void stopAdvertising() { + uBit.bleManager.stopAdvertising(); + } +} diff --git a/libs/eddystone/eddystone.ts b/libs/eddystone/eddystone.ts new file mode 100644 index 00000000..efc810ad --- /dev/null +++ b/libs/eddystone/eddystone.ts @@ -0,0 +1,13 @@ +/** +* Support for Eddystone beacons +*/ +//% color=#0082FB weight=19 +namespace eddystone { + //% shim=eddystone::advertiseUrl + export function advertiseUrl(url: string, powerLevel: number) { + } + + //% shim=eddystone::stopAdvertising + export function stopAdvertising() { + } +} diff --git a/libs/eddystone/enums.d.ts b/libs/eddystone/enums.d.ts new file mode 100644 index 00000000..7c80d5f7 --- /dev/null +++ b/libs/eddystone/enums.d.ts @@ -0,0 +1,5 @@ +// Auto-generated. Do not edit. +declare namespace eddystone { +} + +// Auto-generated. Do not edit. Really. diff --git a/libs/eddystone/pxt.json b/libs/eddystone/pxt.json new file mode 100644 index 00000000..76388b95 --- /dev/null +++ b/libs/eddystone/pxt.json @@ -0,0 +1,38 @@ +{ + "name": "eddystone", + "description": "Eddystone beacon support", + "dependencies": { + "core": "file:../core" + }, + "files": [ + "eddystone.cpp", + "eddystone.ts", + "enums.d.ts", + "shims.d.ts" + ], + "yotta": { + "config": { + "microbit-dal": { + "bluetooth": { + "enabled": 1, + "eddystone_url": 1, + "eddystone_uid": 0 + } + } + }, + "optionalConfig": { + "microbit-dal": { + "bluetooth": { + "pairing_mode": 0, + "private_addressing": 0, + "whitelist": 0, + "advertising_timeout": 0, + "tx_power": 6, + "dfu_service": 0, + "event_service": 0, + "device_info_service": 0 + } + } + } + } +} \ No newline at end of file diff --git a/libs/eddystone/shims.d.ts b/libs/eddystone/shims.d.ts new file mode 100644 index 00000000..09cd073e --- /dev/null +++ b/libs/eddystone/shims.d.ts @@ -0,0 +1,23 @@ +// Auto-generated. Do not edit. + + + /** + * Support for Eddystone beacons + */ + //% color=#0082FB weight=19 +declare namespace eddystone { + + /** + * Advertise an Eddystone URL + */ + //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" shim=eddystone::advertiseUrl + function advertiseUrl(url: string, powerLevel: number): void; + + /** + * Stops advertising Eddystone end points + */ + //% blockId=eddystone_stop_advertising block="eddystone stop advertising" shim=eddystone::stopAdvertising + function stopAdvertising(): void; +} + +// Auto-generated. Do not edit. Really. diff --git a/pxtarget.json b/pxtarget.json index 54a0ed36..5833d9e5 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -9,7 +9,8 @@ "libs/core", "libs/radio", "libs/devices", - "libs/bluetooth" + "libs/bluetooth", + "libs/eddystone" ], "cloud": { "workspace": false, From f0947cddaad23e8b66c5ed6a9ca38cfa417c7338 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 29 Nov 2016 23:39:52 -0800 Subject: [PATCH 2/8] updated signatures --- libs/eddystone/eddystone.cpp | 11 ++++++----- libs/eddystone/eddystone.ts | 2 +- libs/eddystone/shims.d.ts | 5 ++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libs/eddystone/eddystone.cpp b/libs/eddystone/eddystone.cpp index 879a0a84..c5ecf11a 100644 --- a/libs/eddystone/eddystone.cpp +++ b/libs/eddystone/eddystone.cpp @@ -1,5 +1,4 @@ #include "pxt.h" -#include "Microbit.h" #include "MicroBitEddystone.h" using namespace pxt; @@ -13,12 +12,14 @@ namespace eddystone { /** * 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 + * @param connectable true to keep bluetooth connectable for other services, false otherwise */ //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" - void advertiseUrl(StringData* url, int powerLevel) { - int power = CALIBRATED_POWERS[min(7, max(0, powerLevel))]; - ManagedString murl(url) - uBit.bleManager.advertiseEddystoneUrl(murl, power, false); + void advertiseUrl(StringData* url, int power, bool connectable) { + int8_t level = CALIBRATED_POWERS[min(7, max(0, power))]; + uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level, connectable); } /** diff --git a/libs/eddystone/eddystone.ts b/libs/eddystone/eddystone.ts index efc810ad..12c902b1 100644 --- a/libs/eddystone/eddystone.ts +++ b/libs/eddystone/eddystone.ts @@ -4,7 +4,7 @@ //% color=#0082FB weight=19 namespace eddystone { //% shim=eddystone::advertiseUrl - export function advertiseUrl(url: string, powerLevel: number) { + export function advertiseUrl(url: string, powerLevel: number, connectable: boolean) { } //% shim=eddystone::stopAdvertising diff --git a/libs/eddystone/shims.d.ts b/libs/eddystone/shims.d.ts index 09cd073e..7db54b41 100644 --- a/libs/eddystone/shims.d.ts +++ b/libs/eddystone/shims.d.ts @@ -9,9 +9,12 @@ declare namespace eddystone { /** * 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 + * @param connectable true to keep bluetooth connectable for other services, false otherwise */ //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" shim=eddystone::advertiseUrl - function advertiseUrl(url: string, powerLevel: number): void; + function advertiseUrl(url: string, power: number, connectable: boolean): void; /** * Stops advertising Eddystone end points From be0984cc4ab17b5c4e149abc928eb82e20760af0 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 30 Nov 2016 04:06:15 -0800 Subject: [PATCH 3/8] integrating eddystone into bluetooth package --- docs/reference.md | 6 ++-- docs/reference/bluetooth.md | 12 ++++++- docs/reference/bluetooth/advertise-url.md | 37 +++++++++++++++++++ docs/reference/bluetooth/stop-advertising.md | 26 ++++++++++++++ libs/bluetooth/bluetooth.cpp | 28 +++++++++++++-- libs/bluetooth/bluetooth.ts | 9 +++++ libs/bluetooth/pxt.json | 4 ++- libs/bluetooth/shims.d.ts | 18 ++++++++++ libs/core/dal.d.ts | 2 +- libs/eddystone/eddystone.cpp | 32 ----------------- libs/eddystone/eddystone.ts | 13 ------- libs/eddystone/enums.d.ts | 5 --- libs/eddystone/pxt.json | 38 -------------------- libs/eddystone/shims.d.ts | 26 -------------- pxtarget.json | 5 ++- 15 files changed, 135 insertions(+), 126 deletions(-) create mode 100644 docs/reference/bluetooth/advertise-url.md create mode 100644 docs/reference/bluetooth/stop-advertising.md delete mode 100644 libs/eddystone/eddystone.cpp delete mode 100644 libs/eddystone/eddystone.ts delete mode 100644 libs/eddystone/enums.d.ts delete mode 100644 libs/eddystone/pxt.json delete mode 100644 libs/eddystone/shims.d.ts diff --git a/docs/reference.md b/docs/reference.md index aca07c1e..257425d3 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -29,21 +29,19 @@ control.inBackground(() => { }); ``` -## bluetooth and Eddystone +## Bluetooth ```namespaces devices.tellCameraTo(MesCameraEvent.TakePhoto); bluetooth.onBluetoothConnected(() => {}); -eddystone.advertiseUrl("https://pxt.io", 6); ``` ```package radio devices bluetooth -eddystone ``` ### See Also -[basic](/reference/basic), [input](/reference/input), [music](/reference/music), [led](/reference/led), [Math (blocks)](/blocks/math), [String](/reference/types/string), [game](/reference/game), [images](/reference/images), [pins](/reference/pins), [serial](/reference/serial), [control](/reference/control), [radio](/reference/radio), [devices](/reference/devices), [bluetooth](/reference/bluetooth), [eddystone](/reference/eddystone) +[basic](/reference/basic), [input](/reference/input), [music](/reference/music), [led](/reference/led), [Math (blocks)](/blocks/math), [String](/reference/types/string), [game](/reference/game), [images](/reference/images), [pins](/reference/pins), [serial](/reference/serial), [control](/reference/control), [radio](/reference/radio), [devices](/reference/devices), [bluetooth](/reference/bluetooth) diff --git a/docs/reference/bluetooth.md b/docs/reference/bluetooth.md index d2fa66b2..21e850bb 100644 --- a/docs/reference/bluetooth.md +++ b/docs/reference/bluetooth.md @@ -31,6 +31,13 @@ bluetooth.uartWriteNumber(0); bluetooth.uartWriteValue("", 0); ``` +## Eddystone + +```cards +bluetooth.advertiseUrl("https://pxt.microbit.org/", 7); +bluetooth.stopAdvertising(); +``` + ```package bluetooth ``` @@ -47,4 +54,7 @@ For more advanced information on the @boardname@ Bluetooth UART service includin [uartWriteString](/reference/bluetooth/uart-write-string), [uartWriteNumber](/reference/bluetooth/uart-write-number), [uartWriteValue](/reference/bluetooth/uart-write-value), -[onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected), [onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected) +[onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected), +[onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected), +[advertiseUrl](/reference/bluetooth/advertise-url), +[stopAdvertising](/reference/bluetooth/stop-advertising) diff --git a/docs/reference/bluetooth/advertise-url.md b/docs/reference/bluetooth/advertise-url.md new file mode 100644 index 00000000..e969d21c --- /dev/null +++ b/docs/reference/bluetooth/advertise-url.md @@ -0,0 +1,37 @@ +# Avertise Url + +Advertises a URL via the Eddystone protocol over Bluetooth. + +## ~hint + +### Eddystone + +Bluetooth beacons are used to indicate proximity to a place or object of interest. +Beacons use Bluetooth advertising to broadcast a small amount of data, +which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application. + +There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data. +iBeacon is Apple's beacon message format. Eddystone comes from Google. + +Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ . + +## ~ + +```sig +bluetooth.advertiseUrl("https://pxt.microbit.org/", 7); +``` + +### Parameters + +* ``url`` - a [string](/reference/types/string) containing the URL to broadcast, at most 18 characters long +* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range). + +### Example: Broadcast a secret code + +```blocks +bluetooth.advertiseUrl("https://pxt.io?secret=42") +``` + +## See Also + +[stop-advertising](/reference/bluetooth/stop-advertising) diff --git a/docs/reference/bluetooth/stop-advertising.md b/docs/reference/bluetooth/stop-advertising.md new file mode 100644 index 00000000..27a2ce29 --- /dev/null +++ b/docs/reference/bluetooth/stop-advertising.md @@ -0,0 +1,26 @@ +# Stop Advertising + +Stops advertising URL via the Eddystone protocol over Bluetooth. + +## ~hint + +### Eddystone + +Bluetooth beacons are used to indicate proximity to a place or object of interest. +Beacons use Bluetooth advertising to broadcast a small amount of data, +which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application. + +There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data. +iBeacon is Apple's beacon message format. Eddystone comes from Google. + +Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ . + +## ~ + +```sig +bluetooth.stop-advertising(); +``` + +## See Also + +[advertise-url](/reference/bluetooth/advertise-url) diff --git a/libs/bluetooth/bluetooth.cpp b/libs/bluetooth/bluetooth.cpp index 007f5518..fc2add8e 100644 --- a/libs/bluetooth/bluetooth.cpp +++ b/libs/bluetooth/bluetooth.cpp @@ -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(); + } } \ No newline at end of file diff --git a/libs/bluetooth/bluetooth.ts b/libs/bluetooth/bluetooth.ts index 3f480408..99af025c 100644 --- a/libs/bluetooth/bluetooth.ts +++ b/libs/bluetooth/bluetooth.ts @@ -46,4 +46,13 @@ namespace bluetooth { // dummy implementation for simulator return "???" } + + //% shim=bluetooth::advertiseUrl + export function advertiseUrl(url: string, powerLevel: number) { + } + + //% shim=bluetooth::stopAdvertising + export function stopAdvertising() { + } + } diff --git a/libs/bluetooth/pxt.json b/libs/bluetooth/pxt.json index 51f109d8..680fc305 100644 --- a/libs/bluetooth/pxt.json +++ b/libs/bluetooth/pxt.json @@ -25,7 +25,9 @@ "tx_power": 6, "dfu_service": 1, "event_service": 1, - "device_info_service": 1 + "device_info_service": 1, + "eddystone_url": 1, + "eddystone_uid": 0 }, "gatt_table_size": "0x700" } diff --git a/libs/bluetooth/shims.d.ts b/libs/bluetooth/shims.d.ts index 58c52fa9..1df83b16 100644 --- a/libs/bluetooth/shims.d.ts +++ b/libs/bluetooth/shims.d.ts @@ -80,6 +80,24 @@ declare namespace bluetooth { //% blockId=bluetooth_on_disconnected block="on bluetooth disconnected" //% parts="bluetooth" shim=bluetooth::onBluetoothDisconnected function onBluetoothDisconnected(body: () => void): void; + + /** + * 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 shim=bluetooth::advertiseUrl + function advertiseUrl(url: string, power: number): void; + + /** + * Stops advertising Eddystone end points + */ + //% blockId=eddystone_stop_advertising block="eddystone stop advertising" + //% parts=bluetooth + //% help=bluetooth/stop-advertising shim=bluetooth::stopAdvertising + function stopAdvertising(): void; } // Auto-generated. Do not edit. Really. diff --git a/libs/core/dal.d.ts b/libs/core/dal.d.ts index 7e7f4134..6dae7e1f 100644 --- a/libs/core/dal.d.ts +++ b/libs/core/dal.d.ts @@ -80,13 +80,13 @@ declare const enum DAL { MICROBIT_BLE_POWER_LEVELS = 8, MICROBIT_BLE_MAXIMUM_BONDS = 4, MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL = 400, + MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER = 0xF0, // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitButtonService.h // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitDFUService.h MICROBIT_DFU_OPCODE_START_DFU = 1, MICROBIT_DFU_HISTOGRAM_WIDTH = 5, MICROBIT_DFU_HISTOGRAM_HEIGHT = 5, // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitEddystone.h - MICROBIT_BLE_EDDYSTONE_URL_ADV_INTERVAL = 400, // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitEventService.h // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitIOPinService.h MICROBIT_IO_PIN_SERVICE_PINCOUNT = 19, diff --git a/libs/eddystone/eddystone.cpp b/libs/eddystone/eddystone.cpp deleted file mode 100644 index c5ecf11a..00000000 --- a/libs/eddystone/eddystone.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "pxt.h" -#include "MicroBitEddystone.h" - -using namespace pxt; - -/** -* Support for Eddystone beacons -*/ -//% color=#0082FB weight=19 -namespace eddystone { - 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 - * @param connectable true to keep bluetooth connectable for other services, false otherwise - */ - //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" - void advertiseUrl(StringData* url, int power, bool connectable) { - int8_t level = CALIBRATED_POWERS[min(7, max(0, power))]; - uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level, connectable); - } - - /** - * Stops advertising Eddystone end points - */ - //% blockId=eddystone_stop_advertising block="eddystone stop advertising" - void stopAdvertising() { - uBit.bleManager.stopAdvertising(); - } -} diff --git a/libs/eddystone/eddystone.ts b/libs/eddystone/eddystone.ts deleted file mode 100644 index 12c902b1..00000000 --- a/libs/eddystone/eddystone.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** -* Support for Eddystone beacons -*/ -//% color=#0082FB weight=19 -namespace eddystone { - //% shim=eddystone::advertiseUrl - export function advertiseUrl(url: string, powerLevel: number, connectable: boolean) { - } - - //% shim=eddystone::stopAdvertising - export function stopAdvertising() { - } -} diff --git a/libs/eddystone/enums.d.ts b/libs/eddystone/enums.d.ts deleted file mode 100644 index 7c80d5f7..00000000 --- a/libs/eddystone/enums.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -// Auto-generated. Do not edit. -declare namespace eddystone { -} - -// Auto-generated. Do not edit. Really. diff --git a/libs/eddystone/pxt.json b/libs/eddystone/pxt.json deleted file mode 100644 index 76388b95..00000000 --- a/libs/eddystone/pxt.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "eddystone", - "description": "Eddystone beacon support", - "dependencies": { - "core": "file:../core" - }, - "files": [ - "eddystone.cpp", - "eddystone.ts", - "enums.d.ts", - "shims.d.ts" - ], - "yotta": { - "config": { - "microbit-dal": { - "bluetooth": { - "enabled": 1, - "eddystone_url": 1, - "eddystone_uid": 0 - } - } - }, - "optionalConfig": { - "microbit-dal": { - "bluetooth": { - "pairing_mode": 0, - "private_addressing": 0, - "whitelist": 0, - "advertising_timeout": 0, - "tx_power": 6, - "dfu_service": 0, - "event_service": 0, - "device_info_service": 0 - } - } - } - } -} \ No newline at end of file diff --git a/libs/eddystone/shims.d.ts b/libs/eddystone/shims.d.ts deleted file mode 100644 index 7db54b41..00000000 --- a/libs/eddystone/shims.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Auto-generated. Do not edit. - - - /** - * Support for Eddystone beacons - */ - //% color=#0082FB weight=19 -declare namespace eddystone { - - /** - * 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 - * @param connectable true to keep bluetooth connectable for other services, false otherwise - */ - //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" shim=eddystone::advertiseUrl - function advertiseUrl(url: string, power: number, connectable: boolean): void; - - /** - * Stops advertising Eddystone end points - */ - //% blockId=eddystone_stop_advertising block="eddystone stop advertising" shim=eddystone::stopAdvertising - function stopAdvertising(): void; -} - -// Auto-generated. Do not edit. Really. diff --git a/pxtarget.json b/pxtarget.json index e426ec06..cf55e6ca 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -9,8 +9,7 @@ "libs/core", "libs/radio", "libs/devices", - "libs/bluetooth", - "libs/eddystone" + "libs/bluetooth" ], "cloud": { "workspace": false, @@ -163,7 +162,7 @@ "yottaTarget": "bbc-microbit-classic-gcc", "yottaCorePackage": "microbit", "githubCorePackage": "lancaster-university/microbit", - "gittag": "v2.0.0-rc6", + "gittag": "v2.0.0-rc7", "serviceId": "microbit" }, "serial": { From adef3a64870458cd10119961b6d622e4de6088bb Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 30 Nov 2016 04:19:17 -0800 Subject: [PATCH 4/8] updated docs --- docs/reference/bluetooth/advertise-url.md | 6 +++++- docs/reference/bluetooth/stop-advertising.md | 10 +++++++++- libs/bluetooth/bluetooth.cpp | 8 ++++---- libs/bluetooth/shims.d.ts | 8 ++++---- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/reference/bluetooth/advertise-url.md b/docs/reference/bluetooth/advertise-url.md index e969d21c..9a0a808d 100644 --- a/docs/reference/bluetooth/advertise-url.md +++ b/docs/reference/bluetooth/advertise-url.md @@ -29,9 +29,13 @@ bluetooth.advertiseUrl("https://pxt.microbit.org/", 7); ### Example: Broadcast a secret code ```blocks -bluetooth.advertiseUrl("https://pxt.io?secret=42") +bluetooth.advertiseUrl("https://pxt.io?secret=42", 7); ``` ## See Also [stop-advertising](/reference/bluetooth/stop-advertising) + +```package +bluetooth +``` \ No newline at end of file diff --git a/docs/reference/bluetooth/stop-advertising.md b/docs/reference/bluetooth/stop-advertising.md index 27a2ce29..1f0c41c4 100644 --- a/docs/reference/bluetooth/stop-advertising.md +++ b/docs/reference/bluetooth/stop-advertising.md @@ -18,9 +18,17 @@ Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ ## ~ ```sig -bluetooth.stop-advertising(); +bluetooth.stopAdvertising(); ``` ## See Also [advertise-url](/reference/bluetooth/advertise-url) + +```blocks +bluetooth.stopAdvertising(); +``` + +```package +bluetooth +``` \ No newline at end of file diff --git a/libs/bluetooth/bluetooth.cpp b/libs/bluetooth/bluetooth.cpp index fc2add8e..82424b74 100644 --- a/libs/bluetooth/bluetooth.cpp +++ b/libs/bluetooth/bluetooth.cpp @@ -127,8 +127,8 @@ namespace bluetooth { * @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 + //% blockId=eddystone_advertise_url block="advertise url %url|power %power" + //% parts=bluetooth weight=11 //% help=bluetooth/advertise-url void advertiseUrl(StringData* url, int power) { int8_t level = CALIBRATED_POWERS[min(7, max(0, power))]; @@ -138,8 +138,8 @@ namespace bluetooth { /** * Stops advertising Eddystone end points */ - //% blockId=eddystone_stop_advertising block="eddystone stop advertising" - //% parts=bluetooth + //% blockId=eddystone_stop_advertising block="stop advertising" + //% parts=bluetooth weight=10 //% help=bluetooth/stop-advertising void stopAdvertising() { uBit.bleManager.stopAdvertising(); diff --git a/libs/bluetooth/shims.d.ts b/libs/bluetooth/shims.d.ts index 1df83b16..adce4f03 100644 --- a/libs/bluetooth/shims.d.ts +++ b/libs/bluetooth/shims.d.ts @@ -86,16 +86,16 @@ declare namespace bluetooth { * @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 + //% blockId=eddystone_advertise_url block="advertise url %url|power %power" + //% parts=bluetooth weight=11 //% help=bluetooth/advertise-url shim=bluetooth::advertiseUrl function advertiseUrl(url: string, power: number): void; /** * Stops advertising Eddystone end points */ - //% blockId=eddystone_stop_advertising block="eddystone stop advertising" - //% parts=bluetooth + //% blockId=eddystone_stop_advertising block="stop advertising" + //% parts=bluetooth weight=10 //% help=bluetooth/stop-advertising shim=bluetooth::stopAdvertising function stopAdvertising(): void; } From d873cbb6c3b8d757cabe2378b74987208ec64dd5 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 30 Nov 2016 04:24:52 -0800 Subject: [PATCH 5/8] updated api definitions --- docs/reference/bluetooth/stop-advertising.md | 12 ++++++++---- libs/bluetooth/_locales/bluetooth-jsdoc-strings.json | 4 ++++ libs/bluetooth/_locales/bluetooth-strings.json | 2 ++ libs/bluetooth/bluetooth.cpp | 6 +++--- libs/bluetooth/bluetooth.ts | 9 --------- libs/bluetooth/shims.d.ts | 6 +++--- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/docs/reference/bluetooth/stop-advertising.md b/docs/reference/bluetooth/stop-advertising.md index 1f0c41c4..82ce25ba 100644 --- a/docs/reference/bluetooth/stop-advertising.md +++ b/docs/reference/bluetooth/stop-advertising.md @@ -21,14 +21,18 @@ Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ bluetooth.stopAdvertising(); ``` +### Example: stop advertising on button pressed + +```blocks +input.onButtonPressed(Button.A, () => { + bluetooth.stopAdvertising(); +}) +``` + ## See Also [advertise-url](/reference/bluetooth/advertise-url) -```blocks -bluetooth.stopAdvertising(); -``` - ```package bluetooth ``` \ No newline at end of file diff --git a/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json b/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json index ca3ba8ef..b22f5b9c 100644 --- a/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json +++ b/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json @@ -1,5 +1,8 @@ { "bluetooth": "Support for additional Bluetooth services.", + "bluetooth.advertiseUrl": "Advertise an Eddystone URL", + "bluetooth.advertiseUrl|param|power": "power level between 0 and 7, e.g.: 7", + "bluetooth.advertiseUrl|param|url": "the url to transmit. Must be no longer than the supported eddystone url length", "bluetooth.onBluetoothConnected": "Register code to run when the micro:bit is connected to over Bluetooth", "bluetooth.onBluetoothConnected|param|body": "Code to run when a Bluetooth connection is established", "bluetooth.onBluetoothDisconnected": "Register code to run when a bluetooth connection to the micro:bit is lost", @@ -11,6 +14,7 @@ "bluetooth.startMagnetometerService": "Starts the Bluetooth magnetometer service", "bluetooth.startTemperatureService": "Starts the Bluetooth temperature service", "bluetooth.startUartService": "Starts the Bluetooth UART service", + "bluetooth.stopAdvertising": "Stops advertising Eddystone end points", "bluetooth.uartReadUntil": "Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered.", "bluetooth.uartWriteNumber": "Prints a numeric value to the serial", "bluetooth.uartWriteString": "Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.", diff --git a/libs/bluetooth/_locales/bluetooth-strings.json b/libs/bluetooth/_locales/bluetooth-strings.json index ad894e0c..f4ac4022 100644 --- a/libs/bluetooth/_locales/bluetooth-strings.json +++ b/libs/bluetooth/_locales/bluetooth-strings.json @@ -1,4 +1,5 @@ { + "bluetooth.advertiseUrl|block": "bluetooth advertise url %url|with power %power", "bluetooth.onBluetoothConnected|block": "on bluetooth connected", "bluetooth.onBluetoothDisconnected|block": "on bluetooth disconnected", "bluetooth.startAccelerometerService|block": "bluetooth accelerometer service", @@ -8,6 +9,7 @@ "bluetooth.startMagnetometerService|block": "bluetooth magnetometer service", "bluetooth.startTemperatureService|block": "bluetooth temperature service", "bluetooth.startUartService|block": "bluetooth uart service", + "bluetooth.stopAdvertising|block": "bluetooth stop advertising", "bluetooth.uartReadUntil|block": "bluetooth uart|read until %del=serial_delimiter_conv", "bluetooth.uartWriteNumber|block": "bluetooth uart|write number %value", "bluetooth.uartWriteString|block": "bluetooth uart|write string %data", diff --git a/libs/bluetooth/bluetooth.cpp b/libs/bluetooth/bluetooth.cpp index 82424b74..37d217ac 100644 --- a/libs/bluetooth/bluetooth.cpp +++ b/libs/bluetooth/bluetooth.cpp @@ -127,8 +127,8 @@ namespace bluetooth { * @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="advertise url %url|power %power" - //% parts=bluetooth weight=11 + //% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power" + //% parts=bluetooth weight=11 blockGap=8 //% help=bluetooth/advertise-url void advertiseUrl(StringData* url, int power) { int8_t level = CALIBRATED_POWERS[min(7, max(0, power))]; @@ -138,7 +138,7 @@ namespace bluetooth { /** * Stops advertising Eddystone end points */ - //% blockId=eddystone_stop_advertising block="stop advertising" + //% blockId=eddystone_stop_advertising block="bluetooth stop advertising" //% parts=bluetooth weight=10 //% help=bluetooth/stop-advertising void stopAdvertising() { diff --git a/libs/bluetooth/bluetooth.ts b/libs/bluetooth/bluetooth.ts index 99af025c..3f480408 100644 --- a/libs/bluetooth/bluetooth.ts +++ b/libs/bluetooth/bluetooth.ts @@ -46,13 +46,4 @@ namespace bluetooth { // dummy implementation for simulator return "???" } - - //% shim=bluetooth::advertiseUrl - export function advertiseUrl(url: string, powerLevel: number) { - } - - //% shim=bluetooth::stopAdvertising - export function stopAdvertising() { - } - } diff --git a/libs/bluetooth/shims.d.ts b/libs/bluetooth/shims.d.ts index adce4f03..57d9e45b 100644 --- a/libs/bluetooth/shims.d.ts +++ b/libs/bluetooth/shims.d.ts @@ -86,15 +86,15 @@ declare namespace bluetooth { * @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="advertise url %url|power %power" - //% parts=bluetooth weight=11 + //% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power" + //% parts=bluetooth weight=11 blockGap=8 //% help=bluetooth/advertise-url shim=bluetooth::advertiseUrl function advertiseUrl(url: string, power: number): void; /** * Stops advertising Eddystone end points */ - //% blockId=eddystone_stop_advertising block="stop advertising" + //% blockId=eddystone_stop_advertising block="bluetooth stop advertising" //% parts=bluetooth weight=10 //% help=bluetooth/stop-advertising shim=bluetooth::stopAdvertising function stopAdvertising(): void; From 097564748c9d3fb72cbb8ecf00b5f4a576fdd8a1 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 30 Nov 2016 04:27:08 -0800 Subject: [PATCH 6/8] fixing simulator --- sim/state/misc.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sim/state/misc.ts b/sim/state/misc.ts index d2d20061..521e9a05 100644 --- a/sim/state/misc.ts +++ b/sim/state/misc.ts @@ -134,7 +134,7 @@ namespace pxsim.devices { export function onSignalStrengthChanged(action: number) { // TODO } - export function signalStrength() : number { + export function signalStrength(): number { // TODO return 0; } @@ -165,18 +165,19 @@ namespace pxsim.bluetooth { export function startUartService(): void { // TODO } - export function uartWrite(s : string): void { - // TODO + export function uartWrite(s: string): void { + serial.writeString(s) } export function uartReadUntil(del: string): string { - // TODO - return "" + return serial.readUntil(del); } - export function onBluetoothConnected(a : RefAction) { + export function onBluetoothConnected(a: RefAction) { // TODO } - export function onBluetoothDisconnected(a : RefAction) { + export function onBluetoothDisconnected(a: RefAction) { // TODO } + export function advertiseUrl(url: string, power: number) { } + export function stopAdvertising() { } } From 97066e1ba4f7940e7b2b9649921fe98997d0d5d2 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 30 Nov 2016 04:30:53 -0800 Subject: [PATCH 7/8] enabling justworks pairing mode for bluetooth --- libs/bluetooth/pxt.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/bluetooth/pxt.json b/libs/bluetooth/pxt.json index 680fc305..81b39877 100644 --- a/libs/bluetooth/pxt.json +++ b/libs/bluetooth/pxt.json @@ -17,9 +17,7 @@ "microbit-dal": { "bluetooth": { "enabled": 1, - "pairing_mode": 1, "private_addressing": 0, - "open": 0, "whitelist": 1, "advertising_timeout": 0, "tx_power": 6, @@ -31,6 +29,15 @@ }, "gatt_table_size": "0x700" } + }, + "optionalConfig": { + "microbit-dal": { + "bluetooth": { + "pairing_mode": 1, + "open": 0, + "security_level": "SECURITY_MODE_ENCRYPTION_WITH_MITM" + } + } } }, "installedVersion": "vzlhfd" From 8d37be7cbe310cd000fc675d311edb4fd05d77a5 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 30 Nov 2016 04:35:24 -0800 Subject: [PATCH 8/8] use optional config to allow override flags in referenced project --- libs/bluetooth/pxt.json | 20 ++++++++++---------- libs/core/pxt.json | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libs/bluetooth/pxt.json b/libs/bluetooth/pxt.json index 81b39877..43f75849 100644 --- a/libs/bluetooth/pxt.json +++ b/libs/bluetooth/pxt.json @@ -16,7 +16,13 @@ "config": { "microbit-dal": { "bluetooth": { - "enabled": 1, + "enabled": 1 + } + } + }, + "optionalConfig": { + "microbit-dal": { + "bluetooth": { "private_addressing": 0, "whitelist": 1, "advertising_timeout": 0, @@ -25,19 +31,13 @@ "event_service": 1, "device_info_service": 1, "eddystone_url": 1, - "eddystone_uid": 0 - }, - "gatt_table_size": "0x700" - } - }, - "optionalConfig": { - "microbit-dal": { - "bluetooth": { + "eddystone_uid": 0, "pairing_mode": 1, "open": 0, "security_level": "SECURITY_MODE_ENCRYPTION_WITH_MITM" } - } + }, + "gatt_table_size": "0x700" } }, "installedVersion": "vzlhfd" diff --git a/libs/core/pxt.json b/libs/core/pxt.json index b79d7634..bca70b9e 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -42,8 +42,7 @@ "public": true, "dependencies": {}, "yotta": { - "configIsJustDefaults": true, - "config": { + "optionalConfig": { "microbit-dal": { "bluetooth": { "enabled": 0