From 6893f05a904dff8c645e4c8f23cac8c71c9df03c Mon Sep 17 00:00:00 2001 From: Bilal Hassan <bilal.hassan@student.uibk.ac.at> Date: Thu, 27 Oct 2022 17:44:51 +0200 Subject: [PATCH] update on analog drs26 lib --- client/client/.vscode/settings.json | 5 ++++ client/client/lib/dr26_analogue/dr26.cpp | 38 ++++++++++++++---------- client/client/lib/dr26_analogue/dr26.hpp | 1 + client/client/src/main.cpp | 21 +++++++++---- 4 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 client/client/.vscode/settings.json diff --git a/client/client/.vscode/settings.json b/client/client/.vscode/settings.json new file mode 100644 index 0000000..f2678ea --- /dev/null +++ b/client/client/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "optional": "cpp" + } +} \ No newline at end of file diff --git a/client/client/lib/dr26_analogue/dr26.cpp b/client/client/lib/dr26_analogue/dr26.cpp index 5521e8a..b9b4d26 100644 --- a/client/client/lib/dr26_analogue/dr26.cpp +++ b/client/client/lib/dr26_analogue/dr26.cpp @@ -2,26 +2,32 @@ void ForteDR26 ::setup() { - Wire.begin(I2C_SDA, I2C_SCL); - // ads.setGain(0); - if (ads.begin()) { - ESP_LOGI(sensorInformation.getSensorName().c_str(), "ADS initialized."); - } else { - ESP_LOGW(sensorInformation.getSensorName().c_str(), "ADS initialization failed."); - } - delay(100); + Wire.begin(6, 7); + ads.setGain(GAIN_ONE); + ads.begin() ? Serial.println("ADS initialized") : Serial.println("failed to initialize ADS"); + delay(100); } float ForteDR26 ::readData() { - float volts = 0; - for (int i = 0; i < 10; i++) { - int16_t adc = ads.readADC_SingleEnded(0); - float volt = ads.computeVolts(adc); - volts += volt; - } - volts /= 10; - return volts; + float volts=0; + for(int i=0; i<10; i++){ + int16_t adc = 0; + float volt = 0; + try + { + adc = ads.readADC_SingleEnded(0); + volt = ads.computeVolts(adc); + } + catch(NoDataAvailableException& e) + { + throw NoDataAvailableException(); //propagate exception + } + volts += volt; + } + + volts /= 10; + return volts; } // The following functions change the ADC input range: be careful diff --git a/client/client/lib/dr26_analogue/dr26.hpp b/client/client/lib/dr26_analogue/dr26.hpp index 778f8fe..7d259b8 100644 --- a/client/client/lib/dr26_analogue/dr26.hpp +++ b/client/client/lib/dr26_analogue/dr26.hpp @@ -7,6 +7,7 @@ #include "Pinout.hpp" #include "esp_log.h" #include <Wire.h> +#include "NoDataAvailableException.hpp" class ForteDR26 : public ForteSensor<float> { public: diff --git a/client/client/src/main.cpp b/client/client/src/main.cpp index c03886c..ce27aa4 100644 --- a/client/client/src/main.cpp +++ b/client/client/src/main.cpp @@ -10,8 +10,8 @@ // #include "esp32-hal-log.h" static const std::string TAG = "MAIN"; -ForteDRS26 drs26; +ForteDR26 dr26; void setup() { Serial.begin(115200); @@ -20,17 +20,27 @@ void setup() DeepSleep::bootCount++; ESP_LOGD(TAG.c_str(), "Boot number: %d", DeepSleep::bootCount); - drs26.setup(); +// drs26.setup(); + dr26.setup(); espnow_setup(); - // log_e("Setup complete."); } void loop() { + float data= dr26.readData(); + Serial.printf("data circumfrence"); + Serial.printf(String(dr26.readData()).c_str()); + try { - auto messages = drs26.buildMessages(); + // out_data_drs26 data= dr26.readData(); + // Serial.printf("data circumfrence"); + // Serial.printf(String( data.circumferenceIncrement).c_str()); + //auto messages = drs26.buildMessages(); + auto messages = dr26.buildMessages(); + + // auto scdMessages = scd30.buildmessages(); for (const Message &message : messages) { if(message.send() != ESP_OK){ @@ -51,7 +61,8 @@ void loop() // log_e("Id: "); Serial.print("This device: "); - Serial.println(WiFi.macAddress()); + +// Serial.println(WiFi.macAddress()); Serial.println("\n"); delay(10000); DeepSleep::deep_sleep(5); -- GitLab