From b34bc60a0a0ab40c9e4db06b1a63074b35013ba9 Mon Sep 17 00:00:00 2001 From: rbaron Date: Sun, 19 Mar 2023 10:14:07 +0100 Subject: [PATCH] Actually use the devicetree calibration coeffs --- code/nrf-connect/prstlib/src/adc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/code/nrf-connect/prstlib/src/adc.c b/code/nrf-connect/prstlib/src/adc.c index 34d43d4..13d3978 100644 --- a/code/nrf-connect/prstlib/src/adc.c +++ b/code/nrf-connect/prstlib/src/adc.c @@ -93,18 +93,11 @@ static inline float eval_poly(const int coeffs[3], float x) { static inline float get_soil_moisture_percent(float battery_voltage, int16_t raw_adc_output) { const float x = battery_voltage; - const float dry = -11.7f * x * x + 101.0f * x + 306.0f; - const float wet = 3.42f * x * x - 4.98f * x + 19.0f; + const float dry = eval_poly(dry_coeffs, x); + const float wet = eval_poly(wet_coeffs, x); const float percent = (raw_adc_output - dry) / (wet - dry); - LOG_INF("Read soil moisture: %.2f | Raw %u | Batt: %.2f | Dry: %.2f | Wet: %.2f", - 100.0f * percent, raw_adc_output, x, dry, wet); - - const float dry2 = eval_poly(dry_coeffs, x); - const float wet2 = eval_poly(wet_coeffs, x); - const float percent2 = (raw_adc_output - dry2) / (wet2 - dry2); LOG_INF("Read soil moisture 2: %.2f | Raw %u | Batt: %.2f | Dry: %.2f | Wet: %.2f", - 100.0f * percent2, raw_adc_output, x, dry2, wet2); - + 100.0f * percent, raw_adc_output, x, dry, wet); return percent; }