1 #pragma once 2 3 #include "interfaces.hpp" 4 #include "sensor.hpp" 5 6 #include <cstdint> 7 #include <memory> 8 #include <string> 9 #include <utility> 10 11 namespace pid_control 12 { 13 14 /* 15 * A Sensor that can use any reader or writer you provide. 16 */ 17 class PluggableSensor : public Sensor 18 { 19 public: 20 PluggableSensor(const std::string& name, int64_t timeout, 21 std::unique_ptr<ReadInterface> reader, 22 std::unique_ptr<WriteInterface> writer) : 23 Sensor(name, timeout), _reader(std::move(reader)), 24 _writer(std::move(writer)) 25 {} 26 27 ReadReturn read(void) override; 28 void write(double value) override; 29 void write(double value, bool force, int64_t* written) override; 30 bool getFailed(void) override; 31 std::string getFailReason(void) override; 32 33 private: 34 std::unique_ptr<ReadInterface> _reader; 35 std::unique_ptr<WriteInterface> _writer; 36 }; 37 38 } // namespace pid_control 39