Fixed voltage and current on puphub
This commit is contained in:
parent
75f35e4ef8
commit
17f638580c
19
lpf2hub.ts
19
lpf2hub.ts
@ -200,20 +200,19 @@ export class LPF2Hub extends Hub {
|
||||
|
||||
private _parseSensorMessage (data: Buffer) {
|
||||
|
||||
if (data[3] === 0x3c) { // Voltage
|
||||
if ((data[3] === 0x3b && this.type === Consts.Hubs.POWERED_UP_REMOTE) || (data[3] === 0x3c && this.type !== Consts.Hubs.POWERED_UP_REMOTE)) { // Voltage
|
||||
data = this._padMessage(data, 6);
|
||||
let batteryLevel = (data.readUInt16LE(4) / 4096) * 100;
|
||||
if (this.type === Consts.Hubs.POWERED_UP_REMOTE) {
|
||||
batteryLevel = (100 / 5.1) * ((data.readUInt16LE(4) / 4096) * 100);
|
||||
}
|
||||
const batteryLevel = (data.readUInt16LE(4) / 4096) * 100;
|
||||
this._batteryLevel = Math.floor(batteryLevel);
|
||||
return;
|
||||
} else if (data[3] === 0x3b) { // Current
|
||||
} else if (data[3] === 0x3b && this.type !== Consts.Hubs.POWERED_UP_REMOTE) { // Current (Non-PUP Remote)
|
||||
data = this._padMessage(data, 6);
|
||||
let current = data.readUInt16LE(4) / 4096;
|
||||
if (this.type === Consts.Hubs.POWERED_UP_REMOTE) {
|
||||
current = data.readUInt16LE(4) / 1000000;
|
||||
}
|
||||
const current = data.readUInt16LE(4) / 4096;
|
||||
this._current = current;
|
||||
return;
|
||||
} else if (data[3] === 0x3c) { // Current (PUP Remote)
|
||||
data = this._padMessage(data, 6);
|
||||
const current = data.readUInt16LE(4) / 1000;
|
||||
this._current = current;
|
||||
return;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-poweredup",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.9",
|
||||
"description": "A Node.js module to interface with LEGO Powered UP components.",
|
||||
"homepage": "https://github.com/nathankellenicki/node-poweredup/",
|
||||
"main": "dist/poweredup.js",
|
||||
|
Loading…
x
Reference in New Issue
Block a user