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
+35
View File
@@ -0,0 +1,35 @@
#pragma once
#include "power_policy.h"
#include "service.h"
#include "settings.h"
namespace roro {
// Screen dimming/off from user activity and G0 handling. A long G0 press powers off (deep sleep,
// woken by G0); Services stop with it.
class PowerService : public Service {
public:
explicit PowerService(const Settings& settings);
const char* name() const override { return "power"; }
uint32_t tickIntervalMs() const override { return 50; }
void start() override;
void tick(uint32_t nowMs) override;
// Call for every key press before routing it. Returns true if the key must not reach the App.
bool onKey(uint32_t nowMs) { return policy_.activity(nowMs); }
ScreenState screen() const { return applied_; }
private:
void applyScreen(ScreenState state);
void powerOff();
const Settings& settings_;
PowerPolicy policy_;
PowerButton button_{2000};
ScreenState applied_ = ScreenState::On;
int appliedBrightness_ = -1;
};
} // namespace roro