From 27a08b456e511d3b5bf97d16878df7cedf3dbe1c Mon Sep 17 00:00:00 2001 From: barbudor Date: Tue, 4 Jan 2022 16:33:35 +0100 Subject: [PATCH] make adc_ph formula more flexible --- tasmota/xsns_02_analog.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index c6fce4051..25670ffaa 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -338,13 +338,13 @@ float AdcGetPh(uint32_t idx) { int adc = AdcRead(Adc[idx].pin, 2); - float y1 = Adc[idx].param1 / ANALOG_PH_DECIMAL_MULTIPLIER; - uint32_t x1 = Adc[idx].param2; - float y2 = Adc[idx].param3 / ANALOG_PH_DECIMAL_MULTIPLIER; - uint32_t x2 = Adc[idx].param4; + float y1 = (float)Adc[idx].param1 / ANALOG_PH_DECIMAL_MULTIPLIER; + int32_t x1 = Adc[idx].param2; + float y2 = (float)Adc[idx].param3 / ANALOG_PH_DECIMAL_MULTIPLIER; + int32_t x2 = Adc[idx].param4; - float m = (y2 - y1) / (x2 - x1); - float ph = m * (adc - x1) + y1; + float m = (y2 - y1) / (float)(x2 - x1); + float ph = m * (float)(adc - x1) + y1; char phLow_chr[6]; @@ -417,7 +417,7 @@ void AdcEverySecond(void) { double Rt = (adc * Adc[idx].param1) / (ANALOG_RANGE * ANALOG_V33 - (double)adc); // Shelly param1 = 32000 (ANALOG_NTC_BRIDGE_RESISTANCE) #else double Rt = (adc * Adc[idx].param1) / (ANALOG_RANGE - (double)adc); -#endif +#endif double BC = (double)Adc[idx].param3 / 10000; // Shelly param3 = 3350 (ANALOG_NTC_B_COEFFICIENT) double T = BC / (BC / ANALOG_T0 + TaylorLog(Rt / (double)Adc[idx].param2)); // Shelly param2 = 10000 (ANALOG_NTC_RESISTANCE) Adc[idx].temperature = ConvertTemp(TO_CELSIUS(T));