diff --git a/docs/BoostMoveHub.html b/docs/BoostMoveHub.html index f10abce..af5a482 100644 --- a/docs/BoostMoveHub.html +++ b/docs/BoostMoveHub.html @@ -327,7 +327,7 @@ @@ -460,7 +460,7 @@ @@ -593,7 +593,7 @@ @@ -726,7 +726,7 @@ @@ -859,7 +859,7 @@ @@ -992,7 +992,7 @@ @@ -1124,7 +1124,7 @@ @@ -1250,7 +1250,7 @@ @@ -1376,7 +1376,7 @@ @@ -1502,7 +1502,7 @@ @@ -1674,7 +1674,7 @@ @@ -1904,7 +1904,7 @@ @@ -2075,7 +2075,7 @@ @@ -2294,7 +2294,7 @@ @@ -2532,7 +2532,7 @@ @@ -2789,7 +2789,7 @@ @@ -3030,7 +3030,7 @@ @@ -3201,7 +3201,7 @@ @@ -3322,7 +3322,7 @@ @@ -3499,7 +3499,7 @@ @@ -3719,7 +3719,7 @@ @@ -3895,7 +3895,7 @@ @@ -4072,7 +4072,7 @@ @@ -4280,7 +4280,7 @@ @@ -4451,7 +4451,7 @@ @@ -4622,7 +4622,7 @@ @@ -4817,7 +4817,7 @@ @@ -4969,7 +4969,7 @@ @@ -5140,7 +5140,7 @@ @@ -5311,7 +5311,7 @@ @@ -5506,7 +5506,7 @@ @@ -5585,7 +5585,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/DuploTrainBase.html b/docs/DuploTrainBase.html index 6027706..78bb13f 100644 --- a/docs/DuploTrainBase.html +++ b/docs/DuploTrainBase.html @@ -327,7 +327,7 @@ @@ -460,7 +460,7 @@ @@ -593,7 +593,7 @@ @@ -726,7 +726,7 @@ @@ -859,7 +859,7 @@ @@ -992,7 +992,7 @@ @@ -1124,7 +1124,7 @@ @@ -1250,7 +1250,7 @@ @@ -1376,7 +1376,7 @@ @@ -1502,7 +1502,7 @@ @@ -1674,7 +1674,7 @@ @@ -1832,7 +1832,7 @@ @@ -2066,7 +2066,7 @@ @@ -2233,7 +2233,7 @@ @@ -2452,7 +2452,7 @@ @@ -2693,7 +2693,7 @@ @@ -2864,7 +2864,7 @@ @@ -2985,7 +2985,7 @@ @@ -3162,7 +3162,7 @@ @@ -3382,7 +3382,7 @@ @@ -3558,7 +3558,7 @@ @@ -3735,7 +3735,7 @@ @@ -3938,7 +3938,7 @@ @@ -4109,7 +4109,7 @@ @@ -4188,7 +4188,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/Hub.html b/docs/Hub.html index b905d28..82ee874 100644 --- a/docs/Hub.html +++ b/docs/Hub.html @@ -307,7 +307,7 @@ @@ -426,7 +426,7 @@ @@ -545,7 +545,7 @@ @@ -664,7 +664,7 @@ @@ -783,7 +783,7 @@ @@ -902,7 +902,7 @@ @@ -984,7 +984,7 @@ @@ -1096,7 +1096,7 @@ @@ -1208,7 +1208,7 @@ @@ -1366,7 +1366,7 @@ @@ -1525,7 +1525,7 @@ @@ -1731,7 +1731,7 @@ @@ -1893,7 +1893,7 @@ @@ -2056,7 +2056,7 @@ @@ -2250,7 +2250,7 @@ @@ -2388,7 +2388,7 @@ @@ -2467,7 +2467,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/LPF2Hub.html b/docs/LPF2Hub.html index 1b7bb69..2c2695d 100644 --- a/docs/LPF2Hub.html +++ b/docs/LPF2Hub.html @@ -316,7 +316,7 @@ @@ -444,7 +444,7 @@ @@ -572,7 +572,7 @@ @@ -700,7 +700,7 @@ @@ -828,7 +828,7 @@ @@ -956,7 +956,7 @@ @@ -1052,7 +1052,7 @@ @@ -1173,7 +1173,7 @@ @@ -1294,7 +1294,7 @@ @@ -1461,7 +1461,7 @@ @@ -1619,7 +1619,7 @@ @@ -1829,7 +1829,7 @@ @@ -1991,7 +1991,7 @@ @@ -2103,7 +2103,7 @@ @@ -2275,7 +2275,7 @@ @@ -2490,7 +2490,7 @@ @@ -2661,7 +2661,7 @@ @@ -2833,7 +2833,7 @@ @@ -3036,7 +3036,7 @@ @@ -3198,7 +3198,7 @@ @@ -3360,7 +3360,7 @@ @@ -3546,7 +3546,7 @@ @@ -3693,7 +3693,7 @@ @@ -3855,7 +3855,7 @@ @@ -4017,7 +4017,7 @@ @@ -4179,7 +4179,7 @@ @@ -4365,7 +4365,7 @@ @@ -4444,7 +4444,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/PUPHub.html b/docs/PUPHub.html index adfe834..b57a335 100644 --- a/docs/PUPHub.html +++ b/docs/PUPHub.html @@ -327,7 +327,7 @@ @@ -460,7 +460,7 @@ @@ -593,7 +593,7 @@ @@ -726,7 +726,7 @@ @@ -859,7 +859,7 @@ @@ -992,7 +992,7 @@ @@ -1124,7 +1124,7 @@ @@ -1250,7 +1250,7 @@ @@ -1376,7 +1376,7 @@ @@ -1502,7 +1502,7 @@ @@ -1674,7 +1674,7 @@ @@ -1904,7 +1904,7 @@ @@ -2075,7 +2075,7 @@ @@ -2294,7 +2294,7 @@ @@ -2532,7 +2532,7 @@ @@ -2773,7 +2773,7 @@ @@ -2944,7 +2944,7 @@ @@ -3065,7 +3065,7 @@ @@ -3242,7 +3242,7 @@ @@ -3462,7 +3462,7 @@ @@ -3638,7 +3638,7 @@ @@ -3815,7 +3815,7 @@ @@ -4023,7 +4023,7 @@ @@ -4194,7 +4194,7 @@ @@ -4365,7 +4365,7 @@ @@ -4560,7 +4560,7 @@ @@ -4712,7 +4712,7 @@ @@ -4883,7 +4883,7 @@ @@ -5078,7 +5078,7 @@ @@ -5157,7 +5157,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/PUPRemote.html b/docs/PUPRemote.html index 00230ea..e1da312 100644 --- a/docs/PUPRemote.html +++ b/docs/PUPRemote.html @@ -327,7 +327,7 @@ @@ -460,7 +460,7 @@ @@ -593,7 +593,7 @@ @@ -726,7 +726,7 @@ @@ -859,7 +859,7 @@ @@ -992,7 +992,7 @@ @@ -1088,7 +1088,7 @@ @@ -1214,7 +1214,7 @@ @@ -1340,7 +1340,7 @@ @@ -1512,7 +1512,7 @@ @@ -1675,7 +1675,7 @@ @@ -1890,7 +1890,7 @@ @@ -2061,7 +2061,7 @@ @@ -2182,7 +2182,7 @@ @@ -2359,7 +2359,7 @@ @@ -2579,7 +2579,7 @@ @@ -2755,7 +2755,7 @@ @@ -2932,7 +2932,7 @@ @@ -3135,7 +3135,7 @@ @@ -3330,7 +3330,7 @@ @@ -3409,7 +3409,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/PoweredUP.html b/docs/PoweredUP.html index 126961e..d24c06c 100644 --- a/docs/PoweredUP.html +++ b/docs/PoweredUP.html @@ -149,7 +149,7 @@ @@ -316,7 +316,7 @@ @@ -427,7 +427,7 @@ @@ -585,7 +585,7 @@ @@ -693,7 +693,7 @@ @@ -781,7 +781,7 @@ @@ -939,7 +939,7 @@ @@ -1018,7 +1018,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/WeDo2SmartHub.html b/docs/WeDo2SmartHub.html index a39c253..cd0ce42 100644 --- a/docs/WeDo2SmartHub.html +++ b/docs/WeDo2SmartHub.html @@ -320,7 +320,7 @@ @@ -448,7 +448,7 @@ @@ -576,7 +576,7 @@ @@ -704,7 +704,7 @@ @@ -832,7 +832,7 @@ @@ -960,7 +960,7 @@ @@ -1092,7 +1092,7 @@ @@ -1218,7 +1218,7 @@ @@ -1339,7 +1339,7 @@ @@ -1460,7 +1460,7 @@ @@ -1627,7 +1627,7 @@ @@ -1809,7 +1809,7 @@ @@ -2043,7 +2043,7 @@ @@ -2205,7 +2205,7 @@ @@ -2415,7 +2415,7 @@ @@ -2653,7 +2653,7 @@ @@ -2891,7 +2891,7 @@ @@ -3053,7 +3053,7 @@ @@ -3165,7 +3165,7 @@ @@ -3337,7 +3337,7 @@ @@ -3552,7 +3552,7 @@ @@ -3723,7 +3723,7 @@ @@ -3895,7 +3895,7 @@ @@ -4098,7 +4098,7 @@ @@ -4260,7 +4260,7 @@ @@ -4422,7 +4422,7 @@ @@ -4569,7 +4569,7 @@ @@ -4731,7 +4731,7 @@ @@ -4893,7 +4893,7 @@ @@ -5079,7 +5079,7 @@ @@ -5158,7 +5158,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/boostmovehub.js.html b/docs/boostmovehub.js.html index 1bde08a..78dee7c 100644 --- a/docs/boostmovehub.js.html +++ b/docs/boostmovehub.js.html @@ -111,7 +111,9 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub { * @ignore */ static IsBoostMoveHub(peripheral) { - return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.BOOST_MOVE_HUB_ID); + return (peripheral.advertisement && + peripheral.advertisement.serviceUuids && + peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.BOOST_MOVE_HUB_ID); } constructor(peripheral, autoSubscribe = true) { super(peripheral, autoSubscribe); @@ -349,7 +351,7 @@ exports.BoostMoveHub = BoostMoveHub; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/classes.list.html b/docs/classes.list.html index f4dd319..c104205 100644 --- a/docs/classes.list.html +++ b/docs/classes.list.html @@ -335,7 +335,7 @@ @@ -506,7 +506,7 @@ @@ -677,7 +677,7 @@ @@ -872,7 +872,7 @@ @@ -1024,7 +1024,7 @@ @@ -1195,7 +1195,7 @@ @@ -1366,7 +1366,7 @@ @@ -1561,7 +1561,7 @@ @@ -1732,7 +1732,7 @@ @@ -1903,7 +1903,7 @@ @@ -2065,7 +2065,7 @@ @@ -2203,7 +2203,7 @@ @@ -2374,7 +2374,7 @@ @@ -2536,7 +2536,7 @@ @@ -2698,7 +2698,7 @@ @@ -2884,7 +2884,7 @@ @@ -3031,7 +3031,7 @@ @@ -3193,7 +3193,7 @@ @@ -3355,7 +3355,7 @@ @@ -3517,7 +3517,7 @@ @@ -3703,7 +3703,7 @@ @@ -3853,7 +3853,7 @@ @@ -4029,7 +4029,7 @@ @@ -4200,7 +4200,7 @@ @@ -4371,7 +4371,7 @@ @@ -4566,7 +4566,7 @@ @@ -4718,7 +4718,7 @@ @@ -4889,7 +4889,7 @@ @@ -5084,7 +5084,7 @@ @@ -5255,7 +5255,7 @@ @@ -5450,7 +5450,7 @@ @@ -5621,7 +5621,7 @@ @@ -5783,7 +5783,7 @@ @@ -5945,7 +5945,7 @@ @@ -6092,7 +6092,7 @@ @@ -6254,7 +6254,7 @@ @@ -6416,7 +6416,7 @@ @@ -6602,7 +6602,7 @@ @@ -6681,7 +6681,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/consts.js.html b/docs/consts.js.html index 797c441..5a3b1da 100644 --- a/docs/consts.js.html +++ b/docs/consts.js.html @@ -214,6 +214,10 @@ var BLEManufacturerData; var BLEService; (function (BLEService) { BLEService["WEDO2_SMART_HUB"] = "00001523-1212-efde-1523-785feabcd123"; + BLEService["WEDO2_SMART_HUB_2"] = "00004f0e-1212-efde-1523-785feabcd123"; + BLEService["WEDO2_SMART_HUB_3"] = "2a19"; + BLEService["WEDO2_SMART_HUB_4"] = "180f"; + BLEService["WEDO2_SMART_HUB_5"] = "180a"; BLEService["LPF2_HUB"] = "00001623-1212-efde-1623-785feabcd123"; })(BLEService = exports.BLEService || (exports.BLEService = {})); var BLECharacteristic; @@ -278,7 +282,7 @@ var BLECharacteristic; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/duplotrainbase.js.html b/docs/duplotrainbase.js.html index 617adcd..ec4c0c6 100644 --- a/docs/duplotrainbase.js.html +++ b/docs/duplotrainbase.js.html @@ -135,7 +135,9 @@ class DuploTrainBase extends lpf2hub_1.LPF2Hub { * @ignore */ static IsDuploTrainBase(peripheral) { - return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.DUPLO_TRAIN_HUB_ID); + return (peripheral.advertisement && + peripheral.advertisement.serviceUuids && + peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.DUPLO_TRAIN_HUB_ID); } constructor(peripheral, autoSubscribe = true) { super(peripheral, autoSubscribe); @@ -298,7 +300,7 @@ exports.DuploTrainBase = DuploTrainBase; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/global.html b/docs/global.html index 83d2d37..af0009d 100644 --- a/docs/global.html +++ b/docs/global.html @@ -3272,7 +3272,7 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/hub.js.html b/docs/hub.js.html index 1905713..ec3a935 100644 --- a/docs/hub.js.html +++ b/docs/hub.js.html @@ -102,34 +102,29 @@ const debug = Debug("hub"); * @extends EventEmitter */ class Hub extends events_1.EventEmitter { - constructor(peripheral, autoSubscribe = true) { + constructor(device, autoSubscribe = true) { super(); this.autoSubscribe = true; this.useSpeedMap = true; this.type = Consts.HubType.UNKNOWN; this._ports = {}; - this._characteristics = {}; this._name = ""; this._firmwareInfo = { major: 0, minor: 0, bugFix: 0, build: 0 }; this._batteryLevel = 100; this._voltage = 0; this._current = 0; this._rssi = -100; + this._isConnecting = false; + this._isConnected = false; this.autoSubscribe = !!autoSubscribe; - this._peripheral = peripheral; - this._uuid = peripheral.uuid; - // NK: This hack allows LPF2.0 hubs to send a second advertisement packet consisting of the hub name before we try to read it - setTimeout(() => { - this._name = peripheral.advertisement.localName; - this.emit("discoverComplete"); - }, 1000); + this._bleDevice = device; } /** * @readonly * @property {string} name Name of the hub */ get name() { - return this._name; + return this._bleDevice.name; } /** * @readonly @@ -143,7 +138,7 @@ class Hub extends events_1.EventEmitter { * @property {string} uuid UUID of the hub */ get uuid() { - return this._uuid; + return this._bleDevice.uuid; } /** * @readonly @@ -179,47 +174,60 @@ class Hub extends events_1.EventEmitter { * @returns {Promise} Resolved upon successful connect. */ connect() { - return new Promise((connectResolve, connectReject) => { + return new Promise(async (connectResolve, connectReject) => { const self = this; - this._peripheral.connect((err) => { - this._rssi = this._peripheral.rssi; - const rssiUpdateInterval = setInterval(() => { - this._peripheral.updateRssi((err, rssi) => { - if (!err) { - if (this._rssi !== rssi) { - this._rssi = rssi; - } - } - }); - }, 2000); - self._peripheral.on("disconnect", () => { - clearInterval(rssiUpdateInterval); - this.emit("disconnect"); - }); - self._peripheral.discoverServices([], (err, services) => { - if (err) { - this.emit("error", err); - return; - } - debug("Service/characteristic discovery started"); - const servicePromises = []; - services.forEach((service) => { - servicePromises.push(new Promise((resolve, reject) => { - service.discoverCharacteristics([], (err, characteristics) => { - characteristics.forEach((characteristic) => { - this._characteristics[characteristic.uuid] = characteristic; - }); - return resolve(); - }); - })); - }); - Promise.all(servicePromises).then(() => { - debug("Service/characteristic discovery finished"); - this.emit("connect"); - return connectResolve(); - }); - }); - }); + if (this._isConnecting) { + return connectReject("Already connecting"); + } + else if (this._isConnected) { + return connectReject("Already connected"); + } + this._isConnecting = true; + await this._bleDevice.connect(); + return connectResolve(); + // this._peripheral.connect((err: string) => { + // this._rssi = this._peripheral.rssi; + // const rssiUpdateInterval = setInterval(() => { + // this._peripheral.updateRssi((err: string, rssi: number) => { + // if (!err) { + // if (this._rssi !== rssi) { + // this._rssi = rssi; + // } + // } + // }); + // }, 2000); + // self._peripheral.on("disconnect", () => { + // clearInterval(rssiUpdateInterval); + // this._isConnecting = false; + // this._isConnected = false; + // this.emit("disconnect"); + // }); + // self._peripheral.discoverServices([], (err: string, services: Service[]) => { + // if (err) { + // this.emit("error", err); + // return; + // } + // debug("Service/characteristic discovery started"); + // const servicePromises: Array<Promise<null>> = []; + // services.forEach((service) => { + // servicePromises.push(new Promise((resolve, reject) => { + // service.discoverCharacteristics([], (err, characteristics) => { + // characteristics.forEach((characteristic) => { + // this._characteristics[characteristic.uuid] = characteristic; + // }); + // return resolve(); + // }); + // })); + // }); + // Promise.all(servicePromises).then(() => { + // debug("Service/characteristic discovery finished"); + // this._isConnecting = false; + // this._isConnected = true; + // this.emit("connect"); + // return connectResolve(); + // }); + // }); + // }); }); } /** @@ -227,12 +235,8 @@ class Hub extends events_1.EventEmitter { * @method Hub#disconnect * @returns {Promise} Resolved upon successful disconnect. */ - disconnect() { - return new Promise((resolve, reject) => { - this._peripheral.disconnect(() => { - return resolve(); - }); - }); + async disconnect() { + await this._bleDevice.disconnect(); } /** * Subscribe to sensor notifications on a given port. @@ -307,19 +311,19 @@ class Hub extends events_1.EventEmitter { getPortDeviceType(port) { return this._portLookup(port).type; } - _getCharacteristic(uuid) { - return this._characteristics[uuid.replace(/-/g, "")]; - } - _subscribeToCharacteristic(characteristic, callback) { - characteristic.on("data", (data) => { - return callback(data); - }); - characteristic.subscribe((err) => { - if (err) { - this.emit("error", err); - } - }); - } + // protected _getCharacteristic (uuid: string) { + // return this._characteristics[uuid.replace(/-/g, "")]; + // } + // protected _subscribeToCharacteristic (characteristic: Characteristic, callback: (data: Buffer) => void) { + // characteristic.on("data", (data: Buffer) => { + // return callback(data); + // }); + // characteristic.subscribe((err) => { + // if (err) { + // this.emit("error", err); + // } + // }); + // } _activatePortDevice(port, type, mode, format, callback) { if (callback) { callback(); @@ -485,7 +489,7 @@ exports.Hub = Hub; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/index.html b/docs/index.html index 40feb73..0a9385e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -314,7 +314,7 @@ poweredUP.scan(); // Start scanning for Hubs

More examples are av Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/lpf2hub.js.html b/docs/lpf2hub.js.html index 674bd2b..d117ba4 100644 --- a/docs/lpf2hub.js.html +++ b/docs/lpf2hub.js.html @@ -111,8 +111,8 @@ class LPF2Hub extends hub_1.Hub { connect() { return new Promise(async (resolve, reject) => { await super.connect(); - const characteristic = this._getCharacteristic(Consts.BLECharacteristic.LPF2_ALL); - this._subscribeToCharacteristic(characteristic, this._parseMessage.bind(this)); + await this._bleDevice.discoverCharacteristicsForService(Consts.BLEService.LPF2_HUB); + this._bleDevice.subscribeToCharacteristic(Consts.BLECharacteristic.LPF2_ALL, this._parseMessage.bind(this)); setTimeout(() => { this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x02, 0x02])); // Activate button reports this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x03, 0x05])); // Request firmware version @@ -122,8 +122,9 @@ class LPF2Hub extends hub_1.Hub { if (this.type === Consts.HubType.DUPLO_TRAIN_HUB) { this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01])); } + this.emit("connect"); + return resolve(); }, 1000); - return resolve(); }); } /** @@ -207,13 +208,10 @@ class LPF2Hub extends hub_1.Hub { this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x00]), callback); } _writeMessage(uuid, message, callback) { - const characteristic = this._getCharacteristic(uuid); - if (characteristic) { - message = Buffer.concat([Buffer.alloc(2), message]); - message[0] = message.length; - debug("Sent Message (LPF2_ALL)", message); - characteristic.write(message, false, callback); - } + message = Buffer.concat([Buffer.alloc(2), message]); + message[0] = message.length; + debug("Sent Message (LPF2_ALL)", message); + this._bleDevice.writeToCharacteristic(uuid, message, callback); } _parseMessage(data) { if (data) { @@ -507,7 +505,7 @@ exports.LPF2Hub = LPF2Hub; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/poweredup.js.html b/docs/poweredup.js.html index c0f8e66..949a4c6 100644 --- a/docs/poweredup.js.html +++ b/docs/poweredup.js.html @@ -93,6 +93,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); +const bledevice_1 = require("./bledevice"); const boostmovehub_1 = require("./boostmovehub"); const duplotrainbase_1 = require("./duplotrainbase"); const puphub_1 = require("./puphub"); @@ -192,21 +193,22 @@ class PoweredUP extends events_1.EventEmitter { return Object.keys(this._connectedHubs).map((uuid) => this._connectedHubs[uuid]).filter((hub) => hub.name === name); } async _discoveryEventHandler(peripheral) { + const device = new bledevice_1.BLEDevice(peripheral); let hub; if (await wedo2smarthub_1.WeDo2SmartHub.IsWeDo2SmartHub(peripheral)) { - hub = new wedo2smarthub_1.WeDo2SmartHub(peripheral, this.autoSubscribe); + hub = new wedo2smarthub_1.WeDo2SmartHub(device, this.autoSubscribe); } else if (await boostmovehub_1.BoostMoveHub.IsBoostMoveHub(peripheral)) { - hub = new boostmovehub_1.BoostMoveHub(peripheral, this.autoSubscribe); + hub = new boostmovehub_1.BoostMoveHub(device, this.autoSubscribe); } else if (await puphub_1.PUPHub.IsPUPHub(peripheral)) { - hub = new puphub_1.PUPHub(peripheral, this.autoSubscribe); + hub = new puphub_1.PUPHub(device, this.autoSubscribe); } else if (await pupremote_1.PUPRemote.IsPUPRemote(peripheral)) { - hub = new pupremote_1.PUPRemote(peripheral, this.autoSubscribe); + hub = new pupremote_1.PUPRemote(device, this.autoSubscribe); } else if (await duplotrainbase_1.DuploTrainBase.IsDuploTrainBase(peripheral)) { - hub = new duplotrainbase_1.DuploTrainBase(peripheral, this.autoSubscribe); + hub = new duplotrainbase_1.DuploTrainBase(device, this.autoSubscribe); } else { return; @@ -216,7 +218,7 @@ class PoweredUP extends events_1.EventEmitter { // if (!isBrowserContext) { // startScanning(); // } - hub.on("discoverComplete", () => { + device.on("discoverComplete", () => { hub.on("connect", () => { debug(`Hub ${hub.uuid} connected`); this._connectedHubs[hub.uuid] = hub; @@ -284,7 +286,7 @@ exports.PoweredUP = PoweredUP; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/puphub.js.html b/docs/puphub.js.html index 094618a..c5d4a1c 100644 --- a/docs/puphub.js.html +++ b/docs/puphub.js.html @@ -115,7 +115,9 @@ class PUPHub extends lpf2hub_1.LPF2Hub { * @ignore */ static IsPUPHub(peripheral) { - return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_HUB_ID); + return (peripheral.advertisement && + peripheral.advertisement.serviceUuids && + peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_HUB_ID); } constructor(peripheral, autoSubscribe = true) { super(peripheral, autoSubscribe); @@ -306,7 +308,7 @@ exports.PUPHub = PUPHub; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/pupremote.js.html b/docs/pupremote.js.html index 32caa92..1d379ad 100644 --- a/docs/pupremote.js.html +++ b/docs/pupremote.js.html @@ -135,7 +135,9 @@ class PUPRemote extends lpf2hub_1.LPF2Hub { * @ignore */ static IsPUPRemote(peripheral) { - return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID); + return (peripheral.advertisement && + peripheral.advertisement.serviceUuids && + peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID); } constructor(peripheral, autoSubscribe = true) { super(peripheral, autoSubscribe); @@ -236,7 +238,7 @@ exports.PUPRemote = PUPRemote; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 6th 2019 using the DocStrap template. diff --git a/docs/quicksearch.html b/docs/quicksearch.html index 4f4fcab..36d0011 100644 --- a/docs/quicksearch.html +++ b/docs/quicksearch.html @@ -7,7 +7,7 @@