mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Revert "Attempting to fix #1492: WeDo2 use of should be backwards compatible."
This reverts commit ae28a0c1b86209c66dcdbe9b10e0df8c39be7e10.
This commit is contained in:
parent
bfa4dfaac2
commit
1f7d9d3b67
2 changed files with 20 additions and 18 deletions
|
@ -460,9 +460,8 @@ class WeDo2 {
|
|||
// TODO: rename scan?
|
||||
startDeviceScan () {
|
||||
this._ble = new BLESession(this._runtime, {
|
||||
filters: [
|
||||
{services: [UUID.DEVICE_SERVICE, UUID.IO_SERVICE]}
|
||||
]
|
||||
filters: [{services: [UUID.DEVICE_SERVICE]}],
|
||||
optionalServices: [UUID.IO_SERVICE]
|
||||
}, this._onConnect);
|
||||
}
|
||||
|
||||
|
@ -517,6 +516,10 @@ class WeDo2 {
|
|||
})
|
||||
.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);
|
||||
});
|
||||
}
|
||||
|
@ -626,6 +629,10 @@ class WeDo2 {
|
|||
|
||||
this._send(UUID.INPUT_COMMAND, Base64Util.uint8ArrayToBase64(cmd))
|
||||
.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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const JSONRPCWebSocket = require('../util/jsonrpc-web-socket');
|
||||
const log = require('../util/log');
|
||||
// const log = require('../util/log');
|
||||
const ScratchLinkWebSocket = 'wss://device-manager.scratch.mit.edu:20110/scratch/ble';
|
||||
|
||||
class BLESession extends JSONRPCWebSocket {
|
||||
|
@ -115,17 +115,7 @@ class BLESession extends JSONRPCWebSocket {
|
|||
characteristicId
|
||||
};
|
||||
this._characteristicDidChangeCallback = onCharacteristicChanged;
|
||||
return this.sendRemoteRequest('startNotifications', params)
|
||||
.catch(() => {
|
||||
// backwards compatibility: try read
|
||||
this.read(serviceId, characteristicId, true, onCharacteristicChanged)
|
||||
.catch(e => {
|
||||
// if read not allowed, send error
|
||||
if (e.data !== 'Reading is not permitted.') { // OSX error TODO: Windows error?
|
||||
this._sendError(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
return this.sendRemoteRequest('startNotifications', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,7 +135,12 @@ class BLESession extends JSONRPCWebSocket {
|
|||
params.startNotifications = true;
|
||||
}
|
||||
this._characteristicDidChangeCallback = onCharacteristicChanged;
|
||||
return this.sendRemoteRequest('read', params);
|
||||
return this.sendRemoteRequest('read', params)
|
||||
.catch(e => {
|
||||
if (e.data !== 'Reading is not permitted.') { // TODO: move this error check to extension
|
||||
this._sendError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,9 +166,9 @@ class BLESession extends JSONRPCWebSocket {
|
|||
});
|
||||
}
|
||||
|
||||
_sendError (e) {
|
||||
_sendError (/* e */) {
|
||||
this._connected = false;
|
||||
log.error(`BLESession error: ${JSON.stringify(e)}`);
|
||||
// log.error(`BLESession error: ${JSON.stringify(e)}`);
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue