adafruit/Adafruit_CircuitPython_VL53L1X

wants : change for three distance modes

halcyon1945 opened this issue · 4 comments

Hi,
this issue is feature request .

VL53L1X chip datasheet say distance_mode has three enums.
short,middle and long.
but this library set only two. short and long.

@property
def distance_mode(self):
"""The distance mode. 1=short, 2=long."""
mode = self._read_register(_PHASECAL_CONFIG__TIMEOUT_MACROP)[0]
if mode == 0x14:
return 1 # short distance
if mode == 0x0A:
return 2 # long distance
return None # unknown
@distance_mode.setter
def distance_mode(self, mode):
if mode == 1:
# short distance
self._write_register(_PHASECAL_CONFIG__TIMEOUT_MACROP, b"\x14")
self._write_register(_RANGE_CONFIG__VCSEL_PERIOD_A, b"\x07")
self._write_register(_RANGE_CONFIG__VCSEL_PERIOD_B, b"\x05")
self._write_register(_RANGE_CONFIG__VALID_PHASE_HIGH, b"\x38")
self._write_register(_SD_CONFIG__WOI_SD0, b"\x07\x05")
self._write_register(_SD_CONFIG__INITIAL_PHASE_SD0, b"\x06\x06")
elif mode == 2:
# long distance
self._write_register(_PHASECAL_CONFIG__TIMEOUT_MACROP, b"\x0A")
self._write_register(_RANGE_CONFIG__VCSEL_PERIOD_A, b"\x0F")
self._write_register(_RANGE_CONFIG__VCSEL_PERIOD_B, b"\x0D")
self._write_register(_RANGE_CONFIG__VALID_PHASE_HIGH, b"\xB8")
self._write_register(_SD_CONFIG__WOI_SD0, b"\x0F\x0D")
self._write_register(_SD_CONFIG__INITIAL_PHASE_SD0, b"\x0E\x0E")
else:
raise ValueError("Unsupported mode.")

could your change for three mode?

see this datasheet and section 2.5.1 Distance mode.
https://www.st.com/resource/en/datasheet/vl53l1x.pdf

thanks.

Unfortunately, ST does not provide register details in their datasheet. This CircuitPython library was written based on ST's Arduino library here:
https://github.com/stm32duino/VL53L1X
and that library only has code for setting two distance modes:
https://github.com/stm32duino/VL53L1X/blob/5aa46e743913186c448aaf86dd0f12071fddc0a2/src/vl53l1x_class.cpp#L420-L451

If you have a source for more information on how the Medium distance mode can be set, please link here and we can take a look.

i got it.

i did download and unzip ST official API called "VL53L1X Full API "
https://www.st.com/en/embedded-software/stsw-img007.html

and checked
API/core/src/vl53l1_api.c
around L:996 function is similar.

VL53L1_Error VL53L1_SetDistanceMode(VL53L1_DEV Dev,
		VL53L1_DistanceModes DistanceMode)

VL53L1_DistanceModes definition.

/** @defgroup VL53L1_define_DistanceModes_group Defines Distance modes
 *  Defines all possible Distance modes for the device
 *  @{
 */
typedef uint8_t VL53L1_DistanceModes;

#define VL53L1_DISTANCEMODE_SHORT             ((VL53L1_DistanceModes)  1)
#define VL53L1_DISTANCEMODE_MEDIUM            ((VL53L1_DistanceModes)  2)
#define VL53L1_DISTANCEMODE_LONG              ((VL53L1_DistanceModes)  3)
/** @} VL53L1_define_DistanceModes_group */

and another way ....
it seems pololu deal with this issue.
https://github.com/pololu/vl53l1x-arduino/blob/8f21d608af00b42dc8776cfdf5ce935b45d2387d/VL53L1X.cpp#L272

Ugh. They require email validation to access the "full" API.

Will take a look at the pololu code. The timing budget settings are affected by distance mode. So will need to verify what is needed there for "medium" mode.

memo :
Current (tag 1.1.6) lib can be set to short and long . It just doesn't have medium , which I don't use much.
I thought it was short and medium because the enum is 1 and 2. (ST doc said 1 as short, 2 as medium ,3 as long)