From b1fcc51bc82e087b0540ffc077cf779c190ab61c Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 29 Nov 2016 09:21:23 -0800 Subject: [PATCH] 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,