From 63eb78df8d727b22134c26e83ef1a22afc3ae4c8 Mon Sep 17 00:00:00 2001
From: Fabrizio Monti <fabrizio.monti@skywarder.eu>
Date: Mon, 18 Mar 2024 22:06:17 +0100
Subject: [PATCH] [VN100-SPI] Added self test.

---
 src/shared/sensors/VN100/VN100Spi.cpp | 8 +++++++-
 src/tests/sensors/test-vn100-spi.cpp  | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/shared/sensors/VN100/VN100Spi.cpp b/src/shared/sensors/VN100/VN100Spi.cpp
index 752eda5fe..73b37a900 100644
--- a/src/shared/sensors/VN100/VN100Spi.cpp
+++ b/src/shared/sensors/VN100/VN100Spi.cpp
@@ -104,7 +104,13 @@ void VN100Spi::sendDummyPacket()
 
 bool VN100Spi::selfTest()
 {
-    // TODO
+    D(assert(isInit && "init() was not called"));
+
+    if (!checkModelNumber())
+    {
+        lastError = SensorErrors::SELF_TEST_FAIL;
+        return false;
+    }
 
     return true;
 }
diff --git a/src/tests/sensors/test-vn100-spi.cpp b/src/tests/sensors/test-vn100-spi.cpp
index 4334c78f5..c94d91c29 100644
--- a/src/tests/sensors/test-vn100-spi.cpp
+++ b/src/tests/sensors/test-vn100-spi.cpp
@@ -60,9 +60,15 @@ int main()
     }
     printf("Sensor initialized\n");
 
+    if (!sensor.selfTest())
+    {
+        printf("Error while performing self test\n\n");
+        return 0;
+    }
+    printf("Self test successful\n");
+
     for (int i = 0; i < 100; ++i)
     {
-        // AccelerometerData data = sensor.readAcc();
         sensor.sample();
         VN100Data sample = sensor.getLastSample();
 
-- 
GitLab