Skip to content

Commit

Permalink
Reduce hard delay. Improve startup time for units that are already me…
Browse files Browse the repository at this point in the history
…asuring.
  • Loading branch information
nseidle committed May 24, 2020
1 parent 1db9c7b commit 065e292
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun VL53L1X 4m Laser Distance Sensor
version=1.2.8
version=1.2.9
author=SparkFun Electronics <techsupport@sparkfun.com>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X
Expand Down
19 changes: 7 additions & 12 deletions src/vl53l1x_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,28 +166,23 @@ VL53L1X_ERROR VL53L1X::VL53L1X_SetI2CAddress(uint8_t new_address)
VL53L1X_ERROR VL53L1X::VL53L1X_SensorInit()
{
VL53L1X_ERROR status = 0;
uint8_t Addr = 0x00, tmp = 0, timeout = 0;
uint8_t Addr = 0x00, dataReady = 0, timeout = 0;

for (Addr = 0x2D; Addr <= 0x87; Addr++)
{
status = VL53L1_WrByte(Device, Addr, VL51L1X_DEFAULT_CONFIGURATION[Addr - 0x2D]);
}
status = VL53L1X_StartRanging();

delay(103); //Wait the default intermeasurement period of 103ms before checking for dataready

while (tmp == 0)
//We need to wait at least the default intermeasurement period of 103ms before dataready will occur
//But if a unit has already been powered and polling, it may happen much faster
while (dataReady == 0)
{
status = VL53L1X_CheckForDataReady(&tmp);
timeout++;
if (timeout > 50)
{
status = VL53L1_ERROR_TIME_OUT;
return status;
}
status = VL53L1X_CheckForDataReady(&dataReady);
if (timeout++ > 150)
return VL53L1_ERROR_TIME_OUT;
delay(1);
}
tmp = 0;
status = VL53L1X_ClearInterrupt();
status = VL53L1X_StopRanging();
status = VL53L1_WrByte(Device, VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */
Expand Down

0 comments on commit 065e292

Please sign in to comment.