File tree Expand file tree Collapse file tree 1 file changed +20
-7
lines changed Expand file tree Collapse file tree 1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -380,6 +380,22 @@ class ModulinoLight : public Module {
380
380
381
381
};
382
382
383
+ class Distance {
384
+ public:
385
+ Distance (int f) : internal(f) {}
386
+ operator int () {
387
+ return internal;
388
+ }
389
+ operator bool () {
390
+ return internal > 0 ;
391
+ }
392
+ bool isValid () {
393
+ return *this ;
394
+ }
395
+ private:
396
+ int internal;
397
+ };
398
+
383
399
class ModulinoDistance : public Module {
384
400
public:
385
401
bool begin () {
@@ -402,9 +418,9 @@ class ModulinoDistance : public Module {
402
418
operator bool () {
403
419
return (tof_sensor != nullptr );
404
420
}
405
- float get () {
421
+ Distance get () {
406
422
if (tof_sensor == nullptr ) {
407
- return NAN ;
423
+ return Distance (- 1 ) ;
408
424
}
409
425
uint8_t NewDataReady = 0 ;
410
426
uint8_t status = tof_sensor->VL53L4CD_CheckForDataReady (&NewDataReady);
@@ -413,14 +429,11 @@ class ModulinoDistance : public Module {
413
429
tof_sensor->VL53L4CD_GetResult (&results);
414
430
}
415
431
if (results.range_status == 0 ) {
416
- return results.distance_mm ;
432
+ return Distance ( results.distance_mm ) ;
417
433
} else {
418
- return NAN ;
434
+ return Distance (- 1 ) ;
419
435
}
420
436
}
421
- bool isValid (float distance) {
422
- return !isnan (distance);
423
- }
424
437
private:
425
438
VL53L4CD* tof_sensor = nullptr ;
426
439
VL53L4CD_Result_t results;
You can’t perform that action at this time.
0 commit comments