From 831db9e7b6aaf3913bddf107d296933f4847d086 Mon Sep 17 00:00:00 2001 From: Moreno Gasperini Date: Fri, 25 Oct 2024 09:42:38 +0200 Subject: [PATCH] Slave VWC Fix adc bug with calibrated ADC value check limit. Remove message ovweflow without sensor conection, only enabled with minimal measure value. --- platformio/stima_v4/slave-vwc/include/config.h | 4 +++- .../stima_v4/slave-vwc/src/tasks/soil_vwc_sensor_task.cpp | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/platformio/stima_v4/slave-vwc/include/config.h b/platformio/stima_v4/slave-vwc/include/config.h index 14fed7ec8..16d55b778 100644 --- a/platformio/stima_v4/slave-vwc/include/config.h +++ b/platformio/stima_v4/slave-vwc/include/config.h @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define MODULE_MAIN_VERSION (4) /// @brief Module minor version. -#define MODULE_MINOR_VERSION (2) +#define MODULE_MINOR_VERSION (3) /// @brief rmap protocol version #define RMAP_PROCOTOL_VERSION (1) @@ -226,6 +226,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define SOIL_VWC_VOLTAGE_MAX (2000.0) /// @brief Limit MIN voltage adc range for module sensor #define SOIL_VWC_VOLTAGE_MIN (1000.0) +/// @brief Limit MIN voltage adc range sensor absent +#define SOIL_VWC_VOLTAGE_ABSENT (200.0) /// @brief Limit MAX error valid range for module sensor #define SOIL_VWC_ERROR_VOLTAGE_MAX (500.0) diff --git a/platformio/stima_v4/slave-vwc/src/tasks/soil_vwc_sensor_task.cpp b/platformio/stima_v4/slave-vwc/src/tasks/soil_vwc_sensor_task.cpp index f78770ca7..ee879a661 100644 --- a/platformio/stima_v4/slave-vwc/src/tasks/soil_vwc_sensor_task.cpp +++ b/platformio/stima_v4/slave-vwc/src/tasks/soil_vwc_sensor_task.cpp @@ -396,6 +396,8 @@ float SoilVWCSensorTask::getAdcCalibratedValue(float adc_value, float offset, fl value = adc_value; value += offset; value *= gain; + if(value <= ADC_MIN) value = ADC_MIN; + if(value >= ADC_MAX) value = ADC_MAX; } return value; @@ -457,8 +459,9 @@ float SoilVWCSensorTask::getSoilVWC(float adc_value, float adc_voltage_min, floa if ((value < (adc_voltage_min + SOIL_VWC_ERROR_VOLTAGE_MIN)) || (value > (adc_voltage_max + SOIL_VWC_ERROR_VOLTAGE_MAX))) { - *adc_overflow = true; value = UINT16_MAX; + // Activate flag only with sensor is a real connected to ADC + if(value > SOIL_VWC_VOLTAGE_ABSENT) *adc_overflow = true; } else {