1 #pragma once
2 
3 #include <chrono>
4 
5 namespace pid_control
6 {
7 
8 struct ReadReturn
9 {
10     double value;
11     std::chrono::high_resolution_clock::time_point updated;
12 
13     bool operator==(const ReadReturn& rhs) const
14     {
15         return (this->value == rhs.value && this->updated == rhs.updated);
16     }
17 };
18 
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 {
25   public:
26     ReadInterface()
27     {}
28 
29     virtual ~ReadInterface()
30     {}
31 
32     virtual ReadReturn read(void) = 0;
33 
34     virtual bool getFailed(void) const
35     {
36         return false;
37     }
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 {
46   public:
47     WriteInterface(int64_t min, int64_t max) : _min(min), _max(max)
48     {}
49 
50     virtual ~WriteInterface()
51     {}
52 
53     virtual void write(double value) = 0;
54 
55     /*
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     /*
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;
83 };
84 
85 } // namespace pid_control
86