Fixed double disconnect bug, added hardware versions
This commit is contained in:
parent
fedc2bd6e4
commit
6315f54a23
@ -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
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-poweredup",
|
||||
"version": "4.0.2",
|
||||
"version": "4.1.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -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",
|
||||
|
11
src/hub.ts
11
src/hub.ts
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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];
|
||||
|
Loading…
x
Reference in New Issue
Block a user