Merge pull request #2194 from evhan55/ergonomics/1974

GDXFOR: Rename scratchLinkSocket variables to 'socket' and 'ble'
This commit is contained in:
Evelyn Eastmond 2019-06-17 11:59:25 -04:00 committed by GitHub
commit e732d9f3b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 17 deletions

View file

@ -134,7 +134,7 @@ class GdxFor {
* @type {BLE} * @type {BLE}
* @private * @private
*/ */
this._scratchLinkSocket = null; this._ble = null;
/** /**
* An @vernier/godirect Device * An @vernier/godirect Device
@ -181,11 +181,11 @@ class GdxFor {
* Called by the runtime when user wants to scan for a peripheral. * Called by the runtime when user wants to scan for a peripheral.
*/ */
scan () { scan () {
if (this._scratchLinkSocket) { if (this._ble) {
this._scratchLinkSocket.disconnect(); this._ble.disconnect();
} }
this._scratchLinkSocket = new BLE(this._runtime, this._extensionId, { this._ble = new BLE(this._runtime, this._extensionId, {
filters: [ filters: [
{namePrefix: 'GDX-FOR'} {namePrefix: 'GDX-FOR'}
], ],
@ -200,8 +200,8 @@ class GdxFor {
* @param {number} id - the id of the peripheral to connect to. * @param {number} id - the id of the peripheral to connect to.
*/ */
connect (id) { connect (id) {
if (this._scratchLinkSocket) { if (this._ble) {
this._scratchLinkSocket.connectPeripheral(id); this._ble.connectPeripheral(id);
} }
} }
@ -220,8 +220,8 @@ class GdxFor {
spinSpeedY: 0, spinSpeedY: 0,
spinSpeedZ: 0 spinSpeedZ: 0
}; };
if (this._scratchLinkSocket) { if (this._ble) {
this._scratchLinkSocket.disconnect(); this._ble.disconnect();
} }
} }
@ -231,8 +231,8 @@ class GdxFor {
*/ */
isConnected () { isConnected () {
let connected = false; let connected = false;
if (this._scratchLinkSocket) { if (this._ble) {
connected = this._scratchLinkSocket.isConnected(); connected = this._ble.isConnected();
} }
return connected; return connected;
} }
@ -242,7 +242,7 @@ class GdxFor {
* @private * @private
*/ */
_onConnect () { _onConnect () {
const adapter = new ScratchLinkDeviceAdapter(this._scratchLinkSocket, BLEUUID); const adapter = new ScratchLinkDeviceAdapter(this._ble, BLEUUID);
godirect.createDevice(adapter, {open: true, startMeasurements: false}).then(device => { godirect.createDevice(adapter, {open: true, startMeasurements: false}).then(device => {
// Setup device // Setup device
this._device = device; this._device = device;
@ -262,7 +262,7 @@ class GdxFor {
}); });
}); });
this._timeoutID = window.setInterval( this._timeoutID = window.setInterval(
() => this._scratchLinkSocket.handleDisconnectError(BLEDataStoppedError), () => this._ble.handleDisconnectError(BLEDataStoppedError),
BLETimeout BLETimeout
); );
}); });
@ -306,7 +306,7 @@ class GdxFor {
// cancel disconnect timeout and start a new one // cancel disconnect timeout and start a new one
window.clearInterval(this._timeoutID); window.clearInterval(this._timeoutID);
this._timeoutID = window.setInterval( this._timeoutID = window.setInterval(
() => this._scratchLinkSocket.handleDisconnectError(BLEDataStoppedError), () => this._ble.handleDisconnectError(BLEDataStoppedError),
BLETimeout BLETimeout
); );
} }

View file

@ -4,8 +4,8 @@ const Base64Util = require('../../util/base64-util');
* Adapter class * Adapter class
*/ */
class ScratchLinkDeviceAdapter { class ScratchLinkDeviceAdapter {
constructor (scratchLinkSocket, {service, commandChar, responseChar}) { constructor (socket, {service, commandChar, responseChar}) {
this.scratchLinkSocket = scratchLinkSocket; this.socket = socket;
this._service = service; this._service = service;
this._commandChar = commandChar; this._commandChar = commandChar;
@ -21,13 +21,13 @@ class ScratchLinkDeviceAdapter {
writeCommand (commandBuffer) { writeCommand (commandBuffer) {
const data = Base64Util.uint8ArrayToBase64(commandBuffer); const data = Base64Util.uint8ArrayToBase64(commandBuffer);
return this.scratchLinkSocket return this.socket
.write(this._service, this._commandChar, data, 'base64'); .write(this._service, this._commandChar, data, 'base64');
} }
setup ({onResponse}) { setup ({onResponse}) {
this._deviceOnResponse = onResponse; this._deviceOnResponse = onResponse;
return this.scratchLinkSocket return this.socket
.startNotifications(this._service, this._responseChar, this._onResponse); .startNotifications(this._service, this._responseChar, this._onResponse);
// TODO: // TODO: