From 2e68ae54094c62eaa71bd403bdb697c2a8fc9883 Mon Sep 17 00:00:00 2001 From: Nathan Kellenicki Date: Sat, 9 Feb 2019 11:18:15 -0800 Subject: [PATCH 1/7] Added logging to the sample --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index ef956f1..a495bdd 100644 --- a/README.md +++ b/README.md @@ -74,19 +74,25 @@ const PoweredUP = require("node-poweredup"); 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 Hubs +console.log("Scanning for Hubs..."); ``` More examples are available in the "examples" directory. From 1ff3d2c8c38ba32423958f5a2e44580366f44f3d Mon Sep 17 00:00:00 2001 From: Nathan Kellenicki Date: Wed, 13 Feb 2019 13:18:32 -0800 Subject: [PATCH 2/7] Added Drone config --- .drone.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..f5ffed4 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,7 @@ +pipeline: + install: + image: node:8.11.4 + commands: + - sudo apt-get update + - sudo apt-get install -y bluetooth bluez libbluetooth-dev libudev-dev + - npm install From 228b02735decd7cdbfb56c6437d845471d23ff14 Mon Sep 17 00:00:00 2001 From: Nathan Kellenicki Date: Wed, 13 Feb 2019 13:19:49 -0800 Subject: [PATCH 3/7] Updated docs --- 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 | 2 +- docs/WeDo2SmartHub.html | 34 +++++++++++++++++----------------- docs/boostmovehub.js.html | 2 +- docs/classes.list.html | 22 +++++++++++----------- docs/consts.js.html | 2 +- docs/duplotrainbase.js.html | 2 +- docs/global.html | 2 +- docs/hub.js.html | 15 ++++++++++++++- docs/index.html | 10 ++++++++-- docs/lpf2hub.js.html | 2 +- docs/poweredup.js.html | 2 +- docs/puphub.js.html | 2 +- docs/pupremote.js.html | 2 +- docs/quicksearch.html | 2 +- docs/wedo2smarthub.js.html | 2 +- 21 files changed, 159 insertions(+), 140 deletions(-) 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@ Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 Hubs

More 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.

Credits

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 Hubs

More examples are av Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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; Documentation generated by JSDoc 3.5.5 - on Mon Feb 4th 2019 + on Wed Feb 13th 2019 using the DocStrap template. 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 @@