blob: 8ec474b80d3d7c3d40ba179e5947e3924d294244 [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 /*
Josh Lehan2400ce42020-10-01 01:50:39 -070056 * 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 Ventureda4a5dd2018-08-31 09:42:48 -070068 * 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 Venturee6206562018-03-08 15:36:53 -080083};
Patrick Venturea0764872020-08-08 07:48:43 -070084
85} // namespace pid_control