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