Public Access
- lib/storage_model (host-tested): FAT-safe names, daily Log paths, dates from Log/Capture file names, CleanupPlan by category and age, byte formatting - StorageService does all card I/O on its task: queued Log lines are written in batches each second (dropped while Logs are paused), plus file listing and deletion jobs - Settings > Storage moves into StoragePage: usage, Clean up (category, age with size preview, confirmation), Erase SD card - Clock: local date for Log names - Serial: log <text>, sd list Verified on the device: lines land in /irc/dev/#test/2026-10-02.log with folders created as needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
44 lines
1.5 KiB
C++
44 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include "clock_model.h"
|
|
#include "event_bus.h"
|
|
#include "service.h"
|
|
#include "settings.h"
|
|
|
|
namespace roro {
|
|
|
|
// Holds wall-clock time. Sources (GNSS in M2, NTP in M1, mesh in M4) call set().
|
|
class ClockService : public Service {
|
|
public:
|
|
ClockService(const Settings& settings, EventBus& bus) : settings_(settings) {
|
|
bus.subscribe(EventType::SettingChanged, [this](const Event& e) {
|
|
if (e.a == static_cast<int32_t>(Setting::Timezone)) applyTimezone();
|
|
});
|
|
}
|
|
const char* name() const override { return "clock"; }
|
|
void start() override { applyTimezone(); }
|
|
|
|
bool set(int64_t utcSeconds, TimeSource source) { return model_.set(utcSeconds, source, millis()); }
|
|
const ClockModel& model() const { return model_; }
|
|
|
|
// Local "YYYY-MM-DD" once set; otherwise empty (Logs then go to undated files).
|
|
std::string localDate() const { return model_.isSet() ? ClockModel::formatLocalDate(model_.utcNow(millis())) : ""; }
|
|
// Days since 1970-01-01 (UTC), or -1 if the clock isn't set.
|
|
int today() const { return model_.isSet() ? static_cast<int>(model_.utcNow(millis()) / 86400) : -1; }
|
|
|
|
// "14:05" once set; otherwise "--:--".
|
|
std::string displayTime() const {
|
|
return model_.isSet() ? ClockModel::formatLocalTime(model_.utcNow(millis())) : "--:--";
|
|
}
|
|
|
|
private:
|
|
void applyTimezone() { ClockModel::applyTimezone(settings_.getString(Setting::Timezone).c_str()); }
|
|
|
|
const Settings& settings_;
|
|
ClockModel model_;
|
|
};
|
|
|
|
} // namespace roro
|