mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #1607 from evhan55/multiple-alerts
Show customized alerts on hardware extension peripheral errors.
This commit is contained in:
commit
a676970359
6 changed files with 34 additions and 9 deletions
|
@ -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, {
|
||||
this._bt = new BT(this._runtime, this._extensionId, {
|
||||
majorDeviceClass: 8,
|
||||
minorDeviceClass: 1
|
||||
}, this._onConnect, this._onMessage);
|
||||
|
|
|
@ -73,6 +73,11 @@ class MicroBit {
|
|||
this._ble = null;
|
||||
this._runtime.registerPeripheralExtension(extensionId, this);
|
||||
|
||||
/**
|
||||
* The id of the extension this peripheral belongs to.
|
||||
*/
|
||||
this._extensionId = extensionId;
|
||||
|
||||
/**
|
||||
* The most recently received value for each sensor.
|
||||
* @type {Object.<string, number>}
|
||||
|
@ -200,7 +205,7 @@ class MicroBit {
|
|||
* Called by the runtime when user wants to scan for a peripheral.
|
||||
*/
|
||||
scan () {
|
||||
this._ble = new BLE(this._runtime, {
|
||||
this._ble = new BLE(this._runtime, this._extensionId, {
|
||||
filters: [
|
||||
{services: [BLEUUID.service]}
|
||||
]
|
||||
|
|
|
@ -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, {
|
||||
this._ble = new BLE(this._runtime, this._extensionId, {
|
||||
filters: [{
|
||||
services: [BLEService.DEVICE_SERVICE]
|
||||
}],
|
||||
|
|
|
@ -8,10 +8,11 @@ class BLE extends JSONRPCWebSocket {
|
|||
* A BLE peripheral socket object. It handles connecting, over web sockets, to
|
||||
* BLE peripherals, and reading and writing data to them.
|
||||
* @param {Runtime} runtime - the Runtime for sending/receiving GUI update events.
|
||||
* @param {string} extensionId - the id of the extension using this socket.
|
||||
* @param {object} peripheralOptions - the list of options for peripheral discovery.
|
||||
* @param {object} connectCallback - a callback for connection.
|
||||
*/
|
||||
constructor (runtime, peripheralOptions, connectCallback) {
|
||||
constructor (runtime, extensionId, peripheralOptions, connectCallback) {
|
||||
const ws = new WebSocket(ScratchLinkWebSocket);
|
||||
super(ws);
|
||||
|
||||
|
@ -24,6 +25,7 @@ class BLE extends JSONRPCWebSocket {
|
|||
this._connectCallback = connectCallback;
|
||||
this._connected = false;
|
||||
this._characteristicDidChangeCallback = null;
|
||||
this._extensionId = extensionId;
|
||||
this._peripheralOptions = peripheralOptions;
|
||||
this._discoverTimeoutID = null;
|
||||
this._runtime = runtime;
|
||||
|
@ -172,7 +174,10 @@ class BLE extends JSONRPCWebSocket {
|
|||
_sendError (/* e */) {
|
||||
this.disconnect();
|
||||
// log.error(`BLE error: ${JSON.stringify(e)}`);
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR);
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, {
|
||||
message: `Scratch lost connection to`,
|
||||
extensionId: this._extensionId
|
||||
});
|
||||
}
|
||||
|
||||
_sendDiscoverTimeout () {
|
||||
|
|
|
@ -8,11 +8,12 @@ class BT extends JSONRPCWebSocket {
|
|||
* A BT peripheral socket object. It handles connecting, over web sockets, to
|
||||
* BT peripherals, and reading and writing data to them.
|
||||
* @param {Runtime} runtime - the Runtime for sending/receiving GUI update events.
|
||||
* @param {string} extensionId - the id of the extension using this socket.
|
||||
* @param {object} peripheralOptions - the list of options for peripheral discovery.
|
||||
* @param {object} connectCallback - a callback for connection.
|
||||
* @param {object} messageCallback - a callback for message sending.
|
||||
*/
|
||||
constructor (runtime, peripheralOptions, connectCallback, messageCallback) {
|
||||
constructor (runtime, extensionId, peripheralOptions, connectCallback, messageCallback) {
|
||||
const ws = new WebSocket(ScratchLinkWebSocket);
|
||||
super(ws);
|
||||
|
||||
|
@ -25,6 +26,7 @@ class BT extends JSONRPCWebSocket {
|
|||
this._connectCallback = connectCallback;
|
||||
this._connected = false;
|
||||
this._characteristicDidChangeCallback = null;
|
||||
this._extensionId = extensionId;
|
||||
this._peripheralOptions = peripheralOptions;
|
||||
this._discoverTimeoutID = null;
|
||||
this._messageCallback = messageCallback;
|
||||
|
@ -115,7 +117,10 @@ class BT extends JSONRPCWebSocket {
|
|||
_sendError (/* e */) {
|
||||
this.disconnect();
|
||||
// log.error(`BT error: ${JSON.stringify(e)}`);
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR);
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, {
|
||||
message: `Scratch lost connection to`,
|
||||
extensionId: this._extensionId
|
||||
});
|
||||
}
|
||||
|
||||
_sendDiscoverTimeout () {
|
||||
|
|
|
@ -111,8 +111,8 @@ class VirtualMachine extends EventEmitter {
|
|||
this.runtime.on(Runtime.PERIPHERAL_CONNECTED, () =>
|
||||
this.emit(Runtime.PERIPHERAL_CONNECTED)
|
||||
);
|
||||
this.runtime.on(Runtime.PERIPHERAL_ERROR, () =>
|
||||
this.emit(Runtime.PERIPHERAL_ERROR)
|
||||
this.runtime.on(Runtime.PERIPHERAL_ERROR, data =>
|
||||
this.emit(Runtime.PERIPHERAL_ERROR, data)
|
||||
);
|
||||
this.runtime.on(Runtime.PERIPHERAL_SCAN_TIMEOUT, () =>
|
||||
this.emit(Runtime.PERIPHERAL_SCAN_TIMEOUT)
|
||||
|
|
Loading…
Reference in a new issue