From c8b8c53391df518df52c1044035c7495e4f0b8f9 Mon Sep 17 00:00:00 2001 From: Moreno Gasperini Date: Thu, 24 Oct 2024 15:14:34 +0200 Subject: [PATCH] Update solar_radiation_sensor_task.cpp Fix limit check calibrated value --- .../slave-radiation/src/tasks/solar_radiation_sensor_task.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platformio/stima_v4/slave-radiation/src/tasks/solar_radiation_sensor_task.cpp b/platformio/stima_v4/slave-radiation/src/tasks/solar_radiation_sensor_task.cpp index 6cb20dca0..d39ede97f 100644 --- a/platformio/stima_v4/slave-radiation/src/tasks/solar_radiation_sensor_task.cpp +++ b/platformio/stima_v4/slave-radiation/src/tasks/solar_radiation_sensor_task.cpp @@ -366,7 +366,7 @@ int32_t SolarRadiationSensorTask::getVrefTemp(void) /// @param adc_value adc in value /// @param offset offset adjust value /// @param gain gain adjust value -/// @return ADC value calibrated +/// @return ADC value calibrated and checked with input area validation limit float SolarRadiationSensorTask::getAdcCalibratedValue(float adc_value, float offset, float gain) { float value = (float)UINT16_MAX; @@ -376,6 +376,8 @@ float SolarRadiationSensorTask::getAdcCalibratedValue(float adc_value, float off value = adc_value; value += offset; value *= gain; + if(value <= ADC_MIN) value = ADC_MIN; + if(value >= ADC_MAX) value = ADC_MAX; } return value;