Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 08d2495

Browse files
committed
ModulinoDistance: add available() API
available() returns true is the distance is retrieved and is valid; get() returns now the last value read.
1 parent 84c98f3 commit 08d2495

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

‎src/Modulino.h‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,26 +412,29 @@ class ModulinoDistance : public Module {
412412
operator bool() {
413413
return (tof_sensor != nullptr);
414414
}
415-
floatget() {
415+
boolavailable() {
416416
if (tof_sensor == nullptr) {
417-
return NAN;
417+
return false;
418418
}
419+
float ret = internal;
419420
uint8_t NewDataReady = 0;
420421
tof_sensor->VL53L4CD_CheckForDataReady(&NewDataReady);
421422
if (NewDataReady) {
422423
tof_sensor->VL53L4CD_ClearInterrupt();
423424
tof_sensor->VL53L4CD_GetResult(&results);
424425
}
425426
if (results.range_status == 0) {
426-
return results.distance_mm;
427+
internal = results.distance_mm;
427428
} else {
428-
return NAN;
429+
internal = NAN;
429430
}
431+
return !isnan(internal);
430432
}
431-
boolisValid(float distance) {
432-
return !isnan(distance);
433+
float get() {
434+
return internal;
433435
}
434436
private:
435437
VL53L4CD* tof_sensor = nullptr;
436438
VL53L4CD_Result_t results;
439+
float internal = NAN;
437440
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /