-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConstrainSensor.h
71 lines (56 loc) · 1.51 KB
/
ConstrainSensor.h
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
70
71
/**
ConstrainSensor - class-wrapper allows to constraint
a signal value of origin Sensor instance.
Instantiation:
Sensor* constrainSensor = new ConstrainSensor(
SENSOR, LOW, HIGH
);
Where,
SENSOR - origin Sensor instance.
LOW - the lower end of the constraint range.
HIGH - the upper end of the constraint range.
Read signal:
int value = constrainSensor->read();
v.1.3.3
- optimized read() method;
- updated documentation.
https://github.com/YuriiSalimov/AD_Sensors
Created by Yurii Salimov, May, 2018.
Released into the public domain.
*/
#ifndef CONSTRAIN_SENSOR_H
#define CONSTRAIN_SENSOR_H
#include "Sensor.h"
class ConstrainSensor final : public Sensor {
private:
Sensor* origin;
int low;
int high;
public:
/**
Constructor
@param origin - the origin sensor (not NULL)
@param low - the lower end of the constraint range
@param high - the upper end of the constraint range
*/
ConstrainSensor(Sensor* origin, int low, int high);
/**
Destructor
Deletes the origin Sensor instance.
*/
~ConstrainSensor();
/**
Reads a signal from the origin sensor,
constrains the signal and return it.
Example,
x = the sensor signal;
a = low end of the constraint range;
b = high end of the constraint range.
@return the constrained signal value:
x: if x is between a and b;
a: if x is less than a;
b: if x is greater than b.
*/
int read() override;
};
#endif