From 336745f9f7d617a9bc88ffe29674386d0d308930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 19 Mar 2020 07:13:37 +0100 Subject: [PATCH] tfmini: reduce sampling rate from 10kHz to 143Hz 10kHz sampling seems excessive, given that the sensor is expected to output at 100Hz. Also don't reschedule immediately in case we have not received any data. --- src/drivers/distance_sensor/tfmini/TFMINI.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/drivers/distance_sensor/tfmini/TFMINI.cpp b/src/drivers/distance_sensor/tfmini/TFMINI.cpp index cefb74f2ab..ab69d110ce 100644 --- a/src/drivers/distance_sensor/tfmini/TFMINI.cpp +++ b/src/drivers/distance_sensor/tfmini/TFMINI.cpp @@ -168,7 +168,7 @@ TFMINI::collect() if (!bytes_available) { perf_end(_sample_perf); - return -EAGAIN; + return 0; } // parse entire buffer @@ -223,8 +223,8 @@ TFMINI::collect() void TFMINI::start() { - // schedule a cycle to start things - ScheduleOnInterval(100_us); + // schedule a cycle to start things (the sensor sends at 100Hz, but we run a bit faster to avoid missing data) + ScheduleOnInterval(7_ms); } void @@ -246,7 +246,7 @@ TFMINI::Run() if (collect() == -EAGAIN) { // reschedule to grab the missing bits, time to transmit 9 bytes @ 115200 bps ScheduleClear(); - ScheduleOnInterval(100_us, 87 * 9); + ScheduleOnInterval(7_ms, 87 * 9); return; } }