Change microbit extension to send BLE socket error on data lost, instead of calling disconnect directly.
This commit is contained in:
1 parent
fab292889f
commit
fdda1e53e3
5 files changed
+21
-6
No files matched your search
@@ -579,6 +579,7 @@ class EV3 {
|
||||
* Called by the runtime when user wants to disconnect from the EV3 peripheral.
|
||||
*/
|
||||
disconnect () {
|
||||
console.log('EV3 DISCONNECT');
|
||||
this._clearSensorsAndMotors();
|
||||
window.clearInterval(this._pollingIntervalID);
|
||||
this._pollingIntervalID = null;
|
||||
|
||||
@@ -212,7 +212,7 @@ class MicroBit {
|
||||
filters: [
|
||||
{services: [BLEUUID.service]}
|
||||
]
|
||||
}, this._onConnect, null);
|
||||
}, this._onConnect, this.disconnect);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,6 +229,7 @@ class MicroBit {
|
||||
* Disconnect from the micro:bit.
|
||||
*/
|
||||
disconnect () {
|
||||
console.log('MICROBIT DISCONNECT');
|
||||
window.clearInterval(this._timeoutID);
|
||||
if (this._ble) {
|
||||
this._ble.disconnect();
|
||||
@@ -317,7 +318,11 @@ class MicroBit {
|
||||
|
||||
// cancel disconnect timeout and start a new one
|
||||
window.clearInterval(this._timeoutID);
|
||||
this._timeoutID = window.setInterval(this.disconnect, BLETimeout);
|
||||
this._timeoutID = window.setInterval(
|
||||
// send an error to the BLE socket
|
||||
this._ble._sendDisconnectError.bind(this._ble, 'micro:bit stopped receiving data'),
|
||||
BLETimeout
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -611,6 +611,7 @@ class WeDo2 {
|
||||
* Disconnects from the current BLE socket.
|
||||
*/
|
||||
disconnect () {
|
||||
console.log('WEDO2 DISCONNECT');
|
||||
this._ports = ['none', 'none'];
|
||||
this._motors = [null, null];
|
||||
this._sensors = {
|
||||
|
||||
+6
-2
@@ -73,7 +73,10 @@ class BLE extends JSONRPCWebSocket {
|
||||
* Close the websocket.
|
||||
*/
|
||||
disconnect () {
|
||||
if (!this._connected) return;
|
||||
|
||||
this._ws.close();
|
||||
this._connected = false;
|
||||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
@@ -191,9 +194,10 @@ class BLE extends JSONRPCWebSocket {
|
||||
|
||||
if (!this._connected) return;
|
||||
|
||||
this._connected = false;
|
||||
if (this._disconnectCallback) {
|
||||
this._disconnectCallback();
|
||||
this._disconnectCallback(); // will trigger a disconnect()
|
||||
} else {
|
||||
this.disconnect();
|
||||
}
|
||||
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECT_ERROR, {
|
||||
|
||||
+6
-2
@@ -75,7 +75,10 @@ class BT extends JSONRPCWebSocket {
|
||||
* Close the websocket.
|
||||
*/
|
||||
disconnect () {
|
||||
if (!this._connected) return;
|
||||
|
||||
this._ws.close();
|
||||
this._connected = false;
|
||||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
@@ -136,9 +139,10 @@ class BT extends JSONRPCWebSocket {
|
||||
|
||||
if (!this._connected) return;
|
||||
|
||||
this._connected = false;
|
||||
if (this._disconnectCallback) {
|
||||
this._disconnectCallback();
|
||||
this._disconnectCallback(); // will trigger a disconnect()
|
||||
} else {
|
||||
this.disconnect();
|
||||
}
|
||||
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECT_ERROR, {
|
||||
|
||||
Reference in new issue
Block a user