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
This commit is contained in:
2026-10-02 09:47:36 +02:00
co-authored by Claude Opus 5.5
parent ae0726b7f9
commit 987406fa7c
28 changed files with 1434 additions and 39 deletions
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include <cstdint>
#include <string>
namespace roro {
// Ordered by trust: a source can only replace the time set by an equal or less trusted one.
enum class TimeSource : uint8_t { None, Mesh, Ntp, Gnss };
// Wall-clock time on a device with no battery-backed clock: unset until a TimeSource provides
// it, then advanced from uptime. Stored in UTC; local display uses the POSIX TZ applied globally.
class ClockModel {
public:
// Returns false if a more trusted source already set the time.
bool set(int64_t utcSeconds, TimeSource source, uint32_t nowMs);
bool isSet() const { return source_ != TimeSource::None; }
TimeSource source() const { return source_; }
int64_t utcNow(uint32_t nowMs) const;
static void applyTimezone(const char* posixTz);
static std::string formatLocalTime(int64_t utcSeconds); // "HH:MM"
static std::string formatAge(int64_t seconds); // "now", "5 min ago", "3 h ago", "2 d ago"
private:
TimeSource source_ = TimeSource::None;
int64_t utcAtSet_ = 0;
uint32_t msAtSet_ = 0;
};
} // namespace roro