From c26b689db43e53a1ee1f568273f66f8bc348d09b Mon Sep 17 00:00:00 2001
From: Bilal Hassan <bilal.hassan@student.uibk.ac.at>
Date: Thu, 18 Aug 2022 09:58:01 +0200
Subject: [PATCH] adding the missing libary folder

---
 client/client/lib/drs26_digital/drs26.cpp     | 42 +++++++++++++++++++
 client/client/lib/drs26_digital/drs26.hpp     | 27 ++++++++++++
 .../client/lib/drs26_digital/forte_sensor.hpp | 13 ++++++
 client/client/lib/drs26_digital/pinout.hpp    |  6 +++
 client/client/lib/ina219/forte_sensor.hpp     | 13 ++++++
 client/client/lib/ina219/ina219.cpp           | 26 ++++++++++++
 client/client/lib/ina219/ina219.hpp           | 31 ++++++++++++++
 client/client/lib/ina219/pinout.hpp           |  8 ++++
 client/client/lib/scd30/forte_sensor.hpp      | 13 ++++++
 client/client/lib/scd30/pinout.hpp            |  8 ++++
 10 files changed, 187 insertions(+)
 create mode 100644 client/client/lib/drs26_digital/drs26.cpp
 create mode 100644 client/client/lib/drs26_digital/drs26.hpp
 create mode 100644 client/client/lib/drs26_digital/forte_sensor.hpp
 create mode 100644 client/client/lib/drs26_digital/pinout.hpp
 create mode 100644 client/client/lib/ina219/forte_sensor.hpp
 create mode 100644 client/client/lib/ina219/ina219.cpp
 create mode 100644 client/client/lib/ina219/ina219.hpp
 create mode 100644 client/client/lib/ina219/pinout.hpp
 create mode 100644 client/client/lib/scd30/forte_sensor.hpp
 create mode 100644 client/client/lib/scd30/pinout.hpp

diff --git a/client/client/lib/drs26_digital/drs26.cpp b/client/client/lib/drs26_digital/drs26.cpp
new file mode 100644
index 0000000..4c3378a
--- /dev/null
+++ b/client/client/lib/drs26_digital/drs26.cpp
@@ -0,0 +1,42 @@
+#include <drs26.hpp>
+/*
+It happens for some reason that the sensor cant get reached every 2 time
+Because the sensor use sdi12 protocoll we have to wait aproxemettly 1 secound between the commands
+It is not known how lond the response takes so we use a while loop which can be a risk wehre the programm can get stuck 
+*/
+
+void Forte_DRS26 ::setup()
+{
+    drs26.begin(SDI_DATA);
+}
+
+out_data_drs26 *Forte_DRS26 ::read_data()
+{
+    String sdiResponse = "";
+    String measurement_command="1M!"; //The drs26 sensor uses the sdi12 protocoll , in the sdi12 protocoll is the measurement command is specified as 1M!=Sebsir measurement request at adress 1
+    String data_command="1D0!";       //and the followed data command 1D0! = Sensor data request at adress 1 
+
+    drs26.sendCommand(measurement_command);
+    delay(1000);
+    drs26.sendCommand(data_command);
+
+    while (drs26.available())
+    {
+        char next_character = drs26.read();
+        if ((next_character != '\n') && (next_character != '\r'))
+        {
+            sdiResponse += next_character;
+            delay(10); // 1 character ~ 7.5ms
+        }
+    }
+
+    if (sdiResponse.length() > 1)
+    {
+        data.id = sdiResponse.substring(0, 8).toInt();
+        data.circumference = sdiResponse.substring(9, 15).toFloat();
+        data.temperatur = sdiResponse.substring(16, 22).toFloat();
+        return &data;
+    }
+
+    return 0;
+}
\ No newline at end of file
diff --git a/client/client/lib/drs26_digital/drs26.hpp b/client/client/lib/drs26_digital/drs26.hpp
new file mode 100644
index 0000000..83d02ae
--- /dev/null
+++ b/client/client/lib/drs26_digital/drs26.hpp
@@ -0,0 +1,27 @@
+#ifndef _DRS26
+#define _DRS26
+
+#include <forte_sensor.hpp>
+#include <SDI12.h>
+#include <pinout.hpp>
+#include "Wire.h"
+
+     
+struct out_data_drs26 {
+        int id;
+        float circumference;
+        float temperatur;
+    };
+
+
+class Forte_DRS26 : public Forte_Sensor{
+    public:
+        void setup();
+        out_data_drs26* read_data();
+ 
+    private:
+        SDI12 drs26;
+        out_data_drs26 data; 
+};
+
+#endif
\ No newline at end of file
diff --git a/client/client/lib/drs26_digital/forte_sensor.hpp b/client/client/lib/drs26_digital/forte_sensor.hpp
new file mode 100644
index 0000000..8e030b9
--- /dev/null
+++ b/client/client/lib/drs26_digital/forte_sensor.hpp
@@ -0,0 +1,13 @@
+#ifndef _FORTE_SENSOR
+#define _FORTE_SENSOR
+
+class Forte_Sensor {
+    public:
+        virtual void* read_data() = 0;
+        virtual void setup() = 0;
+
+    private:
+
+};
+
+#endif
\ No newline at end of file
diff --git a/client/client/lib/drs26_digital/pinout.hpp b/client/client/lib/drs26_digital/pinout.hpp
new file mode 100644
index 0000000..5ac8641
--- /dev/null
+++ b/client/client/lib/drs26_digital/pinout.hpp
@@ -0,0 +1,6 @@
+#ifndef _FORTE_PINOUT
+#define _FORTE_PINOUT
+
+// Pins for SDI12 
+#define SDI_DATA 8
+#endif
\ No newline at end of file
diff --git a/client/client/lib/ina219/forte_sensor.hpp b/client/client/lib/ina219/forte_sensor.hpp
new file mode 100644
index 0000000..8e030b9
--- /dev/null
+++ b/client/client/lib/ina219/forte_sensor.hpp
@@ -0,0 +1,13 @@
+#ifndef _FORTE_SENSOR
+#define _FORTE_SENSOR
+
+class Forte_Sensor {
+    public:
+        virtual void* read_data() = 0;
+        virtual void setup() = 0;
+
+    private:
+
+};
+
+#endif
\ No newline at end of file
diff --git a/client/client/lib/ina219/ina219.cpp b/client/client/lib/ina219/ina219.cpp
new file mode 100644
index 0000000..7f4beb3
--- /dev/null
+++ b/client/client/lib/ina219/ina219.cpp
@@ -0,0 +1,26 @@
+#include "ina219.hpp"
+
+
+void Forte_INA219 :: setup(){
+    Wire.begin(I2C_SDA, I2C_SCL);
+     if(!ina219.init()){
+        // Sensor init went wrong
+        return;
+    } 
+}
+
+out_data_ina219* Forte_INA219  :: read_data(){
+    if(!ina219.getOverflow())
+    {
+        data.shuntVoltage_mV = ina219.getShuntVoltage_mV();
+        data.busVoltage_V= ina219.getBusVoltage_V();
+        data.current_mA= ina219.getCurrent_mA();
+        data.power_mW= ina219.getBusPower();
+        data.loadVoltage_V = data.busVoltage_V + (data.shuntVoltage_mV/1000);
+        data.ina219_overflow=ina219.getOverflow();
+        
+        return &data;
+    }
+    else
+        return 0;
+}
\ No newline at end of file
diff --git a/client/client/lib/ina219/ina219.hpp b/client/client/lib/ina219/ina219.hpp
new file mode 100644
index 0000000..a975ba5
--- /dev/null
+++ b/client/client/lib/ina219/ina219.hpp
@@ -0,0 +1,31 @@
+#ifndef _INA219
+#define _INA219
+
+#include <forte_sensor.hpp>
+#include <pinout.hpp>
+#include <INA219_WE.h>
+#include "Wire.h"
+
+
+     
+struct out_data_ina219 {
+        float shuntVoltage_mV = 0.0;
+        float loadVoltage_V = 0.0;
+        float busVoltage_V = 0.0;
+        float current_mA = 0.0;
+        float power_mW = 0.0; 
+        bool ina219_overflow = false;  
+    };
+
+
+class Forte_INA219 : public Forte_Sensor{
+    public:
+        void setup();
+        out_data_ina219* read_data();
+ 
+    private:
+        INA219_WE ina219;
+        out_data_ina219 data; 
+};
+
+#endif
\ No newline at end of file
diff --git a/client/client/lib/ina219/pinout.hpp b/client/client/lib/ina219/pinout.hpp
new file mode 100644
index 0000000..9d336e4
--- /dev/null
+++ b/client/client/lib/ina219/pinout.hpp
@@ -0,0 +1,8 @@
+#ifndef _FORTE_PINOUT
+#define _FORTE_PINOUT
+
+// Pins for I2C
+#define I2C_SDA 5
+#define I2C_SCL 4
+
+#endif
\ No newline at end of file
diff --git a/client/client/lib/scd30/forte_sensor.hpp b/client/client/lib/scd30/forte_sensor.hpp
new file mode 100644
index 0000000..8e030b9
--- /dev/null
+++ b/client/client/lib/scd30/forte_sensor.hpp
@@ -0,0 +1,13 @@
+#ifndef _FORTE_SENSOR
+#define _FORTE_SENSOR
+
+class Forte_Sensor {
+    public:
+        virtual void* read_data() = 0;
+        virtual void setup() = 0;
+
+    private:
+
+};
+
+#endif
\ No newline at end of file
diff --git a/client/client/lib/scd30/pinout.hpp b/client/client/lib/scd30/pinout.hpp
new file mode 100644
index 0000000..9a9ad92
--- /dev/null
+++ b/client/client/lib/scd30/pinout.hpp
@@ -0,0 +1,8 @@
+#ifndef _FORTE_PINOUT
+#define _FORTE_PINOUT
+
+// Pins for I2C
+#define I2C_SDA 18
+#define I2C_SCL 19
+
+#endif
\ No newline at end of file
-- 
GitLab