File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -424,4 +424,52 @@ class ModulinoDistance : public Module {
424
424
private:
425
425
VL53L4CD* tof_sensor = nullptr ;
426
426
VL53L4CD_Result_t results;
427
+ };
428
+
429
+ #include < vl53l1x_class.h> // from stm32duino
430
+
431
+ class ModulinoLongDistance : public Module {
432
+ public:
433
+ bool begin () {
434
+ // try scanning for 0x29 since the library contains a while(true) on begin()
435
+ getWire ()->beginTransmission (0x29 );
436
+ if (getWire ()->endTransmission () != 0 ) {
437
+ return false ;
438
+ }
439
+ tof_sensor = new VL53L1X ((TwoWire*)getWire (), -1 );
440
+ auto ret = tof_sensor->InitSensor (VL53L1X_DEFAULT_DEVICE_ADDRESS);
441
+ if (ret == VL53L1X_ERROR_NONE) {
442
+ tof_sensor->VL53L1X_SetDistanceMode (2 );
443
+ tof_sensor->VL53L1X_SetTimingBudgetInMs (10 );
444
+ tof_sensor->VL53L1X_StartRanging ();
445
+ return true ;
446
+ } else {
447
+ tof_sensor = nullptr ;
448
+ return false ;
449
+ }
450
+ }
451
+ operator bool () {
452
+ return (tof_sensor != nullptr );
453
+ }
454
+ float get () {
455
+ if (tof_sensor == nullptr ) {
456
+ return NAN;
457
+ }
458
+ uint8_t NewDataReady = 0 ;
459
+ uint8_t status = tof_sensor->VL53L1X_CheckForDataReady (&NewDataReady);
460
+ if (NewDataReady) {
461
+ tof_sensor->VL53L1X_ClearInterrupt ();
462
+ status = tof_sensor->VL53L1X_GetDistance (&_distance);
463
+ if (status != VL53L1X_ERROR_NONE) {
464
+ return NAN;
465
+ }
466
+ }
467
+ return _distance;
468
+ }
469
+ bool isValid (float distance) {
470
+ return !isnan (distance);
471
+ }
472
+ private:
473
+ VL53L1X* tof_sensor = nullptr ;
474
+ uint16_t _distance;
427
475
};
You can’t perform that action at this time.
0 commit comments