Skip to content

Commit 37a3984

Browse files
committed
ModulinoDistance: get() returns previous reading, add available() for validity
1 parent 95ec7f6 commit 37a3984

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Modulino.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,22 +406,25 @@ class ModulinoDistance : public Module {
406406
if (tof_sensor == nullptr) {
407407
return NAN;
408408
}
409+
float ret = internal;
409410
uint8_t NewDataReady = 0;
410411
uint8_t status = tof_sensor->VL53L4CD_CheckForDataReady(&NewDataReady);
411412
if (NewDataReady) {
412413
tof_sensor->VL53L4CD_ClearInterrupt();
413414
tof_sensor->VL53L4CD_GetResult(&results);
414415
}
415416
if (results.range_status == 0) {
416-
return results.distance_mm;
417+
internal = results.distance_mm;
417418
} else {
418-
return NAN;
419+
internal = NAN;
419420
}
421+
return ret;
420422
}
421-
bool isValid(float distance) {
422-
return !isnan(distance);
423+
bool available() {
424+
return !isnan(internal);
423425
}
424426
private:
425427
VL53L4CD* tof_sensor = nullptr;
426428
VL53L4CD_Result_t results;
429+
float internal;
427430
};

0 commit comments

Comments
 (0)