From f732e580afd082f9d6c4f9b9ecfe597367a8fc85 Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Tue, 12 Jun 2018 22:36:13 +0100 Subject: [PATCH] Better distance calculation --- boosthub.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/boosthub.js b/boosthub.js index 00770e2..098e760 100644 --- a/boosthub.js +++ b/boosthub.js @@ -203,20 +203,14 @@ class BoostHub extends Hub { this.emit("color", port.id, data[4]); - let distance; - if (data[7] > 0 && data[5] < 2) { - distance = Math.floor(20 - (data[7] * 2.85)); - } else if (data[5] > 9) { - distance = 10; - } else { - distance = Math.floor((20 + (data[5] * 18))); - } + let distance = data[5], + partial = data[7]; - if (distance > 130) { - distance = 130; + if (partial > 0) { + distance += 1 / partial; } - this.emit("distance", port.id, distance); + this.emit("distance", port.id, distance * 25.4); break; } case Consts.Devices.WEDO2_TILT: