44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "fgc/IEnvSensor.h"
|
|
#include "fgc/Logger.h"
|
|
|
|
#include <chrono>
|
|
#include <cmath>
|
|
|
|
namespace fgc {
|
|
|
|
// Simulated ambient sensor for development without hardware: synthesizes a
|
|
// slowly varying, plausible temp/humidity reading so the Sensors panel
|
|
// animates without an SHT41 attached.
|
|
class MockEnvSensor : public IEnvSensor {
|
|
public:
|
|
void start() override {
|
|
start_ = clock::now();
|
|
LOG_INFO << "[mock] env sensor started";
|
|
}
|
|
void stop() override { LOG_INFO << "[mock] env sensor stopped"; }
|
|
|
|
bool connected() const override { return true; }
|
|
|
|
std::optional<EnvSample> sample() override {
|
|
const double t = std::chrono::duration<double>(clock::now() - start_).count();
|
|
EnvSample s;
|
|
s.valid = true;
|
|
s.temp_c = static_cast<float>(22.0 + 3.0 * std::sin(t * 0.02));
|
|
s.humidity_pct = static_cast<float>(45.0 + 10.0 * std::sin(t * 0.013 + 1.0));
|
|
s.timestamp_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
std::chrono::system_clock::now().time_since_epoch())
|
|
.count();
|
|
return s;
|
|
}
|
|
|
|
std::string name() const override { return "SHT41 (mock)"; }
|
|
|
|
private:
|
|
using clock = std::chrono::steady_clock;
|
|
clock::time_point start_ = clock::now();
|
|
};
|
|
|
|
} // namespace fgc
|