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: PluggableSensor(const std::string & name,int64_t timeout,std::unique_ptr<ReadInterface> reader,std::unique_ptr<WriteInterface> writer,bool ignoreFailIfHostOff=false)20 PluggableSensor(const std::string& name, int64_t timeout, 21 std::unique_ptr<ReadInterface> reader, 22 std::unique_ptr<WriteInterface> writer, 23 bool ignoreFailIfHostOff = false) : 24 Sensor(name, timeout, ignoreFailIfHostOff), _reader(std::move(reader)), 25 _writer(std::move(writer)) 26 {} 27 28 ReadReturn read(void) override; 29 void write(double value) override; 30 void write(double value, bool force, int64_t* written) override; 31 bool getFailed(void) override; 32 std::string getFailReason(void) override; 33 34 private: 35 std::unique_ptr<ReadInterface> _reader; 36 std::unique_ptr<WriteInterface> _writer; 37 }; 38 39 } // namespace pid_control 40