Adding extension ids to customize error alerts for extensions.

This commit is contained in:
Evelyn Eastmond 2018-09-22 14:48:41 -04:00
parent ad3328197e
commit 3c905503b7
5 changed files with 20 additions and 13 deletions

View file

@ -408,6 +408,11 @@ class EV3 {
this._runtime = runtime; this._runtime = runtime;
this._runtime.on('PROJECT_STOP_ALL', this.stopAll.bind(this)); 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. * A list of the names of the sensors connected in ports 1,2,3,4.
* @type {string[]} * @type {string[]}
@ -548,7 +553,7 @@ class EV3 {
* Called by the runtime when user wants to scan for an EV3 peripheral. * Called by the runtime when user wants to scan for an EV3 peripheral.
*/ */
scan () { scan () {
this._bt = new BT(this._runtime, 'EV3', { this._bt = new BT(this._runtime, this._extensionId, {
majorDeviceClass: 8, majorDeviceClass: 8,
minorDeviceClass: 1 minorDeviceClass: 1
}, this._onConnect, this._onMessage); }, this._onConnect, this._onMessage);

View file

@ -73,6 +73,9 @@ class MicroBit {
this._ble = null; this._ble = null;
this._runtime.registerPeripheralExtension(extensionId, this); this._runtime.registerPeripheralExtension(extensionId, this);
/**
* The id of the extension this peripheral belongs to.
*/
this._extensionId = extensionId; this._extensionId = extensionId;
/** /**
@ -134,15 +137,6 @@ class MicroBit {
this.disconnect = this.disconnect.bind(this); this.disconnect = this.disconnect.bind(this);
this._onConnect = this._onConnect.bind(this); this._onConnect = this._onConnect.bind(this);
this._onMessage = this._onMessage.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
});
} }
/** /**

View file

@ -357,6 +357,11 @@ class WeDo2 {
this._runtime = runtime; this._runtime = runtime;
this._runtime.on('PROJECT_STOP_ALL', this.stopAll.bind(this)); 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. * A list of the ids of the motors or sensors in ports 1 and 2.
* @type {string[]} * @type {string[]}
@ -549,7 +554,7 @@ class WeDo2 {
* Called by the runtime when user wants to scan for a WeDo 2.0 peripheral. * Called by the runtime when user wants to scan for a WeDo 2.0 peripheral.
*/ */
scan () { scan () {
this._ble = new BLE(this._runtime, 'WeDo 2', { this._ble = new BLE(this._runtime, this._extensionId, {
filters: [{ filters: [{
services: [BLEService.DEVICE_SERVICE] services: [BLEService.DEVICE_SERVICE]
}], }],

View file

@ -174,8 +174,9 @@ class BLE extends JSONRPCWebSocket {
_sendError (/* e */) { _sendError (/* e */) {
this.disconnect(); this.disconnect();
// log.error(`BLE error: ${JSON.stringify(e)}`); // log.error(`BLE error: ${JSON.stringify(e)}`);
console.log('extension id sending: ' + this._extensionId);
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, { this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, {
message: `Scratch lost connection to ${this._peripheralType}.`, message: `Scratch lost connection to`,
extensionId: this._extensionId extensionId: this._extensionId
}); });
} }

View file

@ -117,8 +117,10 @@ class BT extends JSONRPCWebSocket {
_sendError (/* e */) { _sendError (/* e */) {
this.disconnect(); this.disconnect();
// log.error(`BT error: ${JSON.stringify(e)}`); // log.error(`BT error: ${JSON.stringify(e)}`);
console.log('extension id sending: ' + this._extensionId);
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, { this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, {
message: `Scratch lost connection to ${this._peripheralType}.` message: `Scratch lost connection to`,
extensionId: this._extensionId
}); });
} }