Made discovery more reliable
This commit is contained in:
parent
6d5ad34401
commit
ba44189faa
@ -4148,7 +4148,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-268">line 268</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-280">line 280</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
@ -4310,7 +4310,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-313">line 313</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-325">line 325</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
@ -4619,7 +4619,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-302">line 302</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-314">line 314</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
@ -4781,7 +4781,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-343">line 343</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-355">line 355</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
@ -4967,7 +4967,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-331">line 331</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-343">line 343</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
|
@ -5783,7 +5783,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-268">line 268</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-280">line 280</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
@ -5945,7 +5945,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-313">line 313</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-325">line 325</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
@ -6254,7 +6254,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-302">line 302</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-314">line 314</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
@ -6416,7 +6416,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-343">line 343</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-355">line 355</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
@ -6602,7 +6602,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<a href="wedo2smarthub.js.html">wedo2smarthub.js</a>,
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-331">line 331</a>
|
||||
<a href="wedo2smarthub.js.html#sunlight-1-line-343">line 343</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
|
@ -121,8 +121,8 @@ class Hub extends events_1.EventEmitter {
|
||||
// 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);
|
||||
this.emit("discoverComplete");
|
||||
}, 500);
|
||||
}
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -207,6 +207,7 @@ class PoweredUP extends events_1.EventEmitter {
|
||||
if (!utils_1.isBrowserContext) {
|
||||
startScanning();
|
||||
}
|
||||
hub.on("discoverComplete", () => {
|
||||
hub.on("connect", () => {
|
||||
debug(`Hub ${hub.uuid} connected`);
|
||||
this._connectedHubs[hub.uuid] = hub;
|
||||
@ -218,7 +219,6 @@ class PoweredUP extends events_1.EventEmitter {
|
||||
startScanning();
|
||||
}
|
||||
});
|
||||
hub.on("ready", () => {
|
||||
debug(`Hub ${hub.uuid} discovered`);
|
||||
/**
|
||||
* Emits when a Powered UP Hub device is found.
|
||||
|
File diff suppressed because one or more lines are too long
@ -322,10 +322,22 @@ class WeDo2SmartHub extends hub_1.Hub {
|
||||
_writeMessage(uuid, message, callback) {
|
||||
const characteristic = this._getCharacteristic(uuid);
|
||||
if (characteristic) {
|
||||
debug(`Sent Message (${uuid})`, message);
|
||||
if (debug.enabled) {
|
||||
debug(`Sent Message (${this._getCharacteristicNameFromUUID(uuid)})`, message);
|
||||
}
|
||||
characteristic.write(message, false, callback);
|
||||
}
|
||||
}
|
||||
_getCharacteristicNameFromUUID(uuid) {
|
||||
const keys = Object.keys(Consts.BLECharacteristic);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
if (Consts.BLECharacteristic[key] === uuid) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
_parseHighCurrentAlert(data) {
|
||||
debug("Received Message (WEDO2_HIGH_CURRENT_ALERT)", data);
|
||||
// console.log(data);
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-poweredup",
|
||||
"version": "1.7.2",
|
||||
"version": "1.7.3",
|
||||
"description": "A Node.js module to interface with LEGO Powered UP components.",
|
||||
"homepage": "https://github.com/nathankellenicki/node-poweredup/",
|
||||
"main": "dist/index.js",
|
||||
|
@ -49,8 +49,8 @@ export class Hub extends EventEmitter {
|
||||
// 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);
|
||||
this.emit("discoverComplete");
|
||||
}, 500);
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,6 +140,8 @@ export class PoweredUP extends EventEmitter {
|
||||
startScanning();
|
||||
}
|
||||
|
||||
hub.on("discoverComplete", () => {
|
||||
|
||||
hub.on("connect", () => {
|
||||
debug(`Hub ${hub.uuid} connected`);
|
||||
this._connectedHubs[hub.uuid] = hub;
|
||||
@ -154,14 +156,15 @@ export class PoweredUP extends EventEmitter {
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -266,12 +266,26 @@ export class WeDo2SmartHub extends Hub {
|
||||
private _writeMessage (uuid: string, message: Buffer, callback?: () => void) {
|
||||
const characteristic = this._getCharacteristic(uuid);
|
||||
if (characteristic) {
|
||||
debug(`Sent Message (${uuid})`, message);
|
||||
if (debug.enabled) {
|
||||
debug(`Sent Message (${this._getCharacteristicNameFromUUID(uuid)})`, message);
|
||||
}
|
||||
characteristic.write(message, false, callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private _getCharacteristicNameFromUUID (uuid: string) {
|
||||
const keys = Object.keys(Consts.BLECharacteristic);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
if (Consts.BLECharacteristic[key as any] === uuid) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
|
||||
private _parseHighCurrentAlert (data: Buffer) {
|
||||
debug("Received Message (WEDO2_HIGH_CURRENT_ALERT)", data);
|
||||
// console.log(data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user