Skip to content

Commit

Permalink
ModulinoDistance: use range_status to understand if reading is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm committed Jun 10, 2024
1 parent ce2bb16 commit 495735c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Modulino.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class ModulinoDistance : public Module {
tof_sensor = new VL53L4CD((TwoWire*)getWire(), -1);
auto ret = tof_sensor->InitSensor();
if (ret == VL53L4CD_ERROR_NONE) {
tof_sensor->VL53L4CD_SetRangeTiming(200, 0);
tof_sensor->VL53L4CD_SetRangeTiming(20, 0);
tof_sensor->VL53L4CD_StartRanging();
return true;
} else {
Expand All @@ -412,7 +412,11 @@ class ModulinoDistance : public Module {
tof_sensor->VL53L4CD_ClearInterrupt();
tof_sensor->VL53L4CD_GetResult(&results);
}
return results.distance_mm;
if (results.range_status == 0) {
return results.distance_mm;
} else {
return NAN;
}
}
private:
VL53L4CD* tof_sensor = nullptr;
Expand Down

0 comments on commit 495735c

Please sign in to comment.