Skip to content

Commit

Permalink
change colordistancesensor distance calculation
Browse files Browse the repository at this point in the history
ignores inaccurate distance values for small distances and
avoids negative values for distance=0 and partial >0
  • Loading branch information
Debenben committed Jan 9, 2022
1 parent 4bfa4d1 commit 7782d64
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/devices/colordistancesensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7782d64

Please sign in to comment.