Free 500 code bytes on ADC/ESP8266

This commit is contained in:
Theo Arends 2024-08-15 12:52:12 +02:00
parent 851f11dcdd
commit 1b24378da5
1 changed files with 13 additions and 4 deletions

View File

@ -71,7 +71,10 @@
\*********************************************************************************************/ \*********************************************************************************************/
#define XSNS_02 2 #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 #define XNRG_33 33
#endif // ESP32 and USE_ENERGY_SENSOR
#ifdef ESP32 #ifdef ESP32
#include "esp32-hal-adc.h" #include "esp32-hal-adc.h"
@ -944,7 +947,10 @@ void AdcShow(bool json) {
break; break;
} }
case GPIO_ADC_VOLTAGE: 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 float value = AdcGetRange(channel) / 10000; // Volt
if (value < 0.0f) { value = 0.0f; } // Disregard negative values if (value < 0.0f) { value = 0.0f; } // Disregard negative values
if (json) { if (json) {
@ -959,7 +965,10 @@ void AdcShow(bool json) {
} }
break; break;
case GPIO_ADC_CURRENT: 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 float value = AdcGetRange(channel) / 10000; // Ampere
if (value < 0.0f) { value = 0.0f; } // Disregard negative values if (value < 0.0f) { value = 0.0f; } // Disregard negative values
if (json) { if (json) {
@ -1152,7 +1161,7 @@ void CmndAdcParam(void) {
* Energy Interface * Energy Interface
\*********************************************************************************************/ \*********************************************************************************************/
#ifdef USE_ENERGY_SENSOR #if defined(ESP32) && defined(USE_ENERGY_SENSOR)
void AdcEnergyEverySecond(void) { void AdcEnergyEverySecond(void) {
uint32_t voltage_count = 0; uint32_t voltage_count = 0;
uint32_t current_count = 0; uint32_t current_count = 0;
@ -1214,7 +1223,7 @@ bool Xnrg33(uint32_t function) {
} }
return result; return result;
} }
#endif // USE_ENERGY_SENSOR #endif // ESP32 and USE_ENERGY_SENSOR
/*********************************************************************************************\ /*********************************************************************************************\
* Sensor Interface * Sensor Interface