From 4185f79c5248f22618c0027c5fbded611cda06ad Mon Sep 17 00:00:00 2001 From: Nathan Kellenicki Date: Tue, 29 Jan 2019 19:47:02 -0800 Subject: [PATCH] Made name discovery a little more robust --- docs/BoostMoveHub.html | 34 +++++++++++++++++----------------- docs/DuploTrainBase.html | 30 +++++++++++++++--------------- docs/Hub.html | 34 +++++++++++++++++----------------- docs/LPF2Hub.html | 34 +++++++++++++++++----------------- docs/PUPHub.html | 34 +++++++++++++++++----------------- docs/PUPRemote.html | 30 +++++++++++++++--------------- docs/PoweredUP.html | 4 ++-- docs/WeDo2SmartHub.html | 34 +++++++++++++++++----------------- docs/boostmovehub.js.html | 2 +- docs/classes.list.html | 24 ++++++++++++------------ docs/consts.js.html | 2 +- docs/duplotrainbase.js.html | 2 +- docs/global.html | 2 +- docs/hub.js.html | 9 +++++++-- docs/index.html | 2 +- docs/lpf2hub.js.html | 2 +- docs/poweredup.js.html | 18 ++++++++++-------- docs/puphub.js.html | 2 +- docs/pupremote.js.html | 2 +- docs/quicksearch.html | 2 +- docs/wedo2smarthub.js.html | 2 +- package.json | 2 +- src/hub.ts | 1 + src/poweredup.ts | 5 ++--- 24 files changed, 160 insertions(+), 153 deletions(-) diff --git a/docs/BoostMoveHub.html b/docs/BoostMoveHub.html index 30396d4..61f485e 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 @@ @@ -1250,7 +1250,7 @@ @@ -1376,7 +1376,7 @@ @@ -1502,7 +1502,7 @@ @@ -1674,7 +1674,7 @@ @@ -3499,7 +3499,7 @@ @@ -3719,7 +3719,7 @@ @@ -3895,7 +3895,7 @@ @@ -4072,7 +4072,7 @@ @@ -4280,7 +4280,7 @@ @@ -4969,7 +4969,7 @@ @@ -5585,7 +5585,7 @@ Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/DuploTrainBase.html b/docs/DuploTrainBase.html index 07b978f..81a5fee 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 @@ @@ -1250,7 +1250,7 @@ @@ -1376,7 +1376,7 @@ @@ -1502,7 +1502,7 @@ @@ -1674,7 +1674,7 @@ @@ -3162,7 +3162,7 @@ @@ -3382,7 +3382,7 @@ @@ -3558,7 +3558,7 @@ @@ -3735,7 +3735,7 @@ @@ -4188,7 +4188,7 @@ Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/Hub.html b/docs/Hub.html index 40d1a83..3e0e2e0 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 Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/LPF2Hub.html b/docs/LPF2Hub.html index 5672dfd..0de5e53 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 @@ @@ -2275,7 +2275,7 @@ @@ -2490,7 +2490,7 @@ @@ -2661,7 +2661,7 @@ @@ -2833,7 +2833,7 @@ @@ -3036,7 +3036,7 @@ @@ -3693,7 +3693,7 @@ @@ -4444,7 +4444,7 @@ Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/PUPHub.html b/docs/PUPHub.html index dd0f388..0e57e1c 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 @@ @@ -1250,7 +1250,7 @@ @@ -1376,7 +1376,7 @@ @@ -1502,7 +1502,7 @@ @@ -1674,7 +1674,7 @@ @@ -3242,7 +3242,7 @@ @@ -3462,7 +3462,7 @@ @@ -3638,7 +3638,7 @@ @@ -3815,7 +3815,7 @@ @@ -4023,7 +4023,7 @@ @@ -4712,7 +4712,7 @@ @@ -5157,7 +5157,7 @@ Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/PUPRemote.html b/docs/PUPRemote.html index dd53ce5..50c8e59 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 @@ @@ -2359,7 +2359,7 @@ @@ -2579,7 +2579,7 @@ @@ -2755,7 +2755,7 @@ @@ -2932,7 +2932,7 @@ @@ -3409,7 +3409,7 @@ Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/PoweredUP.html b/docs/PoweredUP.html index 2728ded..5303a28 100644 --- a/docs/PoweredUP.html +++ b/docs/PoweredUP.html @@ -781,7 +781,7 @@ @@ -860,7 +860,7 @@ Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/WeDo2SmartHub.html b/docs/WeDo2SmartHub.html index 78de3a7..8cac2c1 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 @@ @@ -1218,7 +1218,7 @@ @@ -1339,7 +1339,7 @@ @@ -1460,7 +1460,7 @@ @@ -1627,7 +1627,7 @@ @@ -3225,7 +3225,7 @@ @@ -3440,7 +3440,7 @@ @@ -3611,7 +3611,7 @@ @@ -3783,7 +3783,7 @@ @@ -3986,7 +3986,7 @@ @@ -4457,7 +4457,7 @@ @@ -5046,7 +5046,7 @@ Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/boostmovehub.js.html b/docs/boostmovehub.js.html index 9f3d94e..968b0d4 100644 --- a/docs/boostmovehub.js.html +++ b/docs/boostmovehub.js.html @@ -349,7 +349,7 @@ exports.BoostMoveHub = BoostMoveHub; Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/classes.list.html b/docs/classes.list.html index a488015..a9a0736 100644 --- a/docs/classes.list.html +++ b/docs/classes.list.html @@ -335,7 +335,7 @@ @@ -1024,7 +1024,7 @@ @@ -2065,7 +2065,7 @@ @@ -2203,7 +2203,7 @@ @@ -2374,7 +2374,7 @@ @@ -3031,7 +3031,7 @@ @@ -3853,7 +3853,7 @@ @@ -4029,7 +4029,7 @@ @@ -4718,7 +4718,7 @@ @@ -5621,7 +5621,7 @@ @@ -6092,7 +6092,7 @@ @@ -6681,7 +6681,7 @@ Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/consts.js.html b/docs/consts.js.html index 4f66815..1e8f14d 100644 --- a/docs/consts.js.html +++ b/docs/consts.js.html @@ -277,7 +277,7 @@ var BLECharacteristic; Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/duplotrainbase.js.html b/docs/duplotrainbase.js.html index d457118..dd63833 100644 --- a/docs/duplotrainbase.js.html +++ b/docs/duplotrainbase.js.html @@ -298,7 +298,7 @@ exports.DuploTrainBase = DuploTrainBase; Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/global.html b/docs/global.html index fbb8dcc..bc8d120 100644 --- a/docs/global.html +++ b/docs/global.html @@ -3272,7 +3272,7 @@ Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/hub.js.html b/docs/hub.js.html index e2dcf80..1ab8d27 100644 --- a/docs/hub.js.html +++ b/docs/hub.js.html @@ -109,6 +109,7 @@ class Hub extends events_1.EventEmitter { 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; @@ -117,7 +118,11 @@ class Hub extends events_1.EventEmitter { this.autoSubscribe = !!autoSubscribe; this._peripheral = peripheral; this._uuid = peripheral.uuid; - this._name = peripheral.advertisement.localName; + // 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("ready"); + }, 200); } /** * @readonly @@ -480,7 +485,7 @@ exports.Hub = Hub; Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/index.html b/docs/index.html index 93757d5..25de7d6 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 Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/lpf2hub.js.html b/docs/lpf2hub.js.html index e8b76d8..f926291 100644 --- a/docs/lpf2hub.js.html +++ b/docs/lpf2hub.js.html @@ -507,7 +507,7 @@ exports.LPF2Hub = LPF2Hub; Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/poweredup.js.html b/docs/poweredup.js.html index 82efe9a..215328e 100644 --- a/docs/poweredup.js.html +++ b/docs/poweredup.js.html @@ -218,13 +218,15 @@ class PoweredUP extends events_1.EventEmitter { startScanning(); } }); - debug(`Hub ${hub.uuid} discovered`); - /** - * Emits when a Powered UP Hub device is found. - * @event PoweredUP#discover - * @param {WeDo2SmartHub | BoostMoveHub | PUPHub | PUPRemote | DuploTrainBase} hub - */ - this.emit("discover", hub); + hub.on("ready", () => { + debug(`Hub ${hub.uuid} discovered`); + /** + * Emits when a Powered UP Hub device is found. + * @event PoweredUP#discover + * @param {WeDo2SmartHub | BoostMoveHub | PUPHub | PUPRemote | DuploTrainBase} hub + */ + this.emit("discover", hub); + }); } } exports.PoweredUP = PoweredUP; @@ -273,7 +275,7 @@ exports.PoweredUP = PoweredUP; Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/puphub.js.html b/docs/puphub.js.html index 730484f..1105998 100644 --- a/docs/puphub.js.html +++ b/docs/puphub.js.html @@ -306,7 +306,7 @@ exports.PUPHub = PUPHub; Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/pupremote.js.html b/docs/pupremote.js.html index 009ff0e..037154c 100644 --- a/docs/pupremote.js.html +++ b/docs/pupremote.js.html @@ -236,7 +236,7 @@ exports.PUPRemote = PUPRemote; Documentation generated by JSDoc 3.5.5 - on Sat Jan 26th 2019 + on Tue Jan 29th 2019 using the DocStrap template. diff --git a/docs/quicksearch.html b/docs/quicksearch.html index 5b3fc3d..aeeb487 100644 --- a/docs/quicksearch.html +++ b/docs/quicksearch.html @@ -7,7 +7,7 @@