From 0da5a5a349fe52ff4591d47d42445928e097fbe3 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 6 Dec 2016 11:32:22 -0800 Subject: [PATCH 01/11] Bump pxt-core to 0.5.91 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ecfaf610..47fed783 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,6 @@ "semantic-ui-less": "^2.2.4" }, "dependencies": { - "pxt-core": "0.5.90" + "pxt-core": "0.5.91" } } From 485a42758c012a8fc32078bed4dbe6068b04a939 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 6 Dec 2016 11:32:24 -0800 Subject: [PATCH 02/11] 0.6.31 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47fed783..57c651f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.6.30", + "version": "0.6.31", "description": "micro:bit target for PXT", "keywords": [ "JavaScript", From 2ae21efb7b9d2e6ffb432c72d88f4d9fbf32b8b9 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Tue, 6 Dec 2016 15:06:16 -0800 Subject: [PATCH 03/11] Moving blockly toolbox button margins to target. --- theme/style.less | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/theme/style.less b/theme/style.less index 3fa6d9a2..6b35e3af 100644 --- a/theme/style.less +++ b/theme/style.less @@ -115,6 +115,11 @@ .organization { top: auto; } + /* Blockly Toolbox buttons */ + #blocklyToolboxButtons { + margin-right: 0.5rem; + margin-left: 0.5rem; + } } /* Small Monitor */ @@ -122,6 +127,11 @@ .organization { top: auto; } + /* Blockly Toolbox buttons */ + #blocklyToolboxButtons { + margin-right: 1rem; + margin-left: 1rem; + } } /* Large Monitor */ @@ -130,4 +140,9 @@ width: 230px; padding-left: 1rem; } + /* Blockly Toolbox buttons */ + #blocklyToolboxButtons { + margin-right: 2rem; + margin-left: 2rem; + } } From d457c3e8d0c4dd141673e0c7a637532dad2cebab Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 6 Dec 2016 16:19:35 -0800 Subject: [PATCH 04/11] exposing delete in blocks --- libs/core/game.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libs/core/game.ts b/libs/core/game.ts index c84ae864..ccd36552 100644 --- a/libs/core/game.ts +++ b/libs/core/game.ts @@ -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); } /** From 1c11a4823bb12ca307f62fed3541f21d65c80cc9 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Tue, 6 Dec 2016 21:48:21 -0800 Subject: [PATCH 05/11] adjusting the blockly flyout opacity. --- theme/style.less | 1 + 1 file changed, 1 insertion(+) diff --git a/theme/style.less b/theme/style.less index 6b35e3af..8dbb1cfc 100644 --- a/theme/style.less +++ b/theme/style.less @@ -61,6 +61,7 @@ .blocklyFlyoutBackground { fill: #525A67 !important; + fill-opacity: 0.5 !important; } /* Remove shadow around blockly blocks */ From 9e5d9787c7c8faae447575664f43ed86f464fa88 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 6 Dec 2016 21:51:51 -0800 Subject: [PATCH 06/11] linking to pxt issue tracker --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 32f14b4a..879d51d8 100644 --- a/README.md +++ b/README.md @@ -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. From 91197c5cec44bc555f4b81f6683fe9af5b73a560 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 7 Dec 2016 08:07:08 -0800 Subject: [PATCH 07/11] updated BLE settings --- libs/bluetooth/pxt.json | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/libs/bluetooth/pxt.json b/libs/bluetooth/pxt.json index 73b13be8..ac852cd5 100644 --- a/libs/bluetooth/pxt.json +++ b/libs/bluetooth/pxt.json @@ -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 - } - } - } } ] }, From 6c11dbcdf4310617d3cab81b16a23b8e1683e2e2 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 7 Dec 2016 09:05:03 -0800 Subject: [PATCH 08/11] added setTransmitPower in BLE --- docs/reference/bluetooth.md | 1 + .../reference/bluetooth/set-transmit-power.md | 26 ++++++++++++++++++ .../_locales/bluetooth-jsdoc-strings.json | 5 +++- .../bluetooth/_locales/bluetooth-strings.json | 3 ++- libs/bluetooth/bluetooth.cpp | 27 +++++++++++++------ libs/bluetooth/shims.d.ts | 17 +++++++++--- sim/state/misc.ts | 3 ++- 7 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 docs/reference/bluetooth/set-transmit-power.md diff --git a/docs/reference/bluetooth.md b/docs/reference/bluetooth.md index 21e850bb..99ce0a45 100644 --- a/docs/reference/bluetooth.md +++ b/docs/reference/bluetooth.md @@ -19,6 +19,7 @@ bluetooth.startMagnetometerService(); bluetooth.startTemperatureService(); bluetooth.onBluetoothConnected(() => {}); bluetooth.onBluetoothDisconnected(() => {}); +bluetooth.setTransmitPower(7); ``` ## UART diff --git a/docs/reference/bluetooth/set-transmit-power.md b/docs/reference/bluetooth/set-transmit-power.md new file mode 100644 index 00000000..6323f354 --- /dev/null +++ b/docs/reference/bluetooth/set-transmit-power.md @@ -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 +``` diff --git a/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json b/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json index b22f5b9c..df1ab95e 100644 --- a/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json +++ b/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json @@ -1,12 +1,15 @@ { "bluetooth": "Support for additional Bluetooth services.", "bluetooth.advertiseUrl": "Advertise an Eddystone URL", + "bluetooth.advertiseUrl|param|connectable": "true to keep bluetooth connectable for other services, false otherwise.", "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|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.", diff --git a/libs/bluetooth/_locales/bluetooth-strings.json b/libs/bluetooth/_locales/bluetooth-strings.json index f4ac4022..70761646 100644 --- a/libs/bluetooth/_locales/bluetooth-strings.json +++ b/libs/bluetooth/_locales/bluetooth-strings.json @@ -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", diff --git a/libs/bluetooth/bluetooth.cpp b/libs/bluetooth/bluetooth.cpp index 37d217ac..2ee3cde7 100644 --- a/libs/bluetooth/bluetooth.cpp +++ b/libs/bluetooth/bluetooth.cpp @@ -120,19 +120,30 @@ namespace bluetooth { 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 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, e.g.: 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 = MICROBIT_BLE_POWER_LEVEL[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 + //% 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))); } /** diff --git a/libs/bluetooth/shims.d.ts b/libs/bluetooth/shims.d.ts index 57d9e45b..df6263d9 100644 --- a/libs/bluetooth/shims.d.ts +++ b/libs/bluetooth/shims.d.ts @@ -83,13 +83,22 @@ declare namespace bluetooth { /** * Advertise an Eddystone URL - * @param url the url to transmit. Must be no longer than the supported eddystone url length + * @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, e.g.: 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 + //% blockId=bluetooth_settransmitpower block="bluetooth set transmit power %power" shim=bluetooth::setTransmitPower + function setTransmitPower(power: number): void; /** * Stops advertising Eddystone end points diff --git a/sim/state/misc.ts b/sim/state/misc.ts index 521e9a05..da5fe165 100644 --- a/sim/state/misc.ts +++ b/sim/state/misc.ts @@ -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) {} } From 019b00209ef9868d2f5c85b7718170f93b61a15b Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 7 Dec 2016 09:49:19 -0800 Subject: [PATCH 09/11] moving blocks to advanced --- libs/bluetooth/_locales/bluetooth-jsdoc-strings.json | 2 +- libs/bluetooth/bluetooth.cpp | 6 +++--- libs/bluetooth/shims.d.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json b/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json index df1ab95e..2ec425db 100644 --- a/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json +++ b/libs/bluetooth/_locales/bluetooth-jsdoc-strings.json @@ -2,7 +2,7 @@ "bluetooth": "Support for additional Bluetooth services.", "bluetooth.advertiseUrl": "Advertise an Eddystone URL", "bluetooth.advertiseUrl|param|connectable": "true to keep bluetooth connectable for other services, false otherwise.", - "bluetooth.advertiseUrl|param|power": "power level between 0 and 7, e.g.: 7", + "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", diff --git a/libs/bluetooth/bluetooth.cpp b/libs/bluetooth/bluetooth.cpp index 2ee3cde7..e1f2db3e 100644 --- a/libs/bluetooth/bluetooth.cpp +++ b/libs/bluetooth/bluetooth.cpp @@ -123,7 +123,7 @@ namespace bluetooth { /** * Advertise an Eddystone URL * @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, e.g.: 7 + * @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|connectable %connectable" @@ -140,7 +140,7 @@ namespace bluetooth { * 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 + //% 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))); @@ -151,7 +151,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(); } diff --git a/libs/bluetooth/shims.d.ts b/libs/bluetooth/shims.d.ts index df6263d9..e62b991f 100644 --- a/libs/bluetooth/shims.d.ts +++ b/libs/bluetooth/shims.d.ts @@ -84,7 +84,7 @@ declare namespace bluetooth { /** * Advertise an Eddystone URL * @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, e.g.: 7 + * @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|connectable %connectable" @@ -96,7 +96,7 @@ declare namespace bluetooth { * 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 + //% 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; @@ -105,7 +105,7 @@ declare namespace bluetooth { */ //% 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; } From c85b6f95079852ea007da53cd1ec516abeccb7f2 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 7 Dec 2016 11:37:33 -0800 Subject: [PATCH 10/11] using calibrated powers for Eddystone --- libs/bluetooth/bluetooth.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/bluetooth/bluetooth.cpp b/libs/bluetooth/bluetooth.cpp index e1f2db3e..75622de9 100644 --- a/libs/bluetooth/bluetooth.cpp +++ b/libs/bluetooth/bluetooth.cpp @@ -120,6 +120,7 @@ namespace bluetooth { 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, eg: "https://pxt.io/" @@ -131,7 +132,7 @@ namespace bluetooth { //% 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 = MICROBIT_BLE_POWER_LEVEL[power]; + int8_t level = CALIBRATED_POWERS[power]; uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level, connectable); uBit.bleManager.setTransmitPower(power); } From 21473f5b9b2ce8814213978a55315735e0d6a90a Mon Sep 17 00:00:00 2001 From: Richard Knoll Date: Wed, 7 Dec 2016 15:44:35 -0800 Subject: [PATCH 11/11] Fixing array deallocation leak (#317) * Fixing array deallocation leak * Moving delete down to the individual destroy methods --- libs/core/pxt.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/libs/core/pxt.cpp b/libs/core/pxt.cpp index 4f6188d4..5295de84 100644 --- a/libs/core/pxt.cpp +++ b/libs/core/pxt.cpp @@ -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::iterator itr = allptrs.begin();itr!=allptrs.end();itr++) { (*itr)->print(); - } + } printf("\n"); } #else @@ -341,16 +346,16 @@ namespace pxt { // --------------------------------------------------------------------------- map, 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