From 36c99ec285469606adc91f1ec36a2fcb6718a8e3 Mon Sep 17 00:00:00 2001
From: Lorenzo Cucchi <lorenzo.cucchi@skywarder.eu>
Date: Fri, 23 Jun 2023 23:31:46 +0200
Subject: [PATCH] [VN300] Fixed mutex that was locking for the duration of a
 whole sample.

---
 src/shared/sensors/VN300/VN300.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/shared/sensors/VN300/VN300.cpp b/src/shared/sensors/VN300/VN300.cpp
index ca802bd5e..b92d3e621 100644
--- a/src/shared/sensors/VN300/VN300.cpp
+++ b/src/shared/sensors/VN300/VN300.cpp
@@ -163,16 +163,19 @@ bool VN300::init()
 
 void VN300::run()
 {
-    while (!shouldStop())
+     while (!shouldStop())
     {
         long long initialTime = miosix::getTick();
+
+        VN300Data data = sampleData();
         {
             // Sample the data locking the mutex
             miosix::Lock<FastMutex> l(mutex);
-            threadSample = sampleData();
+            threadSample = data;
         }
         // Sleep for the sampling period
         miosix::Thread::sleepUntil(initialTime + samplePeriod);
+        printf("Sample time: %lld\n", miosix::getTick() - initialTime);
     }
 }
 
-- 
GitLab