blob: 0dc1c71e6a9399f38053b315db77000238079197 [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001#pragma once
2
Patrick Venture863b9242018-03-08 08:29:23 -08003#include "interfaces.hpp"
4#include "sensor.hpp"
5
Patrick Venturea83a3ec2020-08-04 09:52:05 -07006#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07007#include <string>
Patrick Venture863b9242018-03-08 08:29:23 -08008
Patrick Venturea0764872020-08-08 07:48:43 -07009namespace pid_control
10{
11
Patrick Venture863b9242018-03-08 08:29:23 -080012/*
13 * A Sensor that can use any reader or writer you provide.
14 */
15class PluggableSensor : public Sensor
16{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070017 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))
Patrick Venturea83a3ec2020-08-04 09:52:05 -070023 {}
Patrick Venture863b9242018-03-08 08:29:23 -080024
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025 ReadReturn read(void) override;
26 void write(double value) override;
Josh Lehan2400ce42020-10-01 01:50:39 -070027 void write(double value, bool force, int64_t* written) override;
James Feist36b7d8e2018-10-05 15:39:01 -070028 bool getFailed(void) override;
Patrick Venture863b9242018-03-08 08:29:23 -080029
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030 private:
31 std::unique_ptr<ReadInterface> _reader;
32 std::unique_ptr<WriteInterface> _writer;
Patrick Venture863b9242018-03-08 08:29:23 -080033};
Patrick Venturea0764872020-08-08 07:48:43 -070034
35} // namespace pid_control