Skip to content

Commit

Permalink
Slave VWC
Browse files Browse the repository at this point in the history
Fix adc bug with calibrated ADC value check limit.
Remove message ovweflow without sensor conection, only enabled with minimal measure value.
  • Loading branch information
digitecomg committed Oct 25, 2024
1 parent eb2ee1e commit 831db9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion platformio/stima_v4/slave-vwc/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 831db9e

Please sign in to comment.