Skip to content

Commit 495735c

Browse files
committed
ModulinoDistance: use range_status to understand if reading is correct
1 parent ce2bb16 commit 495735c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Modulino.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ class ModulinoDistance : public Module {
391391
tof_sensor = new VL53L4CD((TwoWire*)getWire(), -1);
392392
auto ret = tof_sensor->InitSensor();
393393
if (ret == VL53L4CD_ERROR_NONE) {
394-
tof_sensor->VL53L4CD_SetRangeTiming(200, 0);
394+
tof_sensor->VL53L4CD_SetRangeTiming(20, 0);
395395
tof_sensor->VL53L4CD_StartRanging();
396396
return true;
397397
} else {
@@ -412,7 +412,11 @@ class ModulinoDistance : public Module {
412412
tof_sensor->VL53L4CD_ClearInterrupt();
413413
tof_sensor->VL53L4CD_GetResult(&results);
414414
}
415-
return results.distance_mm;
415+
if (results.range_status == 0) {
416+
return results.distance_mm;
417+
} else {
418+
return NAN;
419+
}
416420
}
417421
private:
418422
VL53L4CD* tof_sensor = nullptr;

0 commit comments

Comments
 (0)