From 2f33f8e5a88325d8f3813d1dd9a5900eab14371a Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 25 Jul 2024 18:04:01 +0200 Subject: [PATCH] Fix Non-ESP32 Analog read resolution --- tasmota/tasmota_xsns_sensor/xsns_02_analog.ino | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino index 8ad0de246..88928ab19 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino @@ -35,6 +35,7 @@ #define ANALOG_RANGE 1023 // 4095 = 12, 2047 = 11, 1023 = 10 #define ANALOG_PERCENT 10 // backward compatible div10 range #endif // ESP8266 + #ifdef ESP32 #undef ANALOG_RESOLUTION #define ANALOG_RESOLUTION 12 // 12 = 4095, 11 = 2047, 10 = 1023 @@ -305,10 +306,8 @@ void AdcInit(void) { if (Adcs.present) { #ifdef ESP32 -#if CONFIG_IDF_TARGET_ESP32 - analogSetWidth(ANALOG_RESOLUTION); // Default 12 bits (0 - 4095) -#endif // CONFIG_IDF_TARGET_ESP32 - analogSetAttenuation(ADC_11db); // Default 11db + analogReadResolution(ANALOG_RESOLUTION); // Default 12 bits (0 - 4095) + analogSetAttenuation(ADC_11db); // Default 11db #endif for (uint32_t idx = 0; idx < Adcs.present; idx++) { AdcGetSettings(idx);