WeDo2 Extension: First Pass (#1441)

* Adding WeDo2 connection/disconnection over Scratch Link BLE.

* Testing motor and LED output.

* Reading sensor attachment and registering for sensor notifications.

* Motor indexing.

* Some refactoring notes.  Moving some functions around.

* Refactoring and enums.

* Removing some comments

* Fixing linting error.

* Fixing tilt reporter values and added stopAll bound to stop button to stop piezo, LED and motors.
This commit is contained in:
Evelyn Eastmond 2018-08-13 17:10:55 -04:00 committed by Eric Rosenbaum
parent 30892dfd43
commit f01733f019
2 changed files with 378 additions and 117 deletions

View file

@ -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 {
@ -121,7 +121,9 @@ class BLESession extends JSONRPCWebSocket {
this._characteristicDidChangeCallback = onCharacteristicChanged;
return this.sendRemoteRequest('read', params)
.catch(e => {
this._sendError(e);
if (e.data !== 'Reading is not permitted.') { // TODO: workaround til notify-only supported
this._sendError(e);
}
});
}
@ -144,9 +146,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);
}