@@ -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 (10 , 0 );
394+ tof_sensor->VL53L4CD_SetRangeTiming (200 , 0 );
395395 tof_sensor->VL53L4CD_StartRanging ();
396396 return true ;
397397 } else {
@@ -406,16 +406,15 @@ class ModulinoDistance : public Module {
406406 if (tof_sensor == nullptr ) {
407407 return NAN;
408408 }
409- VL53L4CD_Result_t results;
410409 uint8_t NewDataReady = 0 ;
411- uint8_t status;
412- do {
413- status = tof_sensor->VL53L4CD_CheckForDataReady (&NewDataReady);
414- } while (!NewDataReady);
415- tof_sensor->VL53L4CD_ClearInterrupt ();
416- tof_sensor->VL53L4CD_GetResult (&results);
410+ uint8_t status = tof_sensor->VL53L4CD_CheckForDataReady (&NewDataReady);
411+ if (NewDataReady) {
412+ tof_sensor->VL53L4CD_ClearInterrupt ();
413+ tof_sensor->VL53L4CD_GetResult (&results);
414+ }
417415 return results.distance_mm ;
418416 }
419417private:
420418 VL53L4CD* tof_sensor = nullptr ;
419+ VL53L4CD_Result_t results;
421420};
0 commit comments