mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Adding disconnect/state resetting behavior to rest of hardware extensions.
This commit is contained in:
parent
f8a0ea281f
commit
37fe83c057
6 changed files with 59 additions and 19 deletions
|
@ -827,6 +827,7 @@ class Boost {
|
|||
*/
|
||||
disconnect () {
|
||||
console.log('BOOST DISCONNECT CALLED');
|
||||
|
||||
if (this._ble) {
|
||||
this._ble.disconnect();
|
||||
}
|
||||
|
@ -839,6 +840,7 @@ class Boost {
|
|||
*/
|
||||
reset () {
|
||||
console.log('BOOST RESET CALLED');
|
||||
|
||||
this._ports = [];
|
||||
this._motors = [];
|
||||
this._sensors = {
|
||||
|
|
|
@ -601,6 +601,7 @@ class EV3 {
|
|||
*/
|
||||
disconnect() {
|
||||
console.log('EV3 DISCONNECT CALLED');
|
||||
|
||||
if (this._bt) {
|
||||
this._bt.disconnect();
|
||||
}
|
||||
|
@ -613,6 +614,7 @@ class EV3 {
|
|||
*/
|
||||
reset() {
|
||||
console.log('EV3 RESET CALLED');
|
||||
|
||||
this._sensorPorts = [];
|
||||
this._motorPorts = [];
|
||||
this._sensors = {
|
||||
|
|
|
@ -172,7 +172,7 @@ class GdxFor {
|
|||
*/
|
||||
this._timeoutID = null;
|
||||
|
||||
this.disconnect = this.disconnect.bind(this);
|
||||
this.reset = this.reset.bind(this);
|
||||
this._onConnect = this._onConnect.bind(this);
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ class GdxFor {
|
|||
optionalServices: [
|
||||
BLEUUID.service
|
||||
]
|
||||
}, this._onConnect, this.disconnect);
|
||||
}, this._onConnect, this.reset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,8 +209,22 @@ class GdxFor {
|
|||
* Called by the runtime when a user exits the connection popup.
|
||||
* Disconnect from the GDX FOR.
|
||||
*/
|
||||
disconnect () {
|
||||
window.clearInterval(this._timeoutID);
|
||||
disconnect() {
|
||||
console.log('GDXFOR DISCONNECT CALLED');
|
||||
|
||||
if (this._scratchLinkSocket) {
|
||||
this._scratchLinkSocket.disconnect();
|
||||
}
|
||||
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all the state and timeout/interval ids.
|
||||
*/
|
||||
reset () {
|
||||
console.log('GDXFOR RESET CALLED');
|
||||
|
||||
this._sensors = {
|
||||
force: 0,
|
||||
accelerationX: 0,
|
||||
|
@ -220,9 +234,8 @@ class GdxFor {
|
|||
spinSpeedY: 0,
|
||||
spinSpeedZ: 0
|
||||
};
|
||||
if (this._scratchLinkSocket) {
|
||||
this._scratchLinkSocket.disconnect();
|
||||
}
|
||||
|
||||
window.clearInterval(this._timeoutID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -144,7 +144,7 @@ class MicroBit {
|
|||
*/
|
||||
this._busyTimeoutID = null;
|
||||
|
||||
this.disconnect = this.disconnect.bind(this);
|
||||
this.reset = this.reset.bind(this);
|
||||
this._onConnect = this._onConnect.bind(this);
|
||||
this._onMessage = this._onMessage.bind(this);
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ class MicroBit {
|
|||
filters: [
|
||||
{services: [BLEUUID.service]}
|
||||
]
|
||||
}, this._onConnect, this.disconnect);
|
||||
}, this._onConnect, this.reset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,11 +238,23 @@ class MicroBit {
|
|||
/**
|
||||
* Disconnect from the micro:bit.
|
||||
*/
|
||||
disconnect () {
|
||||
window.clearTimeout(this._timeoutID);
|
||||
disconnect() {
|
||||
console.log('MICROBIT DISCONNECT CALLED');
|
||||
|
||||
if (this._ble) {
|
||||
this._ble.disconnect();
|
||||
}
|
||||
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all the state and timeout/interval ids.
|
||||
*/
|
||||
reset() {
|
||||
console.log('MICROBIT RESET CALLED');
|
||||
|
||||
window.clearTimeout(this._timeoutID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -435,7 +435,7 @@ class WeDo2 {
|
|||
*/
|
||||
this._batteryLevelIntervalId = null;
|
||||
|
||||
this.disconnect = this.disconnect.bind(this);
|
||||
this.reset = this.reset.bind(this);
|
||||
this._onConnect = this._onConnect.bind(this);
|
||||
this._onMessage = this._onMessage.bind(this);
|
||||
this._checkBatteryLevel = this._checkBatteryLevel.bind(this);
|
||||
|
@ -594,7 +594,7 @@ class WeDo2 {
|
|||
services: [BLEService.DEVICE_SERVICE]
|
||||
}],
|
||||
optionalServices: [BLEService.IO_SERVICE]
|
||||
}, this._onConnect, this.disconnect);
|
||||
}, this._onConnect, this.reset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -610,7 +610,22 @@ class WeDo2 {
|
|||
/**
|
||||
* Disconnects from the current BLE socket.
|
||||
*/
|
||||
disconnect () {
|
||||
disconnect() {
|
||||
console.log('WEDO2 DISCONNECT CALLED');
|
||||
|
||||
if (this._ble) {
|
||||
this._ble.disconnect();
|
||||
}
|
||||
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all the state and timeout/interval ids.
|
||||
*/
|
||||
reset() {
|
||||
console.log('WEDO2 RESET CALLED');
|
||||
|
||||
this._ports = ['none', 'none'];
|
||||
this._motors = [null, null];
|
||||
this._sensors = {
|
||||
|
@ -619,10 +634,6 @@ class WeDo2 {
|
|||
distance: 0
|
||||
};
|
||||
|
||||
if (this._ble) {
|
||||
this._ble.disconnect();
|
||||
}
|
||||
|
||||
if (this._batteryLevelIntervalId) {
|
||||
window.clearInterval(this._batteryLevelIntervalId);
|
||||
this._batteryLevelIntervalId = null;
|
||||
|
|
|
@ -205,9 +205,9 @@ class BLE extends JSONRPC {
|
|||
*/
|
||||
handleDisconnectError (/* e */) {
|
||||
// log.error(`BLE error: ${JSON.stringify(e)}`);
|
||||
console.log('BLE HANDLEDISCONNECTERROR CALLED');
|
||||
|
||||
if (!this._connected) return;
|
||||
console.log('BLE HANDLEDISCONNECTERROR CALLED');
|
||||
|
||||
this.disconnect();
|
||||
|
||||
|
|
Loading…
Reference in a new issue