Files
roro9stack/lib/services/src/battery_estimator.h
T
twislaandClaude Opus 5.5 987406fa7c Add M0 services: settings, battery, clock, storage, power
lib/services holds the host-tested logic:
- Settings: typed, validated, persisted, SettingChanged events,
  transmit gated on a confirmed Region
- BatteryEstimator: LiPo curve, median smoothing against TX sags
- ClockModel: source priority GNSS > NTP > mesh, relative ages,
  Europe/Brussels local time via POSIX TZ
- StorageMonitor: warning once per boot at 80%, Logs stop at 90%,
  Captures stop with < 2 MiB left
- PowerPolicy / PowerButton: dim/off timeouts, wake key swallowed only
  when the screen was off, G0 long press

src/services wires them to the hardware (NVS, battery ADC, SD on the
shared SPI bus with the LoRa CS held high, backlight, deep sleep), and
main.cpp is a temporary diagnostics screen for the hardware checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-02 09:47:36 +02:00

28 lines
706 B
C++

#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
namespace roro {
// Smooths battery voltage samples and turns them into a charge percentage.
class BatteryEstimator {
public:
// Typical single-cell LiPo discharge curve under light load.
static int percentFromMillivolts(int millivolts);
void addSample(int millivolts);
bool hasReading() const { return count_ > 0; }
int millivolts() const; // median of the recent samples
int percent() const { return percentFromMillivolts(millivolts()); }
private:
static constexpr size_t kWindow = 8;
std::array<int, kWindow> samples_{};
size_t next_ = 0;
size_t count_ = 0;
};
} // namespace roro