Merge pull request #8294 from kugelkopf123/update_adc_2

Update xsns_02_analog.ino
This commit is contained in:
Theo Arends 2020-04-28 09:23:37 +02:00 committed by GitHub
commit 53991beb4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -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