blob: b4b236bf7ddb38de0307c22a6ad7948026b7ce24 [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001#pragma once
2
3#include <chrono>
4
Patrick Venturea0764872020-08-08 07:48:43 -07005namespace pid_control
6{
7
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07008struct ReadReturn
9{
Patrick Venturee6206562018-03-08 15:36:53 -080010 double value;
11 std::chrono::high_resolution_clock::time_point updated;
Patrick Venturebd6b4762018-06-14 09:24:42 -070012
Patrick Venturee2ec0f62018-09-04 12:30:27 -070013 bool operator==(const ReadReturn& rhs) const
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070014 {
Patrick Venturebd6b4762018-06-14 09:24:42 -070015 return (this->value == rhs.value && this->updated == rhs.updated);
16 }
Patrick Venturee6206562018-03-08 15:36:53 -080017};
18
Patrick Venturee6206562018-03-08 15:36:53 -080019/*
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 */
23class ReadInterface
24{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025 public:
26 ReadInterface()
Patrick Venturea83a3ec2020-08-04 09:52:05 -070027 {}
Patrick Venturee6206562018-03-08 15:36:53 -080028
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070029 virtual ~ReadInterface()
Patrick Venturea83a3ec2020-08-04 09:52:05 -070030 {}
Patrick Venturee6206562018-03-08 15:36:53 -080031
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070032 virtual ReadReturn read(void) = 0;
James Feist36b7d8e2018-10-05 15:39:01 -070033
34 virtual bool getFailed(void) const
35 {
36 return false;
37 }
Patrick Venturee6206562018-03-08 15:36:53 -080038};
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 */
44class WriteInterface
45{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070046 public:
47 WriteInterface(int64_t min, int64_t max) : _min(min), _max(max)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070048 {}
Patrick Venturee6206562018-03-08 15:36:53 -080049
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070050 virtual ~WriteInterface()
Patrick Venturea83a3ec2020-08-04 09:52:05 -070051 {}
Patrick Venturee6206562018-03-08 15:36:53 -080052
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070053 virtual void write(double value) = 0;
Patrick Venturee6206562018-03-08 15:36:53 -080054
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070055 /*
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 Venturee6206562018-03-08 15:36:53 -080071};
Patrick Venturea0764872020-08-08 07:48:43 -070072
73} // namespace pid_control