Fixed voltage and current on puphub

This commit is contained in:
Nathan Kellenicki 2018-08-14 09:12:55 +01:00
parent 75f35e4ef8
commit 17f638580c
2 changed files with 10 additions and 11 deletions

View File

@ -200,20 +200,19 @@ export class LPF2Hub extends Hub {
private _parseSensorMessage (data: Buffer) { 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); data = this._padMessage(data, 6);
let batteryLevel = (data.readUInt16LE(4) / 4096) * 100; const batteryLevel = (data.readUInt16LE(4) / 4096) * 100;
if (this.type === Consts.Hubs.POWERED_UP_REMOTE) {
batteryLevel = (100 / 5.1) * ((data.readUInt16LE(4) / 4096) * 100);
}
this._batteryLevel = Math.floor(batteryLevel); this._batteryLevel = Math.floor(batteryLevel);
return; 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); data = this._padMessage(data, 6);
let current = data.readUInt16LE(4) / 4096; const current = data.readUInt16LE(4) / 4096;
if (this.type === Consts.Hubs.POWERED_UP_REMOTE) { this._current = current;
current = data.readUInt16LE(4) / 1000000; return;
} } else if (data[3] === 0x3c) { // Current (PUP Remote)
data = this._padMessage(data, 6);
const current = data.readUInt16LE(4) / 1000;
this._current = current; this._current = current;
return; return;
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "node-poweredup", "name": "node-poweredup",
"version": "1.0.8", "version": "1.0.9",
"description": "A Node.js module to interface with LEGO Powered UP components.", "description": "A Node.js module to interface with LEGO Powered UP components.",
"homepage": "https://github.com/nathankellenicki/node-poweredup/", "homepage": "https://github.com/nathankellenicki/node-poweredup/",
"main": "dist/poweredup.js", "main": "dist/poweredup.js",