Public Access
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
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
namespace roro {
|
|
|
|
enum class ScreenState : uint8_t { On, Dimmed, Off };
|
|
|
|
// Screen power from user activity. Services keep running whatever the screen does.
|
|
class PowerPolicy {
|
|
public:
|
|
PowerPolicy(uint32_t dimAfterMs, uint32_t offAfterMs) : dimMs_(dimAfterMs), offMs_(offAfterMs) {}
|
|
|
|
void setTimeouts(uint32_t dimAfterMs, uint32_t offAfterMs) {
|
|
dimMs_ = dimAfterMs;
|
|
offMs_ = offAfterMs;
|
|
}
|
|
|
|
// Records a key press. Returns true if the key only woke an Off screen and must not reach the App.
|
|
bool activity(uint32_t nowMs);
|
|
|
|
ScreenState update(uint32_t nowMs);
|
|
ScreenState state() const { return state_; }
|
|
|
|
private:
|
|
uint32_t dimMs_;
|
|
uint32_t offMs_;
|
|
uint32_t lastActivityMs_ = 0;
|
|
ScreenState state_ = ScreenState::On;
|
|
};
|
|
|
|
enum class ButtonAction : uint8_t { None, ShortPress, LongPress };
|
|
|
|
// G0 button: a long press fires as soon as the hold time is reached (power off); a short press on release.
|
|
class PowerButton {
|
|
public:
|
|
explicit PowerButton(uint32_t longPressMs) : longMs_(longPressMs) {}
|
|
ButtonAction update(bool pressed, uint32_t nowMs);
|
|
|
|
private:
|
|
uint32_t longMs_;
|
|
bool pressed_ = false;
|
|
bool longFired_ = false;
|
|
uint32_t pressedAtMs_ = 0;
|
|
};
|
|
|
|
} // namespace roro
|