diff --git a/src/lpf2hub.ts b/src/lpf2hub.ts index f61bf5a..ee8e583 100644 --- a/src/lpf2hub.ts +++ b/src/lpf2hub.ts @@ -498,8 +498,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; /** @@ -540,8 +540,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); diff --git a/src/wedo2smarthub.ts b/src/wedo2smarthub.ts index 8084d44..1e7ecb7 100644 --- a/src/wedo2smarthub.ts +++ b/src/wedo2smarthub.ts @@ -420,14 +420,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