From c7a5efcc7817e17bd3ad7507b1221d14fb27f62e Mon Sep 17 00:00:00 2001 From: Michal Szafranski Date: Sat, 2 Nov 2019 12:01:41 +0100 Subject: [PATCH 1/2] Fix and simplify tilt sensor reading --- src/lpf2hub.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lpf2hub.ts b/src/lpf2hub.ts index 28cb7dd..ed73a15 100644 --- a/src/lpf2hub.ts +++ b/src/lpf2hub.ts @@ -496,8 +496,8 @@ export class LPF2Hub extends Hub { break; } case Consts.DeviceType.WEDO2_TILT: { - const tiltX = data[4] > 160 ? data[4] - 255 : data[4] - (data[4] * 2); - const tiltY = data[5] > 160 ? 255 - data[5] : data[5] - (data[5] * 2); + const tiltX = data.readInt8(4); + const tiltY = data.readInt8(5); this._lastTiltX = tiltX; this._lastTiltY = tiltY; /** @@ -538,8 +538,8 @@ export class LPF2Hub extends Hub { break; } case Consts.DeviceType.BOOST_TILT: { - const tiltX = data[4] > 160 ? data[4] - 255 : data[4]; - const tiltY = data[5] > 160 ? 255 - data[5] : data[5] - (data[5] * 2); + const tiltX = data.readInt8(4); + const tiltY = data.readInt8(5); this._lastTiltX = tiltX; this._lastTiltY = tiltY; this.emit("tilt", port.id, this._lastTiltX, this._lastTiltY, this._lastTiltZ); From 00e6840c3247f3c72f4c79a971e7052076e0378f Mon Sep 17 00:00:00 2001 From: Michal Szafranski Date: Sun, 3 Nov 2019 09:51:06 +0100 Subject: [PATCH 2/2] fix tilt sensor readout in wedo hub as well --- src/wedo2smarthub.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/wedo2smarthub.ts b/src/wedo2smarthub.ts index 143c6cf..ab2af91 100644 --- a/src/wedo2smarthub.ts +++ b/src/wedo2smarthub.ts @@ -419,14 +419,8 @@ export class WeDo2SmartHub extends Hub { break; } case Consts.DeviceType.WEDO2_TILT: { - this._lastTiltX = data[2]; - if (this._lastTiltX > 100) { - this._lastTiltX = -(255 - this._lastTiltX); - } - this._lastTiltY = data[3]; - if (this._lastTiltY > 100) { - this._lastTiltY = -(255 - this._lastTiltY); - } + this._lastTiltX = data.readInt8(2); + this._lastTiltY = data.readInt8(3); /** * Emits when a tilt sensor is activated. * @event WeDo2SmartHub#tilt