Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,24 @@ class AnalogBatteryLevel : public HasBatteryLevel
raw = espAdcRead();
scaled = esp_adc_cal_raw_to_voltage(raw, adc_characs);
scaled *= operativeAdcMultiplier;
#else // block for all other platforms
#else // block for all other platforms
#if BATTERY_PIN != -1 // Skip if pin not used
for (uint32_t i = 0; i < BATTERY_SENSE_SAMPLES; i++) {
raw += analogRead(BATTERY_PIN);
}
raw = raw / BATTERY_SENSE_SAMPLES;
scaled = operativeAdcMultiplier * ((1000 * AREF_VOLTAGE) / pow(2, BATTERY_SENSE_RESOLUTION_BITS)) * raw;
#endif
#if defined(USE_VDDHDIV5) and defined(ARCH_NRF52)
if (scaled <
1000) { // Battery pin not used or not connected to voltage divider, fallback to reading voltage of VDDH pin
for (uint32_t i = 0; i < BATTERY_SENSE_SAMPLES; i++) {
raw += analogReadVDDHDIV5();
}
raw = raw / BATTERY_SENSE_SAMPLES;
scaled = 5 * ((1000 * AREF_VOLTAGE) / pow(2, BATTERY_SENSE_RESOLUTION_BITS)) * raw;
}
#endif
#endif
battery_adcDisable();

Expand Down