Remove one copy of constants

This commit is contained in:
Valerie Young 2019-01-10 10:11:46 -05:00
parent 5d4aebf301
commit 477c307304
2 changed files with 7 additions and 15 deletions

View file

@ -140,7 +140,7 @@ class GdxFor {
* @private * @private
*/ */
_onConnect () { _onConnect () {
const adapter = new ScratchLinkDeviceAdapter(this._scratchLinkSocket); const adapter = new ScratchLinkDeviceAdapter(this._scratchLinkSocket, BLEUUID);
godirect.createDevice(adapter, {open: true, startMeasurements: false}).then(device => { godirect.createDevice(adapter, {open: true, startMeasurements: false}).then(device => {
this._device = device; this._device = device;
this._startMeasurements(); this._startMeasurements();

View file

@ -1,23 +1,15 @@
const Base64Util = require('../../util/base64-util'); const Base64Util = require('../../util/base64-util');
/**
* Enum for Vernier godirect protocol.
* @readonly
* @enum {string}
*/
const BLEUUID = {
service: 'd91714ef-28b9-4f91-ba16-f0d9a604f112',
commandChar: 'f4bf14a6-c7d5-4b6d-8aa8-df1a7c83adcb',
responseChar: 'b41e6675-a329-40e0-aa01-44d2f444babe'
};
/** /**
* Adapter class * Adapter class
*/ */
class ScratchLinkDeviceAdapter { class ScratchLinkDeviceAdapter {
constructor (scratchLinkSocket) { constructor (scratchLinkSocket, { service, commandChar, responseChar }) {
this.scratchLinkSocket = scratchLinkSocket; this.scratchLinkSocket = scratchLinkSocket;
this._service = service;
this._commandChar = commandChar;
this._responseChar = responseChar;
this._onResponse = this._onResponse.bind(this); this._onResponse = this._onResponse.bind(this);
this._deviceOnResponse = null; this._deviceOnResponse = null;
} }
@ -30,13 +22,13 @@ class ScratchLinkDeviceAdapter {
const data = Base64Util.uint8ArrayToBase64(commandBuffer); const data = Base64Util.uint8ArrayToBase64(commandBuffer);
return this.scratchLinkSocket return this.scratchLinkSocket
.write(BLEUUID.service, BLEUUID.commandChar, data, 'base64', true); .write(this._service, this._commandChar, data, 'base64', true);
} }
setup ({onResponse}) { setup ({onResponse}) {
this._deviceOnResponse = onResponse; this._deviceOnResponse = onResponse;
return this.scratchLinkSocket return this.scratchLinkSocket
.startNotifications(BLEUUID.service, BLEUUID.responseChar, this._onResponse); .startNotifications(this._service, this._responseChar, this._onResponse);
// TODO: // TODO:
// How do we find out from scratch link if communication closes? // How do we find out from scratch link if communication closes?