Files
roro9stack/src/services/clock_service.h
T
twislaandClaude Opus 5.5 74a341418e M1 step 4b: IRC Service on the device; 8-bit frame buffer
- IrcService: networking on its own task, TLS with the built-in CA
  bundle (or trust-on-first-use pinning when self-signed is allowed),
  plain TCP when TLS is off; connects only while Wi-Fi is Connected,
  marks pauses for Monitoring, reconnects with backoff, pings a quiet
  server, writes Logs, raises Notifications for Mentions
- Session: forget /quit once disconnected (it was handled every loop);
  the server Buffer never counts as unread (MOTD showed as [4])
- Status Bar: unread count
- Frame buffer 16 -> 8-bit colour (M1 Q46): min free heap with IRC on
  TLS went from 51 KB to 79 KB
- Serial: irc start / say / dump

Verified on the device against irc.libera.chat:6697: certificate
checked, joined #roro9stack-test, sent a message, quit cleanly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-02 15:10:03 +02:00

47 lines
1.7 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_; }
// UTC seconds, or -1 if the clock isn't set.
int64_t utcNow() const { return model_.isSet() ? model_.utcNow(millis()) : -1; }
// 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