Public Access
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:
@@ -0,0 +1,36 @@
|
||||
#include "power_policy.h"
|
||||
|
||||
namespace roro {
|
||||
|
||||
bool PowerPolicy::activity(uint32_t nowMs) {
|
||||
bool swallow = state_ == ScreenState::Off;
|
||||
lastActivityMs_ = nowMs;
|
||||
state_ = ScreenState::On;
|
||||
return swallow;
|
||||
}
|
||||
|
||||
ScreenState PowerPolicy::update(uint32_t nowMs) {
|
||||
uint32_t idle = nowMs - lastActivityMs_;
|
||||
state_ = idle >= offMs_ ? ScreenState::Off : idle >= dimMs_ ? ScreenState::Dimmed : ScreenState::On;
|
||||
return state_;
|
||||
}
|
||||
|
||||
ButtonAction PowerButton::update(bool pressed, uint32_t nowMs) {
|
||||
if (pressed && !pressed_) {
|
||||
pressed_ = true;
|
||||
longFired_ = false;
|
||||
pressedAtMs_ = nowMs;
|
||||
return ButtonAction::None;
|
||||
}
|
||||
if (pressed && !longFired_ && nowMs - pressedAtMs_ >= longMs_) {
|
||||
longFired_ = true;
|
||||
return ButtonAction::LongPress;
|
||||
}
|
||||
if (!pressed && pressed_) {
|
||||
pressed_ = false;
|
||||
return longFired_ ? ButtonAction::None : ButtonAction::ShortPress;
|
||||
}
|
||||
return ButtonAction::None;
|
||||
}
|
||||
|
||||
} // namespace roro
|
||||
Reference in New Issue
Block a user