Skip to content

Commit 065e292

Browse files
committed
Reduce hard delay. Improve startup time for units that are already measuring.
1 parent 1db9c7b commit 065e292

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun VL53L1X 4m Laser Distance Sensor
2-
version=1.2.8
2+
version=1.2.9
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X

src/vl53l1x_class.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,28 +166,23 @@ VL53L1X_ERROR VL53L1X::VL53L1X_SetI2CAddress(uint8_t new_address)
166166
VL53L1X_ERROR VL53L1X::VL53L1X_SensorInit()
167167
{
168168
VL53L1X_ERROR status = 0;
169-
uint8_t Addr = 0x00, tmp = 0, timeout = 0;
169+
uint8_t Addr = 0x00, dataReady = 0, timeout = 0;
170170

171171
for (Addr = 0x2D; Addr <= 0x87; Addr++)
172172
{
173173
status = VL53L1_WrByte(Device, Addr, VL51L1X_DEFAULT_CONFIGURATION[Addr - 0x2D]);
174174
}
175175
status = VL53L1X_StartRanging();
176176

177-
delay(103); //Wait the default intermeasurement period of 103ms before checking for dataready
178-
179-
while (tmp == 0)
177+
//We need to wait at least the default intermeasurement period of 103ms before dataready will occur
178+
//But if a unit has already been powered and polling, it may happen much faster
179+
while (dataReady == 0)
180180
{
181-
status = VL53L1X_CheckForDataReady(&tmp);
182-
timeout++;
183-
if (timeout > 50)
184-
{
185-
status = VL53L1_ERROR_TIME_OUT;
186-
return status;
187-
}
181+
status = VL53L1X_CheckForDataReady(&dataReady);
182+
if (timeout++ > 150)
183+
return VL53L1_ERROR_TIME_OUT;
188184
delay(1);
189185
}
190-
tmp = 0;
191186
status = VL53L1X_ClearInterrupt();
192187
status = VL53L1X_StopRanging();
193188
status = VL53L1_WrByte(Device, VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */

0 commit comments

Comments
 (0)