mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 09:42:35 +00:00
Always do battery resampling if we use the ADC. Improves reading a lot.
This commit is contained in:
parent
b14289e976
commit
2a84d39e40
@ -102,6 +102,10 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
#define ADC_MULTIPLIER 2.0
|
#define ADC_MULTIPLIER 2.0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef BATTERY_SENSE_SAMPLES
|
||||||
|
#define BATTERY_SENSE_SAMPLES 30
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BATTERY_PIN
|
#ifdef BATTERY_PIN
|
||||||
// Override variant or default ADC_MULTIPLIER if we have the override pref
|
// Override variant or default ADC_MULTIPLIER if we have the override pref
|
||||||
float operativeAdcMultiplier = config.power.adc_multiplier_override > 0
|
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) {
|
if (millis() - last_read_time_ms > min_read_interval) {
|
||||||
last_read_time_ms = millis();
|
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.
|
//Set the number of samples, it has an effect of increasing sensitivity, especially in complex electromagnetic environment.
|
||||||
uint32_t raw = 0;
|
uint32_t raw = 0;
|
||||||
for(uint32_t i=0; i<BATTERY_SENSE_SAMPLES;i++){
|
for(uint32_t i=0; i<BATTERY_SENSE_SAMPLES; i++){
|
||||||
raw += analogRead(BATTERY_PIN);
|
raw += analogRead(BATTERY_PIN);
|
||||||
}
|
}
|
||||||
raw = raw/BATTERY_SENSE_SAMPLES;
|
raw = raw/BATTERY_SENSE_SAMPLES;
|
||||||
#else
|
|
||||||
uint32_t raw = analogRead(BATTERY_PIN);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
float scaled;
|
float scaled;
|
||||||
#ifndef VBAT_RAW_TO_SCALED
|
#ifndef VBAT_RAW_TO_SCALED
|
||||||
@ -290,7 +290,8 @@ void Power::readPowerStatus()
|
|||||||
if (powerStatus2.getHasBattery() && !powerStatus2.getHasUSB()) {
|
if (powerStatus2.getHasBattery() && !powerStatus2.getHasUSB()) {
|
||||||
if (batteryLevel->getBattVoltage() < MIN_BAT_MILLIVOLTS) {
|
if (batteryLevel->getBattVoltage() < MIN_BAT_MILLIVOLTS) {
|
||||||
low_voltage_counter++;
|
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);
|
powerFSM.trigger(EVENT_LOW_BATTERY);
|
||||||
} else {
|
} else {
|
||||||
low_voltage_counter = 0;
|
low_voltage_counter = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user