mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
WeDo2 backwards compatibility update (#1518)
* Resolving #1492: No longer trying to make WeDo2 backwards compatible with Scratch Link API v1.0. * Closing the socket on all BLE/BT errors. * Adding BT disconnection.
This commit is contained in:
parent
f567e34c3a
commit
5320dfb676
3 changed files with 7 additions and 15 deletions
|
@ -537,11 +537,6 @@ class WeDo2 {
|
||||||
this.setLED(0x0000FF);
|
this.setLED(0x0000FF);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// register for attached io notifications
|
|
||||||
// TODO: make backwards compatible with 'read':
|
|
||||||
// - try 'startNotifications'
|
|
||||||
// - then try 'read' with 'startNotifications' flag
|
|
||||||
// - then catch OSX and Windows errors
|
|
||||||
this._ble.startNotifications(UUID.DEVICE_SERVICE, UUID.ATTACHED_IO, this._onMessage);
|
this._ble.startNotifications(UUID.DEVICE_SERVICE, UUID.ATTACHED_IO, this._onMessage);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -663,10 +658,6 @@ class WeDo2 {
|
||||||
|
|
||||||
this._send(UUID.INPUT_COMMAND, Base64Util.uint8ArrayToBase64(cmd))
|
this._send(UUID.INPUT_COMMAND, Base64Util.uint8ArrayToBase64(cmd))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// TODO: make backwards compatible with 'read':
|
|
||||||
// - try 'startNotifications'
|
|
||||||
// - then try 'read' with 'startNotifications' flag
|
|
||||||
// - then catch OSX and Windows errors
|
|
||||||
this._ble.startNotifications(UUID.IO_SERVICE, UUID.INPUT_VALUES, this._onMessage);
|
this._ble.startNotifications(UUID.IO_SERVICE, UUID.INPUT_VALUES, this._onMessage);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,10 @@ class BLESession extends JSONRPCWebSocket {
|
||||||
characteristicId
|
characteristicId
|
||||||
};
|
};
|
||||||
this._characteristicDidChangeCallback = onCharacteristicChanged;
|
this._characteristicDidChangeCallback = onCharacteristicChanged;
|
||||||
return this.sendRemoteRequest('startNotifications', params);
|
return this.sendRemoteRequest('startNotifications', params)
|
||||||
|
.catch(e => {
|
||||||
|
this._sendError(e);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,9 +140,7 @@ class BLESession extends JSONRPCWebSocket {
|
||||||
this._characteristicDidChangeCallback = onCharacteristicChanged;
|
this._characteristicDidChangeCallback = onCharacteristicChanged;
|
||||||
return this.sendRemoteRequest('read', params)
|
return this.sendRemoteRequest('read', params)
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
if (e.data !== 'Reading is not permitted.') { // TODO: move this error check to extension
|
|
||||||
this._sendError(e);
|
this._sendError(e);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +168,7 @@ class BLESession extends JSONRPCWebSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendError (/* e */) {
|
_sendError (/* e */) {
|
||||||
this._connected = false;
|
this.disconnectSession();
|
||||||
// log.error(`BLESession error: ${JSON.stringify(e)}`);
|
// log.error(`BLESession error: ${JSON.stringify(e)}`);
|
||||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR);
|
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ class BTSession extends JSONRPCWebSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendError (/* e */) {
|
_sendError (/* e */) {
|
||||||
this._connected = false;
|
this.disconnectSession();
|
||||||
// log.error(`BTSession error: ${JSON.stringify(e)}`);
|
// log.error(`BTSession error: ${JSON.stringify(e)}`);
|
||||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR);
|
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue