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();
}
}

View File

@ -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() {
}
}

View File

@ -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"
}

View File

@ -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.

2
libs/core/dal.d.ts vendored
View File

@ -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,

View File

@ -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();
}
}

View File

@ -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() {
}
}

View File

@ -1,5 +0,0 @@
// Auto-generated. Do not edit.
declare namespace eddystone {
}
// Auto-generated. Do not edit. Really.

View File

@ -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
}
}
}
}
}

View File

@ -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.