From 477c307304e0e6438d4e5624179740a9d0bfec1d Mon Sep 17 00:00:00 2001 From: Valerie Young Date: Thu, 10 Jan 2019 10:11:46 -0500 Subject: [PATCH] Remove one copy of constants --- src/extensions/scratch3_gdx_for/index.js | 2 +- .../scratch-link-device-adapter.js | 20 ++++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/extensions/scratch3_gdx_for/index.js b/src/extensions/scratch3_gdx_for/index.js index e0cc5b76e..be6b2812c 100644 --- a/src/extensions/scratch3_gdx_for/index.js +++ b/src/extensions/scratch3_gdx_for/index.js @@ -140,7 +140,7 @@ class GdxFor { * @private */ _onConnect () { - const adapter = new ScratchLinkDeviceAdapter(this._scratchLinkSocket); + const adapter = new ScratchLinkDeviceAdapter(this._scratchLinkSocket, BLEUUID); godirect.createDevice(adapter, {open: true, startMeasurements: false}).then(device => { this._device = device; this._startMeasurements(); diff --git a/src/extensions/scratch3_gdx_for/scratch-link-device-adapter.js b/src/extensions/scratch3_gdx_for/scratch-link-device-adapter.js index f9cb69495..33b5f2a02 100644 --- a/src/extensions/scratch3_gdx_for/scratch-link-device-adapter.js +++ b/src/extensions/scratch3_gdx_for/scratch-link-device-adapter.js @@ -1,23 +1,15 @@ 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 */ class ScratchLinkDeviceAdapter { - constructor (scratchLinkSocket) { + constructor (scratchLinkSocket, { service, commandChar, responseChar }) { this.scratchLinkSocket = scratchLinkSocket; + this._service = service; + this._commandChar = commandChar; + this._responseChar = responseChar; this._onResponse = this._onResponse.bind(this); this._deviceOnResponse = null; } @@ -30,13 +22,13 @@ class ScratchLinkDeviceAdapter { const data = Base64Util.uint8ArrayToBase64(commandBuffer); return this.scratchLinkSocket - .write(BLEUUID.service, BLEUUID.commandChar, data, 'base64', true); + .write(this._service, this._commandChar, data, 'base64', true); } setup ({onResponse}) { this._deviceOnResponse = onResponse; return this.scratchLinkSocket - .startNotifications(BLEUUID.service, BLEUUID.responseChar, this._onResponse); + .startNotifications(this._service, this._responseChar, this._onResponse); // TODO: // How do we find out from scratch link if communication closes?