port oxullo library Arduino

Dependents:   MAX30100_oxullo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX30100_PulseOximeter.h Source File

MAX30100_PulseOximeter.h

00001 /*
00002 Arduino-MAX30100 oximetry / heart rate integrated sensor library
00003 Copyright (C) 2016  OXullo Intersecans <x@brainrapers.org>
00004 This program is free software: you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation, either version 3 of the License, or
00007 (at your option) any later version.
00008 This program is distributed in the hope that it will be useful,
00009 but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 GNU General Public License for more details.
00012 You should have received a copy of the GNU General Public License
00013 along with this program.  If not, see <http://www.gnu.org/licenses/>.
00014 */
00015 
00016 #ifndef MAX30100_PULSEOXIMETER_H
00017 #define MAX30100_PULSEOXIMETER_H
00018 
00019 #define SAMPLING_FREQUENCY                  100
00020 #define CURRENT_ADJUSTMENT_PERIOD_MS        500
00021 #define IR_LED_CURRENT                      MAX30100_LED_CURR_50MA
00022 #define RED_LED_CURRENT_START               MAX30100_LED_CURR_27_1MA
00023 #define DC_REMOVER_ALPHA                    0.95
00024 
00025 #include <stdint.h>
00026 #include <vector>
00027 
00028 
00029 #include "MAX30100.h"
00030 #include "MAX30100_BeatDetector.h"
00031 #include "MAX30100_Filters.h"
00032 #include "MAX30100_SpO2Calculator.h"
00033 
00034 typedef enum PulseOximeterState {
00035     PULSEOXIMETER_STATE_INIT,
00036     PULSEOXIMETER_STATE_IDLE,
00037     PULSEOXIMETER_STATE_DETECTING
00038 } PulseOximeterState;
00039 
00040 typedef enum PulseOximeterDebuggingMode {
00041     PULSEOXIMETER_DEBUGGINGMODE_NONE,
00042     PULSEOXIMETER_DEBUGGINGMODE_RAW_VALUES,
00043     PULSEOXIMETER_DEBUGGINGMODE_AC_VALUES,
00044     PULSEOXIMETER_DEBUGGINGMODE_PULSEDETECT
00045 } PulseOximeterDebuggingMode;
00046 
00047 
00048 class PulseOximeter {
00049 public:
00050     PulseOximeter();
00051 
00052     bool begin(PulseOximeterDebuggingMode debuggingMode_=PULSEOXIMETER_DEBUGGINGMODE_NONE);
00053     void update();
00054     float getHeartRate();
00055     uint8_t getSpO2();
00056     uint8_t getRedLedCurrentBias();
00057     void setOnBeatDetectedCallback(void (*cb)());
00058 
00059 private:
00060     void checkSample();
00061     void checkCurrentBias();
00062 
00063     PulseOximeterState state;
00064     PulseOximeterDebuggingMode debuggingMode;
00065 //    uint32_t tsFirstBeatDetected;
00066 //    uint32_t tsLastBeatDetected;
00067 //    uint32_t tsLastSample;
00068 //    uint32_t tsLastBiasCheck;
00069 //    uint32_t tsLastCurrentAdjustment;
00070     BeatDetector beatDetector;
00071     DCRemover irDCRemover;
00072     DCRemover redDCRemover;
00073     FilterBuLp1 lpf;
00074     uint8_t redLedPower;
00075     SpO2Calculator spO2calculator;
00076     
00077     MAX30100 hrm;
00078 
00079     void (*onBeatDetected)();
00080     Timer t_Sample;
00081     Timer t_CurrentBias;
00082 };
00083 #endif