-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsensorFunctions.ino
78 lines (66 loc) · 1.88 KB
/
sensorFunctions.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
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
void handleDistance() {
dist_l = sonarA.ping_cm();
if (dist_l == 0) {
dist_l = 400;
}
// if (dist_l < 150) {
// if (!recording) {
// if (currentTime - last > 1000) {
// Serial.print("Ueberholmanöver entdeckt: ");
// Serial.println(dist_l);
// last = millis();
// recording = true;
// SenseBoxBLE::write(distanceCharacteristic, dist_l);
// Serial.print(dist_l);
// }
// }
// }
// if (dist_l > 150 && recording) {
// if (recording) {
// Serial.print("Ueberholmanoever vorbei: ");
// Serial.println(dist_l);
// }
// recording = false;
// }
}
void callSPS() {
//struct sps30_measurement m;
char serial[SPS30_MAX_SERIAL_LEN];
uint16_t data_ready;
int16_t ret;
do {
ret = sps30_read_data_ready(&data_ready);
if (ret < 0) {
Serial.print("error reading data-ready flag: ");
Serial.println(ret);
} else if (!data_ready)
Serial.print("data not ready, no new measurement available\n");
else
break;
delay(100); /* retry in 100ms */
} while (1);
ret = sps30_read_measurement(&m);
if (ret < 0) {
Serial.print("error reading measurement\n");
}
}
void getAccAmplitudes(float *sumAccX, float *sumAccY, float *sumAccZ) {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
// Acceleration Amplitude calc
float amplitudeAccX = accX - a.acceleration.x;
float amplitudeAccY = accY - a.acceleration.y;
float amplitudeAccZ = accZ - a.acceleration.z;
accX = a.acceleration.x;
accY = a.acceleration.y;
accZ = a.acceleration.z;
if (abs(amplitudeAccX) > 0.05) {
*sumAccX += abs(amplitudeAccX);
}
if (abs(amplitudeAccY) > 0.05) {
*sumAccY += abs(amplitudeAccY);
}
if (abs(amplitudeAccZ) > 0.05) {
*sumAccZ += abs(amplitudeAccZ);
}
};