adafruit / Adafruit_CircuitPython_VL53L1X

CircuitPython module for interacting with the VL53L1X distance sensor.
MIT License
8 stars 10 forks source link

Add range status check #8

Closed caternuson closed 2 years ago

caternuson commented 2 years ago

Simple fix for #7.

The distance will now return None if range status is anything other than "valid".

VL53L1X Simple Test.
--------------------
Model ID: 0xEA
Module Type: 0xCC
Mask Revision: 0x10
Distance Mode: SHORT
Timing Budget: 100
--------------------
Distance: None cm
Distance: None cm
Distance: None cm
Distance: None cm
Distance: 14.0 cm
Distance: 18.2 cm
Distance: 33.1 cm
Distance: 46.3 cm
Distance: 25.2 cm
Distance: 9.9 cm
Distance: None cm
Distance: None cm
Distance: None cm

For now, check is simple and hard coded. In the future, could expand this out to check for other fail modes and report them back in some manor. Note that the values defined for status:

image

are not the same value as the register. See mapping in switch statement here: https://github.com/adafruit/Adafruit_VL53L1X/blob/f2aaac89649823876451751a43cd1b036d65b22f/src/vl53l1x_class.cpp#L600-L644

That was used to determine that 0x09 register value is 0 range status, aka, VL53L1_RANGESTATUS_RANGE_VALID.