From 7782d6400328b54e62cfe3b241e07def7bb2a216 Mon Sep 17 00:00:00 2001 From: bene Date: Sun, 9 Jan 2022 16:32:55 +0100 Subject: [PATCH] change colordistancesensor distance calculation ignores inaccurate distance values for small distances and avoids negative values for distance=0 and partial >0 --- src/devices/colordistancesensor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/colordistancesensor.ts b/src/devices/colordistancesensor.ts index fc3e85f..b4dd6dd 100644 --- a/src/devices/colordistancesensor.ts +++ b/src/devices/colordistancesensor.ts @@ -63,10 +63,10 @@ export class ColorDistanceSensor extends Device { const partial = message[7]; if (partial > 0) { - distance += 1.0 / partial; + distance = 1.0 / partial; } - distance = Math.floor(distance * 25.4) - 20; + distance = Math.floor(distance * 25.4); /** * A combined color and distance event, emits when the sensor is activated.