2026-10-28 16:48:18 +01:00
|
|
|
#pragma once
|
|
|
|
|
#include <cstdint>
|
2026-11-11 00:13:57 +01:00
|
|
|
#include <esp_adc/adc_oneshot.h>
|
|
|
|
|
#include <esp_adc/adc_cali.h>
|
2026-10-28 16:48:18 +01:00
|
|
|
|
|
|
|
|
namespace microbu {
|
2026-11-11 00:13:57 +01:00
|
|
|
// Calibrated divider voltage for the selected board.
|
2026-10-28 16:48:18 +01:00
|
|
|
class BatteryMonitor {
|
|
|
|
|
public:
|
2026-11-11 00:13:57 +01:00
|
|
|
BatteryMonitor();
|
|
|
|
|
std::uint16_t sample_millivolts(); // 0 means unavailable, never an invented percentage
|
|
|
|
|
/// MicrOBU: powers the board down for CONFIG_MICROBU_BATTERY_SLEEP_S seconds (timer wake-up).
|
|
|
|
|
[[noreturn]] static void deep_sleep();
|
|
|
|
|
/// MicrOBU: true when this boot is the timer wake-up of deep_sleep().
|
|
|
|
|
static bool woke_from_battery_sleep();
|
2026-10-28 16:48:18 +01:00
|
|
|
private:
|
2026-11-11 00:13:57 +01:00
|
|
|
adc_oneshot_unit_handle_t adc_ = nullptr;
|
|
|
|
|
adc_cali_handle_t calibration_ = nullptr;
|
|
|
|
|
adc_channel_t channel_ = ADC_CHANNEL_0;
|
2026-10-28 16:48:18 +01:00
|
|
|
};
|
2026-11-11 00:13:57 +01:00
|
|
|
}
|