fwt_software/include/fgc/sensors/Sht41EnvSensor.h

35 lines
1.1 KiB
C++

#pragma once
#include "fgc/IEnvSensor.h"
#include <chrono>
#include <cstdint>
#include <memory>
#include <string>
namespace fgc {
// Real backend: Adafruit SHT41 temperature/humidity sensor on the
// LattePanda's own native I2C bus (NOT the Arduino/motor serial link).
// Triggers a high-precision measurement every `period`, sleeps out the ~10ms
// conversion delay, and reads back on its own thread so the ~100Hz control
// loop is never blocked. CRC-8-checked; a failed checksum discards the
// sample rather than reporting a bad reading.
class Sht41EnvSensor : public IEnvSensor {
public:
Sht41EnvSensor(std::string i2c_device, uint8_t addr, std::chrono::milliseconds period);
~Sht41EnvSensor() override;
void start() override;
void stop() override;
bool connected() const override;
std::optional<EnvSample> sample() override;
std::string name() const override { return "SHT41"; }
private:
struct Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace fgc