Merge branch 'master' into pr/monacotoolbox
This commit is contained in:
commit
438b745d32
@ -7,6 +7,10 @@ PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt
|
||||
|
||||
[![Build Status](https://travis-ci.org/Microsoft/pxt-microbit.svg?branch=master)](https://travis-ci.org/Microsoft/pxt-microbit)
|
||||
|
||||
## Issue tracking
|
||||
|
||||
All issue tracking for this repo happens at https://github.com/Microsoft/pxt, see you there!
|
||||
|
||||
## Local server
|
||||
|
||||
The local server allows to run the editor and the documentation from your computer.
|
||||
|
@ -19,6 +19,7 @@ bluetooth.startMagnetometerService();
|
||||
bluetooth.startTemperatureService();
|
||||
bluetooth.onBluetoothConnected(() => {});
|
||||
bluetooth.onBluetoothDisconnected(() => {});
|
||||
bluetooth.setTransmitPower(7);
|
||||
```
|
||||
|
||||
## UART
|
||||
|
26
docs/reference/bluetooth/set-transmit-power.md
Normal file
26
docs/reference/bluetooth/set-transmit-power.md
Normal file
@ -0,0 +1,26 @@
|
||||
# Bluetooth Set Transmit Power
|
||||
|
||||
### ~hint
|
||||
![](/static/bluetooth/Bluetooth_SIG.png)
|
||||
|
||||
For another device like a smartphone to use any of the Bluetooth "services" which the @boardname@ has, it must first be [paired with the @boardname@](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the @boardname@ and exchange data relating to many of the @boardname@'s features.
|
||||
|
||||
### ~
|
||||
|
||||
Change the output power level of the transmitter to the given value.
|
||||
|
||||
```sig
|
||||
bluetooth.setTransmitPower(7);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `power`: a [number](/reference/types/number) in the range ``0..7``, where ``0`` is the lowest power and ``7`` is the highest.
|
||||
|
||||
### See also
|
||||
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [@boardname@ Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [@boardname@ Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on @boardname@ resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
@ -1,12 +1,15 @@
|
||||
{
|
||||
"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.advertiseUrl|param|connectable": "true to keep bluetooth connectable for other services, false otherwise.",
|
||||
"bluetooth.advertiseUrl|param|power": "power level between 0 and 7, eg: 7",
|
||||
"bluetooth.advertiseUrl|param|url": "the url to transmit. Must be no longer than the supported eddystone url length, eg: \"https://pxt.io/\"",
|
||||
"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",
|
||||
"bluetooth.onBluetoothDisconnected|param|body": "Code to run when a Bluetooth connection is lost",
|
||||
"bluetooth.setTransmitPower": "Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).",
|
||||
"bluetooth.setTransmitPower|param|power": "power level between 0 (minimal) and 7 (maximum), eg: 7.",
|
||||
"bluetooth.startAccelerometerService": "Starts the Bluetooth accelerometer service",
|
||||
"bluetooth.startButtonService": "Starts the Bluetooth button service",
|
||||
"bluetooth.startIOPinService": "Starts the Bluetooth IO pin service.",
|
||||
|
@ -1,7 +1,8 @@
|
||||
{
|
||||
"bluetooth.advertiseUrl|block": "bluetooth advertise url %url|with power %power",
|
||||
"bluetooth.advertiseUrl|block": "bluetooth advertise url %url|with power %power|connectable %connectable",
|
||||
"bluetooth.onBluetoothConnected|block": "on bluetooth connected",
|
||||
"bluetooth.onBluetoothDisconnected|block": "on bluetooth disconnected",
|
||||
"bluetooth.setTransmitPower|block": "bluetooth set transmit power %power",
|
||||
"bluetooth.startAccelerometerService|block": "bluetooth accelerometer service",
|
||||
"bluetooth.startButtonService|block": "bluetooth button service",
|
||||
"bluetooth.startIOPinService|block": "bluetooth io pin service",
|
||||
|
@ -121,18 +121,30 @@ namespace bluetooth {
|
||||
}
|
||||
|
||||
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 url the url to transmit. Must be no longer than the supported eddystone url length, eg: "https://pxt.io/"
|
||||
* @param power power level between 0 and 7, eg: 7
|
||||
* @param connectable true to keep bluetooth connectable for other services, false otherwise.
|
||||
*/
|
||||
//% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power"
|
||||
//% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power|connectable %connectable"
|
||||
//% 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))];
|
||||
uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level);
|
||||
//% help=bluetooth/advertise-url blockExternalInputs=1
|
||||
void advertiseUrl(StringData* url, int power, bool connectable) {
|
||||
power = min(MICROBIT_BLE_POWER_LEVELS-1, max(0, power));
|
||||
int8_t level = CALIBRATED_POWERS[power];
|
||||
uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level, connectable);
|
||||
uBit.bleManager.setTransmitPower(power);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).
|
||||
* @param power power level between 0 (minimal) and 7 (maximum), eg: 7.
|
||||
*/
|
||||
//% parts=bluetooth weight=5 help=bluetooth/set-transmit-power advanced=true
|
||||
//% blockId=bluetooth_settransmitpower block="bluetooth set transmit power %power"
|
||||
void setTransmitPower(int power) {
|
||||
uBit.bleManager.setTransmitPower(min(MICROBIT_BLE_POWER_LEVELS-1, max(0, power)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,7 +152,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% blockId=eddystone_stop_advertising block="bluetooth stop advertising"
|
||||
//% parts=bluetooth weight=10
|
||||
//% help=bluetooth/stop-advertising
|
||||
//% help=bluetooth/stop-advertising advanced=true
|
||||
void stopAdvertising() {
|
||||
uBit.bleManager.stopAdvertising();
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"private_addressing": 0,
|
||||
"whitelist": 1,
|
||||
"advertising_timeout": 0,
|
||||
"tx_power": 6,
|
||||
"dfu_service": 1,
|
||||
@ -32,8 +31,9 @@
|
||||
"device_info_service": 1,
|
||||
"eddystone_url": 1,
|
||||
"eddystone_uid": 0,
|
||||
"pairing_mode": 1,
|
||||
"open": 0,
|
||||
"pairing_mode": 1,
|
||||
"whitelist": 1,
|
||||
"security_level": "SECURITY_MODE_ENCRYPTION_NO_MITM"
|
||||
}
|
||||
},
|
||||
@ -47,13 +47,14 @@
|
||||
"bluetooth": {
|
||||
"open": 1,
|
||||
"pairing_mode": 0,
|
||||
"whitelist": 0
|
||||
"whitelist": 0,
|
||||
"security_level": null
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "JustWorks pairing (default): Button press to pair via Bluetooth.",
|
||||
"description": "JustWorks pairing (default): Button press to pair.",
|
||||
"config": {
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
@ -66,7 +67,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Passkey pairing: Button press and 6 digit key to pair via Bluetooth.",
|
||||
"description": "Passkey pairing: Button press and 6 digit key to pair.",
|
||||
"config": {
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
@ -77,18 +78,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Disable Event, Device Info and Device Flashing services.",
|
||||
"config": {
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"dfu_service": 0,
|
||||
"event_service": 0,
|
||||
"device_info_service": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
21
libs/bluetooth/shims.d.ts
vendored
21
libs/bluetooth/shims.d.ts
vendored
@ -83,20 +83,29 @@ declare namespace bluetooth {
|
||||
|
||||
/**
|
||||
* 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 url the url to transmit. Must be no longer than the supported eddystone url length, eg: "https://pxt.io/"
|
||||
* @param power power level between 0 and 7, eg: 7
|
||||
* @param connectable true to keep bluetooth connectable for other services, false otherwise.
|
||||
*/
|
||||
//% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power"
|
||||
//% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power|connectable %connectable"
|
||||
//% parts=bluetooth weight=11 blockGap=8
|
||||
//% help=bluetooth/advertise-url shim=bluetooth::advertiseUrl
|
||||
function advertiseUrl(url: string, power: number): void;
|
||||
//% help=bluetooth/advertise-url blockExternalInputs=1 shim=bluetooth::advertiseUrl
|
||||
function advertiseUrl(url: string, power: number, connectable: boolean): void;
|
||||
|
||||
/**
|
||||
* Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).
|
||||
* @param power power level between 0 (minimal) and 7 (maximum), eg: 7.
|
||||
*/
|
||||
//% parts=bluetooth weight=5 help=bluetooth/set-transmit-power advanced=true
|
||||
//% blockId=bluetooth_settransmitpower block="bluetooth set transmit power %power" shim=bluetooth::setTransmitPower
|
||||
function setTransmitPower(power: number): void;
|
||||
|
||||
/**
|
||||
* Stops advertising Eddystone end points
|
||||
*/
|
||||
//% blockId=eddystone_stop_advertising block="bluetooth stop advertising"
|
||||
//% parts=bluetooth weight=10
|
||||
//% help=bluetooth/stop-advertising shim=bluetooth::stopAdvertising
|
||||
//% help=bluetooth/stop-advertising advanced=true shim=bluetooth::stopAdvertising
|
||||
function stopAdvertising(): void;
|
||||
}
|
||||
|
||||
|
@ -589,7 +589,7 @@ namespace game {
|
||||
|
||||
/**
|
||||
* Turns on the sprite (on by default)
|
||||
* @param this TODO
|
||||
* @param this the sprite
|
||||
*/
|
||||
public on(): void {
|
||||
this.setBrightness(255);
|
||||
@ -597,7 +597,7 @@ namespace game {
|
||||
|
||||
/**
|
||||
* Turns off the sprite (on by default)
|
||||
* @param this TODO
|
||||
* @param this the sprite
|
||||
*/
|
||||
public off(): void {
|
||||
this.setBrightness(0);
|
||||
@ -605,8 +605,8 @@ namespace game {
|
||||
|
||||
/**
|
||||
* Set the ``brightness`` of a sprite
|
||||
* @param this TODO
|
||||
* @param brightness TODO
|
||||
* @param this the sprite
|
||||
* @param brightness the brightness from 0 (off) to 255 (on), eg: 255.
|
||||
*/
|
||||
//% parts="ledmatrix"
|
||||
public setBrightness(brightness: number): void {
|
||||
@ -616,8 +616,9 @@ namespace game {
|
||||
|
||||
/**
|
||||
* Reports the ``brightness` of a sprite on the LED screen
|
||||
* @param this TODO
|
||||
* @param this the sprite
|
||||
*/
|
||||
//% parts="ledmatrix"
|
||||
public brightness(): number {
|
||||
let r: number;
|
||||
return this._brightness;
|
||||
@ -625,8 +626,8 @@ namespace game {
|
||||
|
||||
/**
|
||||
* Changes the ``y`` position by the given amount
|
||||
* @param this TODO
|
||||
* @param value TODO
|
||||
* @param this the sprite
|
||||
* @param value the value to change brightness
|
||||
*/
|
||||
public changeBrightnessBy(value: number): void {
|
||||
this.setBrightness(this._brightness + value);
|
||||
@ -643,10 +644,11 @@ namespace game {
|
||||
|
||||
/**
|
||||
* Deletes the sprite from the game engine. All further operation of the sprite will not have any effect.
|
||||
* @param sprite TODO
|
||||
* @param this sprite to delete
|
||||
*/
|
||||
public delete(sprite: LedSprite): void {
|
||||
sprites.removeElement(sprite);
|
||||
//% blockId="game_delete_sprite" block="delete %this"
|
||||
public delete(): void {
|
||||
sprites.removeElement(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +79,7 @@ namespace pxt {
|
||||
|
||||
intcheck(vtable->methods[0] == &RefRecord_destroy, ERR_SIZE, 3);
|
||||
intcheck(vtable->methods[1] == &RefRecord_print, ERR_SIZE, 4);
|
||||
|
||||
|
||||
void *ptr = ::operator new(vtable->numbytes);
|
||||
RefRecord *r = new (ptr) RefRecord(PXT_VTABLE_TO_INT(vtable));
|
||||
memset(r->fields, 0, vtable->numbytes - sizeof(RefRecord));
|
||||
@ -117,7 +117,6 @@ namespace pxt {
|
||||
|
||||
void RefObject::destroy() {
|
||||
((RefObjectMethod)getVTable()->methods[0])(this);
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RefObject::print() {
|
||||
@ -132,6 +131,7 @@ namespace pxt {
|
||||
if (refmask[i]) decr(r->fields[i]);
|
||||
r->fields[i] = 0;
|
||||
}
|
||||
delete r;
|
||||
}
|
||||
|
||||
void RefRecord_print(RefRecord *r)
|
||||
@ -242,6 +242,7 @@ namespace pxt {
|
||||
this->data[i] = 0;
|
||||
}
|
||||
this->data.resize(0);
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RefCollection::print()
|
||||
@ -258,6 +259,7 @@ namespace pxt {
|
||||
decr(fields[i]);
|
||||
fields[i] = 0;
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RefAction::print()
|
||||
@ -272,6 +274,7 @@ namespace pxt {
|
||||
|
||||
void RefLocal::destroy()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
PXT_VTABLE_CTOR(RefLocal) {
|
||||
@ -290,6 +293,7 @@ namespace pxt {
|
||||
void RefRefLocal::destroy()
|
||||
{
|
||||
decr(v);
|
||||
delete this;
|
||||
}
|
||||
|
||||
PXT_VTABLE_BEGIN(RefMap, 0, RefMapMarker)
|
||||
@ -304,6 +308,7 @@ namespace pxt {
|
||||
data[i].val = 0;
|
||||
}
|
||||
data.resize(0);
|
||||
delete this;
|
||||
}
|
||||
|
||||
int RefMap::findIdx(uint32_t key) {
|
||||
@ -328,7 +333,7 @@ namespace pxt {
|
||||
for(std::set<RefObject*>::iterator itr = allptrs.begin();itr!=allptrs.end();itr++)
|
||||
{
|
||||
(*itr)->print();
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#else
|
||||
@ -341,16 +346,16 @@ namespace pxt {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
map<pair<int, int>, Action> handlersMap;
|
||||
|
||||
|
||||
MicroBitEvent lastEvent;
|
||||
|
||||
// We have the invariant that if [dispatchEvent] is registered against the DAL
|
||||
// for a given event, then [handlersMap] contains a valid entry for that
|
||||
// event.
|
||||
void dispatchEvent(MicroBitEvent e) {
|
||||
|
||||
|
||||
lastEvent = e;
|
||||
|
||||
|
||||
Action curr = handlersMap[{ e.source, e.value }];
|
||||
if (curr)
|
||||
runAction1(curr, e.value);
|
||||
@ -383,7 +388,7 @@ namespace pxt {
|
||||
create_fiber((void(*)(void*))runAction0, (void*)a, fiberDone);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void error(ERROR code, int subcode)
|
||||
{
|
||||
@ -435,10 +440,10 @@ namespace pxt {
|
||||
|
||||
// unique group for radio based on source hash
|
||||
// ::touch_develop::micro_bit::radioDefaultGroup = programHash();
|
||||
|
||||
|
||||
// repeat error 4 times and restart as needed
|
||||
microbit_panic_timeout(4);
|
||||
|
||||
|
||||
int32_t ver = *pc++;
|
||||
checkStr(ver == 0x4209, ":( Bad runtime version");
|
||||
|
||||
@ -467,6 +472,6 @@ namespace pxt {
|
||||
{
|
||||
exec_binary((int32_t*)functionsAndBytecode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=2 sw=2 expandtab
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.6.30",
|
||||
"version": "0.6.31",
|
||||
"description": "micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -34,6 +34,6 @@
|
||||
"semantic-ui-less": "^2.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.5.90"
|
||||
"pxt-core": "0.5.91"
|
||||
}
|
||||
}
|
||||
|
@ -177,7 +177,8 @@ namespace pxsim.bluetooth {
|
||||
export function onBluetoothDisconnected(a: RefAction) {
|
||||
// TODO
|
||||
}
|
||||
export function advertiseUrl(url: string, power: number) { }
|
||||
export function advertiseUrl(url: string, power: number, connectable: boolean) { }
|
||||
export function stopAdvertising() { }
|
||||
export function setTransmitPower(power: number) {}
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,7 @@
|
||||
|
||||
.blocklyFlyoutBackground {
|
||||
fill: #525A67 !important;
|
||||
fill-opacity: 0.5 !important;
|
||||
}
|
||||
|
||||
/* Remove shadow around blockly blocks */
|
||||
@ -115,6 +116,11 @@
|
||||
.organization {
|
||||
top: auto;
|
||||
}
|
||||
/* Blockly Toolbox buttons */
|
||||
#blocklyToolboxButtons {
|
||||
margin-right: 0.5rem;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* Small Monitor */
|
||||
@ -122,6 +128,11 @@
|
||||
.organization {
|
||||
top: auto;
|
||||
}
|
||||
/* Blockly Toolbox buttons */
|
||||
#blocklyToolboxButtons {
|
||||
margin-right: 1rem;
|
||||
margin-left: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* Large Monitor */
|
||||
@ -130,4 +141,9 @@
|
||||
width: 230px;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
/* Blockly Toolbox buttons */
|
||||
#blocklyToolboxButtons {
|
||||
margin-right: 2rem;
|
||||
margin-left: 2rem;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user