From 2a84d39e40fbc6909163add2556cf6ae09f8410f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Mon, 5 Dec 2022 16:40:23 +0100 Subject: [PATCH] Always do battery resampling if we use the ADC. Improves reading a lot. --- src/Power.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index af10acb5e..dd3ac1497 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -102,6 +102,10 @@ class AnalogBatteryLevel : public HasBatteryLevel #define ADC_MULTIPLIER 2.0 #endif +#ifndef BATTERY_SENSE_SAMPLES +#define BATTERY_SENSE_SAMPLES 30 +#endif + #ifdef BATTERY_PIN // Override variant or default ADC_MULTIPLIER if we have the override pref float operativeAdcMultiplier = config.power.adc_multiplier_override > 0 @@ -112,16 +116,12 @@ class AnalogBatteryLevel : public HasBatteryLevel if (millis() - last_read_time_ms > min_read_interval) { last_read_time_ms = millis(); -#ifdef BATTERY_SENSE_SAMPLES //Set the number of samples, it has an effect of increasing sensitivity, especially in complex electromagnetic environment. uint32_t raw = 0; - for(uint32_t i=0; igetBattVoltage() < MIN_BAT_MILLIVOLTS) { low_voltage_counter++; - if (low_voltage_counter > 3) + DEBUG_MSG("Warning RAK4631 Low voltage counter: %d/10\n", low_voltage_counter); + if (low_voltage_counter > 10) powerFSM.trigger(EVENT_LOW_BATTERY); } else { low_voltage_counter = 0;