From 4cd21644d69dfd53f4094a75bbce15679bf45282 Mon Sep 17 00:00:00 2001 From: kugelkopf123 <45996965+kugelkopf123@users.noreply.github.com> Date: Mon, 27 Apr 2020 20:44:26 +0200 Subject: [PATCH] Update xsns_02_analog.ino --- tasmota/xsns_02_analog.ino | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 038da9fa5..41be46ff8 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -166,6 +166,8 @@ void AdcGetCurrentPower(uint8_t factor) uint16_t analog = 0; uint16_t analog_min = 1023; uint16_t analog_max = 0; + + if(Settings.adc_param1==0){ for (uint32_t i = 0; i < samples; i++) { analog = analogRead(A0); if (analog < analog_min) { @@ -176,8 +178,19 @@ void AdcGetCurrentPower(uint8_t factor) } delay(1); } - Adc.current = (float)(analog_max-analog_min) * ((float)(Settings.adc_param2) / 100000); + } + else{ + + analog = AdcRead(5); + if(analog>Settings.adc_param1){ + Adc.current = ((float)(analog) - (float)Settings.adc_param1) * ((float)(Settings.adc_param2) / 100000); + } + else{ + Adc.current = 0; + } + } + float power = Adc.current * (float)(Settings.adc_param3) / 10; uint32_t current_millis = millis(); Adc.energy = Adc.energy + ((power * (current_millis - Adc.previous_millis)) / 3600000000); @@ -357,7 +370,7 @@ void CmndAdcParam(void) Settings.adc_param3 = (int)(CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 4)) * 10000); } if (ADC0_CT_POWER == XdrvMailbox.payload) { - if ((Settings.adc_param1 & CT_FLAG_ENERGY_RESET) > 0) { + if ((Settings.adc_param1 == 1 & CT_FLAG_ENERGY_RESET) > 0) { Adc.energy = 0; Settings.adc_param1 ^= CT_FLAG_ENERGY_RESET; // Cancel energy reset flag } @@ -435,4 +448,4 @@ bool Xsns02(uint8_t function) return result; } -#endif // USE_ADC_VCC +#endif // USE_ADC_VCC \ No newline at end of file