blob: b65aefd127927c38927b19a5d400d24e6700cea0 [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
Ed Tanousf8b6e552025-06-27 13:27:50 -07006#include <cstdint>
Patrick Venturea83a3ec2020-08-04 09:52:05 -07007#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07008#include <string>
Ed Tanousf8b6e552025-06-27 13:27:50 -07009#include <utility>
Patrick Venture863b9242018-03-08 08:29:23 -080010
Patrick Venturea0764872020-08-08 07:48:43 -070011namespace pid_control
12{
13
Patrick Venture863b9242018-03-08 08:29:23 -080014/*
15 * A Sensor that can use any reader or writer you provide.
16 */
17class PluggableSensor : public Sensor
18{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070019 public:
20 PluggableSensor(const std::string& name, int64_t timeout,
21 std::unique_ptr<ReadInterface> reader,
22 std::unique_ptr<WriteInterface> writer) :
Patrick Williamsbd63bca2024-08-16 15:21:10 -040023 Sensor(name, timeout), _reader(std::move(reader)),
24 _writer(std::move(writer))
Patrick Venturea83a3ec2020-08-04 09:52:05 -070025 {}
Patrick Venture863b9242018-03-08 08:29:23 -080026
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070027 ReadReturn read(void) override;
28 void write(double value) override;
Josh Lehan2400ce42020-10-01 01:50:39 -070029 void write(double value, bool force, int64_t* written) override;
James Feist36b7d8e2018-10-05 15:39:01 -070030 bool getFailed(void) override;
Harvey Wua4270072024-05-29 16:11:13 +080031 std::string getFailReason(void) override;
Patrick Venture863b9242018-03-08 08:29:23 -080032
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070033 private:
34 std::unique_ptr<ReadInterface> _reader;
35 std::unique_ptr<WriteInterface> _writer;
Patrick Venture863b9242018-03-08 08:29:23 -080036};
Patrick Venturea0764872020-08-08 07:48:43 -070037
38} // namespace pid_control