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 | /* |
56 | * All WriteInterfaces have min/max available in case they want to error | ||||
57 | * check. | ||||
58 | */ | ||||
59 | int64_t getMin(void) | ||||
60 | { | ||||
61 | return _min; | ||||
62 | } | ||||
63 | int64_t getMax(void) | ||||
64 | { | ||||
65 | return _max; | ||||
66 | } | ||||
67 | |||||
68 | private: | ||||
69 | int64_t _min; | ||||
70 | int64_t _max; | ||||
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 71 | }; |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 72 | |
73 | } // namespace pid_control |