fwt_software/include/fgc/IEnvSensor.h

38 lines
1.0 KiB
C++

#pragma once
#include <optional>
#include <string>
namespace fgc {
struct EnvSample {
bool valid = false;
float temp_c = 0.0f;
float humidity_pct = 0.0f;
long long timestamp_ms = 0;
};
// Abstraction over an ambient temperature/humidity sensor. Implemented by
// Sht41EnvSensor (SHT41 on the LattePanda's native I2C bus) and MockEnvSensor
// (synthetic). The interface intentionally exposes nothing chip-specific, so
// swapping the sensor (a different I2C part, or a serial one) means writing a
// new backend, not touching Application/UiSnapshot/MQTT.
class IEnvSensor {
public:
virtual ~IEnvSensor() = default;
virtual void start() = 0;
virtual void stop() = 0;
// Whether a valid, recent reading is available.
virtual bool connected() const = 0;
// Latest reading, or nullopt if none/stale.
virtual std::optional<EnvSample> sample() = 0;
// Identity string for logs/UI, e.g. "SHT41".
virtual std::string name() const { return "env"; }
};
} // namespace fgc