Skip to content

Commit

Permalink
Free 500 code bytes on ADC/ESP8266
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Aug 15, 2024
1 parent 851f11d commit 1b24378
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tasmota/tasmota_xsns_sensor/xsns_02_analog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1214,7 +1223,7 @@ bool Xnrg33(uint32_t function) {
}
return result;
}
#endif // USE_ENERGY_SENSOR
#endif // ESP32 and USE_ENERGY_SENSOR

/*********************************************************************************************\
* Sensor Interface
Expand Down

0 comments on commit 1b24378

Please sign in to comment.