diff --git a/docs/BoostMoveHub.html b/docs/BoostMoveHub.html index f10abce..7600435 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 @@ diff --git a/docs/DuploTrainBase.html b/docs/DuploTrainBase.html index 6027706..7b7bae5 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 @@ diff --git a/docs/Hub.html b/docs/Hub.html index b905d28..fca24e1 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 @@ diff --git a/docs/LPF2Hub.html b/docs/LPF2Hub.html index 1b7bb69..86dc94d 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 @@ diff --git a/docs/PUPHub.html b/docs/PUPHub.html index adfe834..38703a2 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 @@ diff --git a/docs/PUPRemote.html b/docs/PUPRemote.html index 00230ea..771ef7e 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 @@ diff --git a/docs/PoweredUP.html b/docs/PoweredUP.html index 126961e..9eef7db 100644 --- a/docs/PoweredUP.html +++ b/docs/PoweredUP.html @@ -1018,7 +1018,7 @@ diff --git a/docs/WeDo2SmartHub.html b/docs/WeDo2SmartHub.html index a39c253..70120b5 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 @@ @@ -3337,7 +3337,7 @@ @@ -3552,7 +3552,7 @@ @@ -3723,7 +3723,7 @@ @@ -3895,7 +3895,7 @@ @@ -4098,7 +4098,7 @@ @@ -4569,7 +4569,7 @@ @@ -5158,7 +5158,7 @@ diff --git a/docs/boostmovehub.js.html b/docs/boostmovehub.js.html index 1bde08a..ef05d6e 100644 --- a/docs/boostmovehub.js.html +++ b/docs/boostmovehub.js.html @@ -349,7 +349,7 @@ exports.BoostMoveHub = BoostMoveHub; diff --git a/docs/classes.list.html b/docs/classes.list.html index f4dd319..0bcf8f2 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 @@ @@ -4029,7 +4029,7 @@ @@ -4718,7 +4718,7 @@ @@ -5621,7 +5621,7 @@ @@ -6092,7 +6092,7 @@ @@ -6681,7 +6681,7 @@ diff --git a/docs/consts.js.html b/docs/consts.js.html index 797c441..7681cd7 100644 --- a/docs/consts.js.html +++ b/docs/consts.js.html @@ -278,7 +278,7 @@ var BLECharacteristic; diff --git a/docs/duplotrainbase.js.html b/docs/duplotrainbase.js.html index 617adcd..23f5657 100644 --- a/docs/duplotrainbase.js.html +++ b/docs/duplotrainbase.js.html @@ -298,7 +298,7 @@ exports.DuploTrainBase = DuploTrainBase; diff --git a/docs/global.html b/docs/global.html index 83d2d37..bcb5f04 100644 --- a/docs/global.html +++ b/docs/global.html @@ -3272,7 +3272,7 @@ diff --git a/docs/hub.js.html b/docs/hub.js.html index 1905713..65c527a 100644 --- a/docs/hub.js.html +++ b/docs/hub.js.html @@ -115,6 +115,8 @@ class Hub extends events_1.EventEmitter { 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; @@ -181,6 +183,13 @@ class Hub extends events_1.EventEmitter { connect() { return new Promise((connectResolve, connectReject) => { const self = this; + if (this._isConnecting) { + return connectReject("Already connecting"); + } + else if (this._isConnected) { + return connectReject("Already connected"); + } + this._isConnecting = true; this._peripheral.connect((err) => { this._rssi = this._peripheral.rssi; const rssiUpdateInterval = setInterval(() => { @@ -194,6 +203,8 @@ class Hub extends events_1.EventEmitter { }, 2000); self._peripheral.on("disconnect", () => { clearInterval(rssiUpdateInterval); + this._isConnecting = false; + this._isConnected = false; this.emit("disconnect"); }); self._peripheral.discoverServices([], (err, services) => { @@ -215,6 +226,8 @@ class Hub extends events_1.EventEmitter { }); Promise.all(servicePromises).then(() => { debug("Service/characteristic discovery finished"); + this._isConnecting = false; + this._isConnected = true; this.emit("connect"); return connectResolve(); }); @@ -485,7 +498,7 @@ exports.Hub = Hub; diff --git a/docs/index.html b/docs/index.html index 40feb73..b4d0ebe 100644 --- a/docs/index.html +++ b/docs/index.html @@ -251,19 +251,25 @@ const poweredUP = new PoweredUP.PoweredUP(); poweredUP.on("discover", async (hub) => { // Wait to discover a Hub + console.log(`Discovered ${hub.name}!`); await hub.connect(); // Connect to the Hub + console.log("Connected"); await hub.sleep(3000); // Sleep for 3 seconds before starting while (true) { // Repeat indefinitely + console.log("Running motor B at speed 75"); hub.setMotorSpeed("B", 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely + console.log("Running motor A at speed 100 for 2 seconds"); await hub.setMotorSpeed("A", 100, 2000); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop await hub.sleep(1000); // Do nothing for 1 second + console.log("Running motor A at speed -50 for 1 seconds"); await hub.setMotorSpeed("A", -50, 1000); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop await hub.sleep(1000); // Do nothing for 1 second } }); -poweredUP.scan(); // Start scanning for HubsMore examples are available in the "examples" directory.
+poweredUP.scan(); // Start scanning for Hubs +console.log("Scanning for Hubs...");More examples are available in the "examples" directory.
Thanks go to Jorge Pereira (@JorgePe), Sebastian Raff (@hobbyquaker), Valentin Heun (@vheun), Johan Korten (@jakorten), and Andrey Pokhilko (@undera) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered UP protocols.
@@ -314,7 +320,7 @@ poweredUP.scan(); // Start scanning for HubsMore examples are av
diff --git a/docs/lpf2hub.js.html b/docs/lpf2hub.js.html index 674bd2b..c814983 100644 --- a/docs/lpf2hub.js.html +++ b/docs/lpf2hub.js.html @@ -507,7 +507,7 @@ exports.LPF2Hub = LPF2Hub; diff --git a/docs/poweredup.js.html b/docs/poweredup.js.html index c0f8e66..fbf1a18 100644 --- a/docs/poweredup.js.html +++ b/docs/poweredup.js.html @@ -284,7 +284,7 @@ exports.PoweredUP = PoweredUP; diff --git a/docs/puphub.js.html b/docs/puphub.js.html index 094618a..3b061ef 100644 --- a/docs/puphub.js.html +++ b/docs/puphub.js.html @@ -306,7 +306,7 @@ exports.PUPHub = PUPHub; diff --git a/docs/pupremote.js.html b/docs/pupremote.js.html index 32caa92..97ecad2 100644 --- a/docs/pupremote.js.html +++ b/docs/pupremote.js.html @@ -236,7 +236,7 @@ exports.PUPRemote = PUPRemote; diff --git a/docs/quicksearch.html b/docs/quicksearch.html index 4f4fcab..52e499e 100644 --- a/docs/quicksearch.html +++ b/docs/quicksearch.html @@ -7,7 +7,7 @@