From 9747e571e000f20d16a327a6af1627370a6dc53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sun, 26 Feb 2017 16:36:09 +0100 Subject: [PATCH] Disable ADC_VCC when using ADC in Emon module --- code/espurna/config/general.h | 8 -------- code/espurna/config/sensors.h | 31 ++++++++++++++++++++----------- code/espurna/emon.ino | 4 +++- code/espurna/espurna.ino | 4 ++-- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 6a00b2fa..5b5683de 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -16,14 +16,6 @@ #define EEPROM_ENERGY_COUNT 1 #define EEPROM_DATA_END 5 -//-------------------------------------------------------------------------------- -// POWER SUPPLY -//-------------------------------------------------------------------------------- - -#ifndef ENABLE_VCC_REPORT -#define ENABLE_VCC_REPORT 1 -#endif - //-------------------------------------------------------------------------------- // BUTTON //-------------------------------------------------------------------------------- diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index db0248d9..bd2c069d 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -1,12 +1,3 @@ -//-------------------------------------------------------------------------------- -// Internal popwer montior -// Enable support by passing ENABLE_VCC_REPORT=1 build flag -//-------------------------------------------------------------------------------- - -#if (MQTT_REPORTS | MQTT_VCC_REPORT) - ADC_MODE(ADC_VCC); -#endif - //-------------------------------------------------------------------------------- // Custom RF module // Check http://tinkerman.cat/adding-rf-to-a-non-rf-itead-sonoff/ @@ -57,15 +48,19 @@ #define EMON_PROVIDER EMON_ANALOG_PROVIDER #if EMON_PROVIDER == EMON_ANALOG_PROVIDER - #define EMON_CURRENT_PIN 0 + #define EMON_CURRENT_PIN 0 #define EMON_ADC_BITS 10 #define EMON_REFERENCE_VOLTAGE 1.0 #define EMON_CURRENT_PRECISION 1 #define EMON_CURRENT_OFFSET 0.25 + #if ENABLE_EMON + #undef ENABLE_ADC_VCC + #define ENABLE_ADC_VCC 0 + #endif #endif #if EMON_PROVIDER == EMON_ADC121_PROVIDER - #define EMON_ADC121_ADDRESS 0x50 + #define EMON_ADC121_ADDRESS 0x50 #define EMON_ADC_BITS 12 #define EMON_REFERENCE_VOLTAGE 3.3 #define EMON_CURRENT_PRECISION 2 @@ -104,3 +99,17 @@ #define POW_ENERGY_TOPIC "/energy" #define POW_UPDATE_INTERVAL 5000 #define POW_REPORT_EVERY 12 + +//-------------------------------------------------------------------------------- +// Internal power montior +// Enable support by passing ENABLE_ADC_VCC=1 build flag +// Do not enable this if using the analog GPIO for any other thing +//-------------------------------------------------------------------------------- + +#ifndef ENABLE_ADC_VCC +#define ENABLE_ADC_VCC 1 +#endif + +#if ENABLE_ADC_VCC + ADC_MODE(ADC_VCC); +#endif diff --git a/code/espurna/emon.ino b/code/espurna/emon.ino index 445feeb1..d70bd32d 100644 --- a/code/espurna/emon.ino +++ b/code/espurna/emon.ino @@ -9,8 +9,10 @@ Copyright (C) 2016-2017 by Xose PĂ©rez #if ENABLE_EMON #include -#include "brzo_i2c.h" #include +#if EMON_PROVIDER == EMON_ADC121_PROVIDER +#include "brzo_i2c.h" +#endif // ADC121 Registers #define ADC121_REG_RESULT 0x00 diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index e2a40bcd..2cac29dc 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -55,7 +55,7 @@ void hardwareLoop() { DEBUG_MSG("[MAIN] Time: %s\n", (char *) NTP.getTimeDateString().c_str()); DEBUG_MSG("[MAIN] Uptime: %ld seconds\n", uptime_seconds); DEBUG_MSG("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap()); - #if ENABLE_VCC_REPORT + #if ENABLE_ADC_VCC DEBUG_MSG("[MAIN] Power: %d mV\n", ESP.getVcc()); #endif @@ -72,7 +72,7 @@ void hardwareLoop() { mqttSend(MQTT_FREEHEAP_TOPIC, String(ESP.getFreeHeap()).c_str()); #endif #if (MQTT_REPORTS | MQTT_VCC_REPORT) - #if ENABLE_VCC_REPORT + #if ENABLE_ADC_VCC mqttSend(MQTT_VCC_TOPIC, String(ESP.getVcc()).c_str()); #endif #endif