#include "fgc/sensors/McuEnvSensor.h" #include namespace fgc { namespace { long long epochMs() { return std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()) .count(); } } // namespace McuEnvSensor::McuEnvSensor(IMotorController& motor, std::function now_ms) : motor_(motor), now_ms_(now_ms ? std::move(now_ms) : epochMs) {} std::optional McuEnvSensor::current() const { const auto r = motor_.latestEnv(); if (!r || !r->sensor_ok) return std::nullopt; if (now_ms_() - r->epoch_ms > kStaleMs) return std::nullopt; EnvSample s; s.valid = true; s.temp_c = static_cast(r->temp_c); s.humidity_pct = static_cast(r->humidity); s.timestamp_ms = r->epoch_ms; return s; } bool McuEnvSensor::connected() const { return current().has_value(); } std::optional McuEnvSensor::sample() { return current(); } } // namespace fgc