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
33 lines
1.2 KiB
C++
33 lines
1.2 KiB
C++
#include "storage_monitor.h"
|
|
|
|
namespace roro {
|
|
|
|
void StorageMonitor::update(bool present, uint64_t totalBytes, uint64_t usedBytes) {
|
|
StorageState next;
|
|
next.present = present && totalBytes > 0;
|
|
if (next.present) {
|
|
next.totalBytes = totalBytes;
|
|
next.usedBytes = usedBytes;
|
|
next.usedPercent = static_cast<int>(usedBytes * 100 / totalBytes);
|
|
bool full = totalBytes - usedBytes < kFullReserveBytes || usedBytes >= totalBytes;
|
|
next.level = full ? 100 : next.usedPercent >= 90 ? 90 : next.usedPercent >= 80 ? 80 : 0;
|
|
next.logsAllowed = next.level < 90;
|
|
next.capturesAllowed = next.level < 100;
|
|
}
|
|
|
|
bool levelChanged = next.present && (next.level != state_.level || !state_.present);
|
|
bool firstReading = !state_.present;
|
|
state_ = next;
|
|
|
|
if (levelChanged && !(firstReading && next.level == 0))
|
|
bus_.publish(Event::withValues(EventType::StorageThreshold, next.usedPercent, next.level));
|
|
|
|
if (next.present && next.level >= 80 && !warned_) {
|
|
warned_ = true;
|
|
bus_.publish(Event::withText(EventType::Notification, "SD card over 80% full",
|
|
static_cast<int32_t>(NotificationLevel::Warning)));
|
|
}
|
|
}
|
|
|
|
} // namespace roro
|