forked from HerrRiebmann/Caravan_Leveler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeepPass.ino
50 lines (41 loc) · 1 KB
/
DeepPass.ino
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
//Original from combie
//https://forum.arduino.cc/index.php?topic=648602.msg4374622#msg4374622
template<typename DataType>
class DeepPass {
private:
const double factor;
double average;
public:
DeepPass(const double factor): factor(factor), average(0) {}
void setInitial(double value) {
average = value;
}
DataType processValue(DataType value) {
average *= 1.0 - factor;
average += factor * value;
return average;
}
DataType operator= (DataType value) {
return processValue(value);
}
DataType operator() (DataType value) {
return processValue(value);
}
DataType operator() () const
{
return average;
}
operator DataType() const
{
return average;
}
};
// 1.0/5.0 is mostly like an array with 5 lines for average measurment
DeepPass<int> deepPassX(1.0 / 5.0);
DeepPass<int> deepPassY(1.0 / 5.0);
// ------------
void InitDeepPass()
{
deepPassX.setInitial(0);
deepPassY.setInitial(0);
}