From 22577ea92a2425d36b31476aac8e1e45a8b16910 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 5 Nov 2018 21:43:22 +0100 Subject: [PATCH] battery.cpp sanitized --- src/battery.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/battery.cpp b/src/battery.cpp index 367a4678..bb2ffce7 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -1,5 +1,3 @@ -#ifdef HAS_BATTERY_PROBE - #include "globals.h" // Local logging tag @@ -14,6 +12,7 @@ static const adc_atten_t atten = ADC_ATTEN_DB_11; static const adc_unit_t unit = ADC_UNIT_1; void calibrate_voltage(void) { +#ifdef HAS_BATTERY_PROBE // configure ADC ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12)); ESP_ERROR_CHECK(adc1_config_channel_atten(adc_channel, atten)); @@ -30,9 +29,11 @@ void calibrate_voltage(void) { } else { ESP_LOGI(TAG, "ADC characterization based on default reference voltage"); } +#endif } uint16_t read_voltage() { +#ifdef HAS_BATTERY_PROBE // multisample ADC uint32_t adc_reading = 0; for (int i = 0; i < NO_OF_SAMPLES; i++) { @@ -47,6 +48,9 @@ uint16_t read_voltage() { #endif ESP_LOGD(TAG, "Raw: %d / Voltage: %dmV", adc_reading, voltage); return voltage; +#else + return 0; +#endif } bool batt_sufficient() { @@ -57,6 +61,4 @@ bool batt_sufficient() { #else return true; #endif -} - -#endif // HAS_BATTERY_PROBE \ No newline at end of file +} \ No newline at end of file