-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAX30100Sensor.cpp
53 lines (40 loc) · 1.23 KB
/
MAX30100Sensor.cpp
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
#include "MAX30100Sensor.h"
MAX30100Sensor *MAX30100Sensor::instance = nullptr;
void MAX30100Sensor::BeatCallback() {
instance->beat = true;
}
MAX30100Sensor::MAX30100Sensor(const char *pulseName, const char *beatName, uint8_t mode) {
pName = pulseName;
bName = beatName;
m = mode;
}
MAX30100Sensor *MAX30100Sensor::GetInstance(const char *pulseName, const char *beatName, uint8_t mode) {
static MAX30100Sensor inst(pulseName, beatName, mode);
instance = &inst;
return instance;
}
void MAX30100Sensor::Init() {
if (!pox.begin()) {
Serial.println("POX not ready!!!");
delay(50000);
}
if (m & MAX30100_BEAT) {
pox.setOnBeatDetectedCallback(BeatCallback);
}
}
void MAX30100Sensor::Sense(OSCBundle *bundle) {
pox.update();
if (m & MAX30100_PULSE) {
float heartRate = pox.getHeartRate();
uint8_t spO2 = pox.getSpO2();
bundle->add(pName).add(heartRate).add(spO2);
Serial.print("Heartrate: "); Serial.print(heartRate); Serial.print(" SpO2: "); Serial.println(spO2);
}
if (m & MAX30100_BEAT) {
if (beat) {
beat = false;
bundle->add(bName).add(1);
Serial.println("Beat ");
}
}
}