-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesh_sensor_.cpp
More file actions
111 lines (83 loc) · 2.99 KB
/
mesh_sensor_.cpp
File metadata and controls
111 lines (83 loc) · 2.99 KB
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
#include "mesh_sensor_.h"
#include "mesh_.h"
/* * * * * * * * * * * * * * * * * * * * * * * *
VIRTUAL: Functions defined by child
* * * * * * * * * * * * * * * * * * * * * * * */
MeshSensorCtrl::MeshSensorCtrl() {}
void MeshSensorCtrl::initialize() {}
String MeshSensorCtrl::sample() {}
/* * * * * * * * * * * * * * * * * * * * * * * *
COMMAND: Awake mode
* * * * * * * * * * * * * * * * * * * * * * * */
void MeshSensorCtrl::awake() {
_controlState = _STATE_AWAKE;
}
/* * * * * * * * * * * * * * * * * * * * * * * *
COMMAND: Sleep mode - power conservation
* * * * * * * * * * * * * * * * * * * * * * * */
void MeshSensorCtrl::sleep() {
_controlState = _STATE_SLEEPING;
}
/* * * * * * * * * * * * * * * * * * * * * * * *
COMMAND: Read state
* * * * * * * * * * * * * * * * * * * * * * * */
int MeshSensorCtrl::getControlState() {
return _controlState;
}
/* * * * * * * * * * * * * * * * * * * * * * * *
COMMAND: Sensor data reading format
* * * * * * * * * * * * * * * * * * * * * * * */
String MeshSensorCtrl::getDataFormat() {
return _DATA_FRAME_FORMAT;
}
/* * * * * * * * * * * * * * * * * * * * * * * *
COMMAND: Control version
* * * * * * * * * * * * * * * * * * * * * * * */
String MeshSensorCtrl::getSensorName() {
return _SENSOR_NAME;
}
/* * * * * * * * * * * * * * * * * * * * * * * *
COMMAND: Control version
* * * * * * * * * * * * * * * * * * * * * * * */
uint8_t MeshSensorCtrl::getVersion() {
return _SENSOR_VERSION;
}
// /* * * * * * * * * * * * * * * * * * * * * * * *
// UTIL: Labels for sensors
// * * * * * * * * * * * * * * * * * * * * * * * */
static String MeshSensorCtrl::getSensorLabels(String sensorName) {
if (sensorName == "ac") return "Ax"+MeshOS::getIntraDataSplitter()+"Ay"+MeshOS::getIntraDataSplitter()+"Az";
else if (sensorName == "gy") return "Gx"+MeshOS::getIntraDataSplitter()+"Gy"+MeshOS::getIntraDataSplitter()+"Gz";
else if (sensorName == "hu") return "H";
else if (sensorName == "li") return "L";
else if (sensorName == "rf") return "R";
else if (sensorName == "te") return "T";
else return "-";
}
// /* * * * * * * * * * * * * * * * * * * * * * * *
// UTIL: Given a set of floats conver to a string
// * * * * * * * * * * * * * * * * * * * * * * * */
static String MeshSensorCtrl::stringifyFloatDataset(float* dataset) {
uint8_t lengthOfDataSet = sizeof(dataset);
String valueString = "";
String intraDataSplitter = MeshOS::getIntraDataSplitter();
for (int i = 0; i < lengthOfDataSet; i++) {
String buff = "-";
if (!isnan(dataset[i])) {
buff = MeshSensorCtrl::_floatToStringConversion(dataset[i]);
}
valueString += buff;
if(i < lengthOfDataSet-1) {
valueString += intraDataSplitter;
}
}
return valueString;
}
// /* * * * * * * * * * * * * * * * * * * * * * * *
// UTIL: convert the float to the string
// * * * * * * * * * * * * * * * * * * * * * * * */
static String MeshSensorCtrl::_floatToStringConversion(float tempVar) {
char buf[10];
dtostrf(tempVar, 4, 2, buf);
return buf;
}