-
Notifications
You must be signed in to change notification settings - Fork 22
/
sensor.hpp
69 lines (56 loc) · 1.42 KB
/
sensor.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include "interfaces.hpp"
#include <string>
namespace pid_control
{
/**
* Abstract base class for all sensors.
*/
class Sensor
{
public:
/**
* Given a sensor's type, return the default timeout value.
* A timeout of 0 means there isn't a timeout for this sensor.
* By default a fan sensor isn't checked for a timeout, whereas
* any of sensor is meant to be sampled once per second. By default.
*
* @param[in] type - the sensor type (e.g. fan)
* @return the default timeout for that type (in seconds).
*/
static int64_t getDefaultTimeout(const std::string& type)
{
return (type == "fan") ? 0 : 2;
}
Sensor(const std::string& name, int64_t timeout) :
_name(name), _timeout(timeout)
{}
virtual ~Sensor() {}
virtual ReadReturn read(void) = 0;
virtual void write(double value) = 0;
virtual void write(double value, bool force, int64_t* written)
{
(void)force;
(void)written;
return write(value);
}
virtual bool getFailed(void)
{
return false;
};
std::string getName(void) const
{
return _name;
}
/* Returns the configurable timeout period
* for this sensor in seconds (undecorated).
*/
int64_t getTimeout(void) const
{
return _timeout;
}
private:
std::string _name;
int64_t _timeout;
};
} // namespace pid_control