blob: 23aea9949b9a65afd639b933f4a6aa7d03d15aef [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;
James Feist36b7d8e2018-10-05 15:39:01 -070027 bool getFailed(void) override;
Patrick Venture863b9242018-03-08 08:29:23 -080028
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070029 private:
30 std::unique_ptr<ReadInterface> _reader;
31 std::unique_ptr<WriteInterface> _writer;
Patrick Venture863b9242018-03-08 08:29:23 -080032};
Patrick Venturea0764872020-08-08 07:48:43 -070033
34} // namespace pid_control