From 1b24378da5ef1c04e8a47908bce3d1cefd5a701f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:52:12 +0200 Subject: [PATCH] Free 500 code bytes on ADC/ESP8266 --- tasmota/tasmota_xsns_sensor/xsns_02_analog.ino | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino index 68754c514..bcd9c358f 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino @@ -71,7 +71,10 @@ \*********************************************************************************************/ #define XSNS_02 2 +#if defined(ESP32) && defined(USE_ENERGY_SENSOR) +// Only ESP32 and up support more than one ADC channel enabling energy driver #define XNRG_33 33 +#endif // ESP32 and USE_ENERGY_SENSOR #ifdef ESP32 #include "esp32-hal-adc.h" @@ -944,7 +947,10 @@ void AdcShow(bool json) { break; } case GPIO_ADC_VOLTAGE: - if (TasmotaGlobal.energy_driver != XNRG_33) { +#if defined(ESP32) && defined(USE_ENERGY_SENSOR) + if (TasmotaGlobal.energy_driver != XNRG_33) +#endif // ESP32 and USE_ENERGY_SENSOR + { float value = AdcGetRange(channel) / 10000; // Volt if (value < 0.0f) { value = 0.0f; } // Disregard negative values if (json) { @@ -959,7 +965,10 @@ void AdcShow(bool json) { } break; case GPIO_ADC_CURRENT: - if (TasmotaGlobal.energy_driver != XNRG_33) { +#if defined(ESP32) && defined(USE_ENERGY_SENSOR) + if (TasmotaGlobal.energy_driver != XNRG_33) +#endif // ESP32 and USE_ENERGY_SENSOR + { float value = AdcGetRange(channel) / 10000; // Ampere if (value < 0.0f) { value = 0.0f; } // Disregard negative values if (json) { @@ -1152,7 +1161,7 @@ void CmndAdcParam(void) { * Energy Interface \*********************************************************************************************/ -#ifdef USE_ENERGY_SENSOR +#if defined(ESP32) && defined(USE_ENERGY_SENSOR) void AdcEnergyEverySecond(void) { uint32_t voltage_count = 0; uint32_t current_count = 0; @@ -1214,7 +1223,7 @@ bool Xnrg33(uint32_t function) { } return result; } -#endif // USE_ENERGY_SENSOR +#endif // ESP32 and USE_ENERGY_SENSOR /*********************************************************************************************\ * Sensor Interface