blob: f14aa2ca735e398fccac06d0635f9ca0f116d47b [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,
Potin Laie1fa8592025-08-29 15:27:08 +080022 std::unique_ptr<WriteInterface> writer,
23 bool ignoreFailIfHostOff = false) :
24 Sensor(name, timeout, ignoreFailIfHostOff), _reader(std::move(reader)),
Patrick Williamsbd63bca2024-08-16 15:21:10 -040025 _writer(std::move(writer))
Patrick Venturea83a3ec2020-08-04 09:52:05 -070026 {}
Patrick Venture863b9242018-03-08 08:29:23 -080027
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070028 ReadReturn read(void) override;
29 void write(double value) override;
Josh Lehan2400ce42020-10-01 01:50:39 -070030 void write(double value, bool force, int64_t* written) override;
James Feist36b7d8e2018-10-05 15:39:01 -070031 bool getFailed(void) override;
Harvey Wua4270072024-05-29 16:11:13 +080032 std::string getFailReason(void) override;
Patrick Venture863b9242018-03-08 08:29:23 -080033
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070034 private:
35 std::unique_ptr<ReadInterface> _reader;
36 std::unique_ptr<WriteInterface> _writer;
Patrick Venture863b9242018-03-08 08:29:23 -080037};
Patrick Venturea0764872020-08-08 07:48:43 -070038
39} // namespace pid_control