Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <chrono> |
| 4 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 5 | namespace pid_control |
| 6 | { |
| 7 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 8 | struct ReadReturn |
| 9 | { |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 10 | double value; |
| 11 | std::chrono::high_resolution_clock::time_point updated; |
Patrick Venture | bd6b476 | 2018-06-14 09:24:42 -0700 | [diff] [blame] | 12 | |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 13 | bool operator==(const ReadReturn& rhs) const |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 14 | { |
Patrick Venture | bd6b476 | 2018-06-14 09:24:42 -0700 | [diff] [blame] | 15 | return (this->value == rhs.value && this->updated == rhs.updated); |
| 16 | } |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 17 | }; |
| 18 | |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 19 | /* |
| 20 | * A ReadInterface is a plug-in for the PluggableSensor and anyone implementing |
| 21 | * this basically is providing a way to read a sensor. |
| 22 | */ |
| 23 | class ReadInterface |
| 24 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 25 | public: |
| 26 | ReadInterface() |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 27 | {} |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 28 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 29 | virtual ~ReadInterface() |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 30 | {} |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 31 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 32 | virtual ReadReturn read(void) = 0; |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 33 | |
| 34 | virtual bool getFailed(void) const |
| 35 | { |
| 36 | return false; |
| 37 | } |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /* |
| 41 | * A WriteInterface is a plug-in for the PluggableSensor and anyone implementing |
| 42 | * this basically is providing a way to write a sensor. |
| 43 | */ |
| 44 | class WriteInterface |
| 45 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 46 | public: |
| 47 | WriteInterface(int64_t min, int64_t max) : _min(min), _max(max) |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 48 | {} |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 49 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 50 | virtual ~WriteInterface() |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 51 | {} |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 52 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 53 | virtual void write(double value) = 0; |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 54 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 55 | /* |
Josh Lehan | 2400ce4 | 2020-10-01 01:50:39 -0700 | [diff] [blame^] | 56 | * A wrapper around write(), with additional parameters. |
| 57 | * force = true to perform redundant write, even if raw value unchanged. |
| 58 | * written = non-null to be filled in with the actual raw value written. |
| 59 | */ |
| 60 | virtual void write(double value, bool force, int64_t* written) |
| 61 | { |
| 62 | (void)force; |
| 63 | (void)written; |
| 64 | return write(value); |
| 65 | } |
| 66 | |
| 67 | /* |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 68 | * All WriteInterfaces have min/max available in case they want to error |
| 69 | * check. |
| 70 | */ |
| 71 | int64_t getMin(void) |
| 72 | { |
| 73 | return _min; |
| 74 | } |
| 75 | int64_t getMax(void) |
| 76 | { |
| 77 | return _max; |
| 78 | } |
| 79 | |
| 80 | private: |
| 81 | int64_t _min; |
| 82 | int64_t _max; |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 83 | }; |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 84 | |
| 85 | } // namespace pid_control |