diff --git a/DOCS.md b/DOCS.md
index 1978866..d794037 100644
--- a/DOCS.md
+++ b/DOCS.md
@@ -92,6 +92,7 @@ Emits when a Powered UP Hub device is found.
* [WeDo2SmartHub](#WeDo2SmartHub) ⇐ Hub
* [new WeDo2SmartHub()](#new_WeDo2SmartHub_new)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -135,6 +136,17 @@ The WeDo2SmartHub is emitted if the discovered device is a WeDo 2.0 Smart Hub.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### weDo2SmartHub.firmwareVersion
+**Kind**: instance property of [WeDo2SmartHub
](#WeDo2SmartHub)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### weDo2SmartHub.uuid
@@ -453,6 +465,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new BoostMoveHub()](#new_BoostMoveHub_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -509,6 +522,18 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### boostMoveHub.firmwareVersion
+**Kind**: instance property of [BoostMoveHub
](#BoostMoveHub)
+**Overrides**: [firmwareVersion
](#Hub+firmwareVersion)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### boostMoveHub.uuid
@@ -853,6 +878,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new PUPHub()](#new_PUPHub_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -907,6 +933,18 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### pupHub.firmwareVersion
+**Kind**: instance property of [PUPHub
](#PUPHub)
+**Overrides**: [firmwareVersion
](#Hub+firmwareVersion)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### pupHub.uuid
@@ -1225,6 +1263,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new PUPRemote()](#new_PUPRemote_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -1270,6 +1309,18 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### pupRemote.firmwareVersion
+**Kind**: instance property of [PUPRemote
](#PUPRemote)
+**Overrides**: [firmwareVersion
](#Hub+firmwareVersion)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### pupRemote.uuid
@@ -1473,6 +1524,7 @@ A combined color and distance event, emits when the sensor is activated.
* [new DuploTrainBase()](#new_DuploTrainBase_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -1523,6 +1575,18 @@ The DuploTrainBase is emitted if the discovered device is a Duplo Train Base.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### duploTrainBase.firmwareVersion
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
+**Overrides**: [firmwareVersion
](#Hub+firmwareVersion)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### duploTrainBase.uuid
diff --git a/README.md b/README.md
index 27542a8..4920a9e 100644
--- a/README.md
+++ b/README.md
@@ -185,6 +185,7 @@ Emits when a Powered UP Hub device is found.
* [WeDo2SmartHub](#WeDo2SmartHub) ⇐ Hub
* [new WeDo2SmartHub()](#new_WeDo2SmartHub_new)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -228,6 +229,17 @@ The WeDo2SmartHub is emitted if the discovered device is a WeDo 2.0 Smart Hub.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### weDo2SmartHub.firmwareVersion
+**Kind**: instance property of [WeDo2SmartHub
](#WeDo2SmartHub)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### weDo2SmartHub.uuid
@@ -546,6 +558,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new BoostMoveHub()](#new_BoostMoveHub_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -602,6 +615,18 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### boostMoveHub.firmwareVersion
+**Kind**: instance property of [BoostMoveHub
](#BoostMoveHub)
+**Overrides**: [firmwareVersion
](#Hub+firmwareVersion)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### boostMoveHub.uuid
@@ -946,6 +971,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new PUPHub()](#new_PUPHub_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -1000,6 +1026,18 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### pupHub.firmwareVersion
+**Kind**: instance property of [PUPHub
](#PUPHub)
+**Overrides**: [firmwareVersion
](#Hub+firmwareVersion)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### pupHub.uuid
@@ -1318,6 +1356,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new PUPRemote()](#new_PUPRemote_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -1363,6 +1402,18 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### pupRemote.firmwareVersion
+**Kind**: instance property of [PUPRemote
](#PUPRemote)
+**Overrides**: [firmwareVersion
](#Hub+firmwareVersion)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### pupRemote.uuid
@@ -1566,6 +1617,7 @@ A combined color and distance event, emits when the sensor is activated.
* [new DuploTrainBase()](#new_DuploTrainBase_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
+ * [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@@ -1616,6 +1668,18 @@ The DuploTrainBase is emitted if the discovered device is a Duplo Train Base.
| --- | --- | --- |
| name | string
| Name of the hub |
+
+
+### duploTrainBase.firmwareVersion
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
+**Overrides**: [firmwareVersion
](#Hub+firmwareVersion)
+**Read only**: true
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| firmwareVersion | string
| Firmware version of the hub |
+
### duploTrainBase.uuid
diff --git a/src/hub.ts b/src/hub.ts
index 8c172cf..0b61f8d 100644
--- a/src/hub.ts
+++ b/src/hub.ts
@@ -25,6 +25,7 @@ export class Hub extends EventEmitter {
protected _characteristics: {[uuid: string]: Characteristic} = {};
protected _name: string;
+ protected _firmwareVersion: string = "0.0.0.0";
protected _batteryLevel: number = 100;
private _peripheral: Peripheral;
@@ -49,6 +50,15 @@ export class Hub extends EventEmitter {
}
+ /**
+ * @readonly
+ * @property {string} firmwareVersion Firmware version of the hub
+ */
+ public get firmwareVersion () {
+ return this._firmwareVersion;
+ }
+
+
/**
* @readonly
* @property {string} uuid UUID of the hub
diff --git a/src/lpf2hub.ts b/src/lpf2hub.ts
index 3277edd..a88828b 100644
--- a/src/lpf2hub.ts
+++ b/src/lpf2hub.ts
@@ -40,6 +40,7 @@ export class LPF2Hub extends Hub {
const characteristic = this._getCharacteristic(Consts.BLECharacteristic.LPF2_ALL);
this._subscribeToCharacteristic(characteristic, 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])); // Get firmware version
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate current reports
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
if (this.type === Consts.HubType.DUPLO_TRAIN_HUB) {
@@ -190,6 +191,18 @@ export class LPF2Hub extends Hub {
this.emit("button", "GREEN", Consts.ButtonState.RELEASED);
return;
}
+ } else if (data[3] === 3) {
+ const fwData = data.slice(5, data.length);
+ let bcd = fwData.readUInt8(3);
+ const major = bcd >>> 4;
+ const minor = bcd & 0xf;
+ bcd = fwData.readUInt8(2);
+ const bugFix = bcd >>> 4 * 10 + bcd & 0xf;
+ bcd = fwData.readUInt8(1);
+ let build = bcd >>> 4 * 1000 + bcd & 0xf * 100;
+ bcd = fwData.readUInt8(0);
+ build = build + bcd >>> 4 * 10 + bcd & 0xf;
+ this._firmwareVersion = `${major}.${minor}.${bugFix}.${build}`;
}
}
@@ -238,7 +251,17 @@ export class LPF2Hub extends Hub {
private _parseSensorMessage (data: Buffer) {
- if ((data[3] === 0x3b && this.type === Consts.HubType.POWERED_UP_REMOTE) || (data[3] === 0x3c && this.type !== Consts.HubType.POWERED_UP_REMOTE)) { // Voltage
+ if ((data[3] === 0x3b && this.type === Consts.HubType.POWERED_UP_REMOTE)) { // Voltage (PUP Remote)
+ data = this._padMessage(data, 6);
+ const batteryLevel = data.readUInt16LE(4) / 500;
+ this._batteryLevel = Math.floor(batteryLevel);
+ return;
+ } else if (data[3] === 0x3c && this.type === Consts.HubType.POWERED_UP_REMOTE) { // Current (PUP Remote)
+ data = this._padMessage(data, 6);
+ const current = data.readUInt16LE(4) / 1000;
+ this._current = current;
+ return;
+ } else if (data[3] === 0x3c && this.type !== Consts.HubType.POWERED_UP_REMOTE) { // Voltage (Non-PUP Remote)
data = this._padMessage(data, 6);
const batteryLevel = data.readUInt16LE(4) / 400;
this._batteryLevel = Math.floor(batteryLevel);
@@ -248,11 +271,6 @@ export class LPF2Hub extends Hub {
const current = data.readUInt16LE(4) / 4096;
this._current = current * 100;
return;
- } else if (data[3] === 0x3c) { // Current (PUP Remote)
- data = this._padMessage(data, 6);
- const current = data.readUInt16LE(4) / 1000;
- this._current = current;
- return;
}
const port = this._getPortForPortNumber(data[3]);