Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 3 | #include "interfaces.hpp" |
| 4 | #include "sensor.hpp" |
| 5 | |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 6 | #include <memory> |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 7 | #include <string> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 8 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 9 | namespace pid_control |
| 10 | { |
| 11 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 12 | /* |
| 13 | * A Sensor that can use any reader or writer you provide. |
| 14 | */ |
| 15 | class PluggableSensor : public Sensor |
| 16 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 17 | 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 Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 23 | {} |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 24 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 25 | ReadReturn read(void) override; |
| 26 | void write(double value) override; |
Josh Lehan | 2400ce4 | 2020-10-01 01:50:39 -0700 | [diff] [blame^] | 27 | void write(double value, bool force, int64_t* written) override; |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 28 | bool getFailed(void) override; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 29 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 30 | private: |
| 31 | std::unique_ptr<ReadInterface> _reader; |
| 32 | std::unique_ptr<WriteInterface> _writer; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 33 | }; |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 34 | |
| 35 | } // namespace pid_control |