-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathMAX30100_PulseOximeter.h
84 lines (69 loc) · 2.5 KB
/
MAX30100_PulseOximeter.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
/*
Arduino-MAX30100 oximetry / heart rate integrated sensor library
Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAX30100_PULSEOXIMETER_H
#define MAX30100_PULSEOXIMETER_H
#define SAMPLING_FREQUENCY 100
#define CURRENT_ADJUSTMENT_PERIOD_MS 500
#define DEFAULT_IR_LED_CURRENT MAX30100_LED_CURR_50MA
#define RED_LED_CURRENT_START MAX30100_LED_CURR_27_1MA
#define DC_REMOVER_ALPHA 0.95
#include <stdint.h>
#include "MAX30100.h"
#include "MAX30100_BeatDetector.h"
#include "MAX30100_Filters.h"
#include "MAX30100_SpO2Calculator.h"
typedef enum PulseOximeterState {
PULSEOXIMETER_STATE_INIT,
PULSEOXIMETER_STATE_IDLE,
PULSEOXIMETER_STATE_DETECTING
} PulseOximeterState;
typedef enum PulseOximeterDebuggingMode {
PULSEOXIMETER_DEBUGGINGMODE_NONE,
PULSEOXIMETER_DEBUGGINGMODE_RAW_VALUES,
PULSEOXIMETER_DEBUGGINGMODE_AC_VALUES,
PULSEOXIMETER_DEBUGGINGMODE_PULSEDETECT
} PulseOximeterDebuggingMode;
class PulseOximeter {
public:
PulseOximeter();
bool begin(PulseOximeterDebuggingMode debuggingMode_=PULSEOXIMETER_DEBUGGINGMODE_NONE);
void update();
float getHeartRate();
uint8_t getSpO2();
uint8_t getRedLedCurrentBias();
void setOnBeatDetectedCallback(void (*cb)());
void setIRLedCurrent(LEDCurrent irLedCurrent);
void shutdown();
void resume();
private:
void checkSample();
void checkCurrentBias();
PulseOximeterState state;
PulseOximeterDebuggingMode debuggingMode;
uint32_t tsFirstBeatDetected;
uint32_t tsLastBeatDetected;
uint32_t tsLastBiasCheck;
uint32_t tsLastCurrentAdjustment;
BeatDetector beatDetector;
DCRemover irDCRemover;
DCRemover redDCRemover;
FilterBuLp1 lpf;
uint8_t redLedCurrentIndex;
LEDCurrent irLedCurrent;
SpO2Calculator spO2calculator;
MAX30100 hrm;
void (*onBeatDetected)();
};
#endif