-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMapSensor.h
75 lines (60 loc) · 1.66 KB
/
MapSensor.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
72
73
74
75
/**
MapSensor - class-wrapper allows to map
a signal value of origin Sensor instance.
Re-maps the signal from one range to another.
That is, a signal of fromLow would get mapped to toLow,
a signal of fromHigh to toHigh, signals in-between to signals in-between, etc.
Instantiation:
Sensor* mapSensor = new MapSensor(
SENSOR,
FROM_LOW, FROM_HIGH,
TO_LOW, TO_HIGH,
);
Where,
SENSOR - origin Sensor instance.
FROM_LOW - the lower bound of the value’s CURRENT range
FROM_HIGH - the upper bound of the value’s CURRENT range
TO_LOW - the lower bound of the value’s TARGET range
TO_HIGH - the upper bound of the value’s TARGET range
Read signal:
int value = mapSensor->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 MAP_SENSOR_H
#define MAP_SENSOR_H
#include "Sensor.h"
class MapSensor final : public Sensor {
private:
Sensor* origin;
int fromLow;
int fromHigh;
int toLow;
int toHigh;
public:
/**
Constructor
@param origin - the origin sensor (not NULL)
@param fromLow - the lower bound of the value’s current range
@param fromHigh - the upper bound of the value’s current range
@param toLow - the lower bound of the value’s target range
@param toHigh - the upper bound of the value’s target range
*/
MapSensor(
Sensor* origin,
int fromLow, int fromHigh,
int toLow, int toHigh
);
~MapSensor();
/**
Reads a signal from a origin sensor,
maps the signal and return it.
@return the mapped signal value.
*/
int read() override;
};
#endif