Fixed double disconnect bug, added hardware versions
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Nathan Kellenicki 2019-11-10 20:40:59 -08:00
parent fedc2bd6e4
commit 6315f54a23
5 changed files with 19 additions and 5 deletions

View File

@ -3,8 +3,8 @@
<head>
<title>Web Bluetooth node-poweredup Example</title>
<!-- <script src="https://cdn.jsdelivr.net/npm/node-poweredup@latest/dist/browser/poweredup.js"></script> -->
<script src="../dist/browser/poweredup.js"></script>
<script src="https://cdn.jsdelivr.net/npm/node-poweredup@latest/dist/browser/poweredup.js"></script>
<!-- <script src="../dist/browser/poweredup.js"></script> -->
<link rel="stylesheet" type="text/css" href="./web_bluetooth.css" />
<script>

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "node-poweredup",
"version": "4.0.2",
"version": "4.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "node-poweredup",
"version": "4.0.2",
"version": "4.1.0",
"description": "A Javascript module to interface with LEGO Powered Up components.",
"homepage": "https://github.com/nathankellenicki/node-poweredup/",
"main": "dist/node/index-node.js",

View File

@ -25,6 +25,7 @@ export class Hub extends EventEmitter {
protected _name: string = "";
protected _firmwareVersion: string = "0.0.00.0000";
protected _hardwareVersion: string = "0.0.00.0000";
protected _batteryLevel: number = 100;
protected _voltage: number = 0;
protected _current: number = 0;
@ -63,6 +64,15 @@ export class Hub extends EventEmitter {
}
/**
* @readonly
* @property {string} firmwareVersion Hardware version of the hub
*/
public get hardwareVersion () {
return this._hardwareVersion;
}
/**
* @readonly
* @property {string} uuid UUID of the hub
@ -134,7 +144,6 @@ export class Hub extends EventEmitter {
* @returns {Promise} Resolved upon successful disconnect.
*/
public async disconnect () {
this.emit("disconnect");
this._bleDevice.disconnect();
}

View File

@ -36,6 +36,7 @@ export class LPF2Hub extends Hub {
this._bleDevice.subscribeToCharacteristic(Consts.BLECharacteristic.LPF2_ALL, this._parseMessage.bind(this));
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
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x04, 0x05])); // Request hardware version
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x06, 0x02])); // Activate battery level reports
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate current reports
@ -250,6 +251,10 @@ export class LPF2Hub extends Hub {
this._firmwareVersion = LPF2Hub.decodeVersion(data.readInt32LE(5));
this._checkFirmware(this._firmwareVersion);
// Hardware version
} else if (data[3] === 0x04) {
this._hardwareVersion = LPF2Hub.decodeVersion(data.readInt32LE(5));
// Battery level reports
} else if (data[3] === 0x06) {
this._batteryLevel = data[5];