-
Notifications
You must be signed in to change notification settings - Fork 2
/
sense_env_class.h
156 lines (123 loc) · 4.06 KB
/
sense_env_class.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// sense env class
// create sensor instance
// sensor add
// max num samples
// ring buffer
// ring index
// sensor id
// sensor index
// sensor mqtt topic (temp/temp2/humidity)
// sensor i2c addr
// sensor unit
// sensor values or sensor group by type
// sensor calc
// avg
// mean
// mode
// running avg
// khalman filter
// validation/rejection/clamping
// timestamp or period reconstructor
// sensor alarms/threshholds
// offline mode/collection/logging to sd, maybe add a second buffer with long term ogging interval
// interrupt for sense_env sensor
// depencandies
// average
// statsistics
// filter
// ability to grab a sample window for deferred submission to mqtt for a series ( useful for battery operated devices or offline )
// ability to grab lastvalue as running average over subset of last n samples/n times
// ability to reject oulier values for known bad sensor values lacking error conditions
// get sensors by group/id for looping to displays etc
#ifndef sensorsdlog_h
#define sensorsdlog_h
// #include <iostream>
#include <vector>
// using namespace std;
#include <Average.h>
// Average<float> avg_a(20);
// #include <Statistic.h>
// Statistic myStats;
// vector or list of sensor objects
// group by type for sensors with many metrics
// addSensor(char* id, char* name, char* unit, T datatype);
// removeSensor(char* id);
// getSensorByID(char* id);
// vector<Statistic> sensors; // how to use a templated class here?
// collections of sensors
// T datatype
template <class T>
class sensorcollection {
private:
std::vector<Average<T>> sensors;
// sensors.resize()
uint32_t _numsamples = 20;
public:
sensorcollection();
~sensorcollection();
void begin();
void addSensor(int idx, uint8_t size);
void addSensorValue(int idx, T value);
float getSensorValue(int idx);
};
template <class T>
sensorcollection<T>::sensorcollection(){
Serial.println("sensorcollection constructor");
// testing in constructor for now
// BUT how to create many new instances and retain them in class?
// Average<T> avg_x(_numsamples); // scope this in class?, surely this will go bye bye
}
template <class T>
sensorcollection<T>::~sensorcollection(){
Serial.println("sensorcollection de-constructor");
sensors.clear();
}
template <class T>
void sensorcollection<T>::begin(){
sensors.push_back(Average<T>(_numsamples)); // use temp obj or smart pointers?
}
template <class T>
void sensorcollection<T>::addSensor(int idx, uint8_t size){
Average<T> *avg_x = new Average<T>(size);
sensors.push_back(*avg_x); // use temp obj or smart pointers?
Serial.println("added sensor: " + (String)idx);
}
template <class T>
void sensorcollection<T>::addSensorValue(int idx, T value){
sensors[idx].push(value);
}
template <class T>
float sensorcollection<T>::getSensorValue(int idx){
return sensors[idx].mean();
}
// // individual sensor log, one per value
// // or find a way to create anonymous objects, but each one might have different units so might as well keep them seperate.
// template <typename T>
// class sensordlog {
// private:
// const char* _id; // unique id of collection
// const char* _name; // name
// char* _unit; // units of values eg. ug/L
// T datatype; // template of typename of sample, float, int etc
// int _numsamples = 20; // number of samples to store in buffer
// public:
// sensordlog(); // add inializer list or use setters?
// ~sensordlog();
// // setSensorRange(T min, T max);
// // setSensorNumSamples(int numSamples);
// // getValue(char* id); // self.value()
// // getAvg(); //self.avg()
// // getMean();
// // getMode();
// // getMax();
// // getMin();
// // extended
// // pass in pointer funcs for specific library methods
// // init()
// // update()
// };
// template <class T> sensordlog<T>::sensordlog(){
// Serial.println("constructor");
// // sensors.push_back(Statistic myStats1); // ? how to use an anoymous object pointer in vector?
// }
#endif