Skip to content

Commit 9d3e0e4

Browse files
author
Andrew England
committed
adding timeout to sensorInit function
1 parent 4de6811 commit 9d3e0e4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
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.2
2+
version=1.2.3
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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,20 @@ VL53L1X_ERROR VL53L1X::VL53L1X_SetI2CAddress(uint8_t new_address)
173173
VL53L1X_ERROR VL53L1X::VL53L1X_SensorInit()
174174
{
175175
VL53L1X_ERROR status = 0;
176-
uint8_t Addr = 0x00, tmp=0;
176+
uint8_t Addr = 0x00, tmp=0, timeout = 0;
177177

178178
for (Addr = 0x2D; Addr <= 0x87; Addr++){
179179
status = VL53L1_WrByte(Device, Addr, VL51L1X_DEFAULT_CONFIGURATION[Addr - 0x2D]);
180180
}
181181
status = VL53L1X_StartRanging();
182182
while(tmp==0){
183-
status = VL53L1X_CheckForDataReady(&tmp);
183+
status = VL53L1X_CheckForDataReady(&tmp);
184+
timeout++;
185+
if (timeout > 50)
186+
{
187+
status = VL53L1_ERROR_TIME_OUT;
188+
return status;
189+
}
184190
}
185191
tmp = 0;
186192
status = VL53L1X_ClearInterrupt();

0 commit comments

Comments
 (0)