From 3c905503b70c8d2fffabe6c564426da8b343901a Mon Sep 17 00:00:00 2001 From: Evelyn Eastmond Date: Sat, 22 Sep 2018 14:48:41 -0400 Subject: [PATCH] Adding extension ids to customize error alerts for extensions. --- src/extensions/scratch3_ev3/index.js | 7 ++++++- src/extensions/scratch3_microbit/index.js | 12 +++--------- src/extensions/scratch3_wedo2/index.js | 7 ++++++- src/io/ble.js | 3 ++- src/io/bt.js | 4 +++- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/extensions/scratch3_ev3/index.js b/src/extensions/scratch3_ev3/index.js index d2243d347..0f27c11e4 100644 --- a/src/extensions/scratch3_ev3/index.js +++ b/src/extensions/scratch3_ev3/index.js @@ -408,6 +408,11 @@ class EV3 { this._runtime = runtime; this._runtime.on('PROJECT_STOP_ALL', this.stopAll.bind(this)); + /** + * The id of the extension this peripheral belongs to. + */ + this._extensionId = extensionId; + /** * A list of the names of the sensors connected in ports 1,2,3,4. * @type {string[]} @@ -548,7 +553,7 @@ class EV3 { * Called by the runtime when user wants to scan for an EV3 peripheral. */ scan () { - this._bt = new BT(this._runtime, 'EV3', { + this._bt = new BT(this._runtime, this._extensionId, { majorDeviceClass: 8, minorDeviceClass: 1 }, this._onConnect, this._onMessage); diff --git a/src/extensions/scratch3_microbit/index.js b/src/extensions/scratch3_microbit/index.js index f0115135a..0c9fc5c15 100644 --- a/src/extensions/scratch3_microbit/index.js +++ b/src/extensions/scratch3_microbit/index.js @@ -73,6 +73,9 @@ class MicroBit { this._ble = null; this._runtime.registerPeripheralExtension(extensionId, this); + /** + * The id of the extension this peripheral belongs to. + */ this._extensionId = extensionId; /** @@ -134,15 +137,6 @@ class MicroBit { this.disconnect = this.disconnect.bind(this); this._onConnect = this._onConnect.bind(this); this._onMessage = this._onMessage.bind(this); - - this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, { - message: `Scratch lost connection to peripheral.`, - extensionId: this._extensionId - }); - this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, { - message: `Scratch lost connection to peripheral.`, - extensionId: 2 - }); } /** diff --git a/src/extensions/scratch3_wedo2/index.js b/src/extensions/scratch3_wedo2/index.js index 464f5c3e6..f4ccdc3ce 100644 --- a/src/extensions/scratch3_wedo2/index.js +++ b/src/extensions/scratch3_wedo2/index.js @@ -357,6 +357,11 @@ class WeDo2 { this._runtime = runtime; this._runtime.on('PROJECT_STOP_ALL', this.stopAll.bind(this)); + /** + * The id of the extension this peripheral belongs to. + */ + this._extensionId = extensionId; + /** * A list of the ids of the motors or sensors in ports 1 and 2. * @type {string[]} @@ -549,7 +554,7 @@ class WeDo2 { * Called by the runtime when user wants to scan for a WeDo 2.0 peripheral. */ scan () { - this._ble = new BLE(this._runtime, 'WeDo 2', { + this._ble = new BLE(this._runtime, this._extensionId, { filters: [{ services: [BLEService.DEVICE_SERVICE] }], diff --git a/src/io/ble.js b/src/io/ble.js index f5a681ba8..c5a369b5e 100644 --- a/src/io/ble.js +++ b/src/io/ble.js @@ -174,8 +174,9 @@ class BLE extends JSONRPCWebSocket { _sendError (/* e */) { this.disconnect(); // log.error(`BLE error: ${JSON.stringify(e)}`); + console.log('extension id sending: ' + this._extensionId); this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, { - message: `Scratch lost connection to ${this._peripheralType}.`, + message: `Scratch lost connection to`, extensionId: this._extensionId }); } diff --git a/src/io/bt.js b/src/io/bt.js index 41438ec00..38e0d446e 100644 --- a/src/io/bt.js +++ b/src/io/bt.js @@ -117,8 +117,10 @@ class BT extends JSONRPCWebSocket { _sendError (/* e */) { this.disconnect(); // log.error(`BT error: ${JSON.stringify(e)}`); + console.log('extension id sending: ' + this._extensionId); this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, { - message: `Scratch lost connection to ${this._peripheralType}.` + message: `Scratch lost connection to`, + extensionId: this._extensionId }); }