From b91ef3ec7e307b8459e929a03b004aa4b77a6d37 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 23 Mar 2019 11:04:22 +0100 Subject: [PATCH] define fixups --- src/battery.cpp | 18 +++++++++++------- src/main.cpp | 17 ++++++++--------- src/mbedtls_aes.c | 2 +- src/payload.cpp | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/battery.cpp b/src/battery.cpp index ab15fe4e..4f412c77 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -8,7 +8,7 @@ esp_adc_cal_characteristics_t *adc_characs = (esp_adc_cal_characteristics_t *)calloc( 1, sizeof(esp_adc_cal_characteristics_t)); -static const adc1_channel_t adc_channel = HAS_BATTERY_PROBE; +static const adc1_channel_t adc_channel = BAT_MEASURE_ADC; static const adc_atten_t atten = ADC_ATTEN_DB_11; static const adc_unit_t unit = ADC_UNIT_1; #endif @@ -43,19 +43,23 @@ uint16_t read_voltage() { } adc_reading /= NO_OF_SAMPLES; // Convert ADC reading to voltage in mV - uint16_t voltage = - (uint16_t)esp_adc_cal_raw_to_voltage(adc_reading, adc_characs); -#ifdef BATT_FACTOR - voltage *= BATT_FACTOR; + uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_characs); +#ifdef BAT_VOLTAGE_DIVIDER + voltage *= BAT_VOLTAGE_DIVIDER; #endif - return voltage; + +#ifdef BAT_MEASURE_EN // turn ext. power off + digitalWrite(EXT_POWER_SW, EXT_POWER_OFF); +#endif + + return (uint16_t)voltage; #else return 0; #endif } bool batt_sufficient() { -#ifdef HAS_BATTERY_PROBE +#ifdef BAT_MEASURE_ADC uint16_t volts = read_voltage(); return ((volts < 1000) || (volts > OTA_MIN_BATT)); // no battery or battery sufficient diff --git a/src/main.cpp b/src/main.cpp index 260513bb..0f87bbf5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -180,16 +180,15 @@ void setup() { strcat_P(features, " PSRAM"); #endif -// set low power mode to off -#ifdef HAS_LOWPOWER_SWITCH - pinMode(HAS_LOWPOWER_SWITCH, OUTPUT); -#if (LOW_POWER_ACTIVE_LOW) - digitalWrite(HAS_LOWPOWER_SWITCH, HIGH); -#else - digitalWrite(HAS_LOWPOWER_SWITCH, LOW); +// set external power mode to off +#ifdef EXT_POWER_SW + pinMode(EXT_POWER_SW, OUTPUT); + digitalWrite(EXT_POWER_SW, EXT_POWER_ON); + strcat_P(features, " VEXT"); #endif - strcat_P(features, " LPWR"); +#ifdef BAT_MEASURE_EN + pinMode(BAT_MEASURE_EN, OUTPUT); #endif // initialize leds @@ -224,7 +223,7 @@ void setup() { #endif // initialize battery status -#ifdef HAS_BATTERY_PROBE +#ifdef BAT_MEASURE_ADC strcat_P(features, " BATT"); calibrate_voltage(); batt_voltage = read_voltage(); diff --git a/src/mbedtls_aes.c b/src/mbedtls_aes.c index 0a40ed3c..aa481790 100644 --- a/src/mbedtls_aes.c +++ b/src/mbedtls_aes.c @@ -13,7 +13,7 @@ #include "mbedtls/aes.h" #include "lmic/oslmic.h" -#if defined(USE_MBEDTLS_AES) +#if defined USE_MBEDTLS_AES void lmic_aes_encrypt(u1_t *data, u1_t *key) { diff --git a/src/payload.cpp b/src/payload.cpp index 20e34a05..c70edc20 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -373,7 +373,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius, buffer[cursor++] = LPP_ANALOG_INPUT; buffer[cursor++] = highByte(volt); buffer[cursor++] = lowByte(volt); -#endif // HAS_BATTERY_PROBE +#endif // BAT_MEASURE_ADC #if (PAYLOAD_ENCODER == 3) buffer[cursor++] = LPP_TEMPERATURE_CHANNEL;