m

Fork of MAX30100 by Eduardo Avelar

Committer:
AVELARDEV
Date:
Fri Nov 25 00:52:54 2016 +0000
Revision:
0:010b908e2187
max30100 example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AVELARDEV 0:010b908e2187 1 /*
AVELARDEV 0:010b908e2187 2 Arduino-MAX30100 oximetry / heart rate integrated sensor library
AVELARDEV 0:010b908e2187 3 Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org>
AVELARDEV 0:010b908e2187 4 This program is free software: you can redistribute it and/or modify
AVELARDEV 0:010b908e2187 5 it under the terms of the GNU General Public License as published by
AVELARDEV 0:010b908e2187 6 the Free Software Foundation, either version 3 of the License, or
AVELARDEV 0:010b908e2187 7 (at your option) any later version.
AVELARDEV 0:010b908e2187 8 This program is distributed in the hope that it will be useful,
AVELARDEV 0:010b908e2187 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
AVELARDEV 0:010b908e2187 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
AVELARDEV 0:010b908e2187 11 GNU General Public License for more details.
AVELARDEV 0:010b908e2187 12 You should have received a copy of the GNU General Public License
AVELARDEV 0:010b908e2187 13 along with this program. If not, see <http://www.gnu.org/licenses/>.
AVELARDEV 0:010b908e2187 14 */
AVELARDEV 0:010b908e2187 15
AVELARDEV 0:010b908e2187 16 #include <math.h>
AVELARDEV 0:010b908e2187 17
AVELARDEV 0:010b908e2187 18 #include "MAX30100_SpO2Calculator.h"
AVELARDEV 0:010b908e2187 19
AVELARDEV 0:010b908e2187 20 // SaO2 Look-up Table
AVELARDEV 0:010b908e2187 21 // http://www.ti.com/lit/an/slaa274b/slaa274b.pdf
AVELARDEV 0:010b908e2187 22 const uint8_t SpO2Calculator::spO2LUT[43] = {100,100,100,100,99,99,99,99,99,99,98,98,98,98,
AVELARDEV 0:010b908e2187 23 98,97,97,97,97,97,97,96,96,96,96,96,96,95,95,
AVELARDEV 0:010b908e2187 24 95,95,95,95,94,94,94,94,94,93,93,93,93,93};
AVELARDEV 0:010b908e2187 25
AVELARDEV 0:010b908e2187 26 SpO2Calculator::SpO2Calculator() :
AVELARDEV 0:010b908e2187 27 irACValueSqSum(0),
AVELARDEV 0:010b908e2187 28 redACValueSqSum(0),
AVELARDEV 0:010b908e2187 29 beatsDetectedNum(0),
AVELARDEV 0:010b908e2187 30 samplesRecorded(0),
AVELARDEV 0:010b908e2187 31 spO2(0)
AVELARDEV 0:010b908e2187 32 {
AVELARDEV 0:010b908e2187 33 }
AVELARDEV 0:010b908e2187 34
AVELARDEV 0:010b908e2187 35 void SpO2Calculator::update(float irACValue, float redACValue, bool beatDetected)
AVELARDEV 0:010b908e2187 36 {
AVELARDEV 0:010b908e2187 37 irACValueSqSum += irACValue * irACValue;
AVELARDEV 0:010b908e2187 38 redACValueSqSum += redACValue * redACValue;
AVELARDEV 0:010b908e2187 39 ++samplesRecorded;
AVELARDEV 0:010b908e2187 40
AVELARDEV 0:010b908e2187 41 if (beatDetected) {
AVELARDEV 0:010b908e2187 42 ++beatsDetectedNum;
AVELARDEV 0:010b908e2187 43 if (beatsDetectedNum == CALCULATE_EVERY_N_BEATS) {
AVELARDEV 0:010b908e2187 44 float acSqRatio = 100.0 * log(redACValueSqSum/samplesRecorded) / log(irACValueSqSum/samplesRecorded);
AVELARDEV 0:010b908e2187 45 uint8_t index = 0;
AVELARDEV 0:010b908e2187 46
AVELARDEV 0:010b908e2187 47 if (acSqRatio > 66) {
AVELARDEV 0:010b908e2187 48 index = (uint8_t)acSqRatio - 66;
AVELARDEV 0:010b908e2187 49 } else if (acSqRatio > 50) {
AVELARDEV 0:010b908e2187 50 index = (uint8_t)acSqRatio - 50;
AVELARDEV 0:010b908e2187 51 }
AVELARDEV 0:010b908e2187 52 reset();
AVELARDEV 0:010b908e2187 53
AVELARDEV 0:010b908e2187 54 spO2 = spO2LUT[index];
AVELARDEV 0:010b908e2187 55 }
AVELARDEV 0:010b908e2187 56 }
AVELARDEV 0:010b908e2187 57 }
AVELARDEV 0:010b908e2187 58
AVELARDEV 0:010b908e2187 59 void SpO2Calculator::reset()
AVELARDEV 0:010b908e2187 60 {
AVELARDEV 0:010b908e2187 61 samplesRecorded = 0;
AVELARDEV 0:010b908e2187 62 redACValueSqSum = 0;
AVELARDEV 0:010b908e2187 63 irACValueSqSum = 0;
AVELARDEV 0:010b908e2187 64 beatsDetectedNum = 0;
AVELARDEV 0:010b908e2187 65 spO2 = 0;
AVELARDEV 0:010b908e2187 66 }
AVELARDEV 0:010b908e2187 67
AVELARDEV 0:010b908e2187 68 uint8_t SpO2Calculator::getSpO2()
AVELARDEV 0:010b908e2187 69 {
AVELARDEV 0:010b908e2187 70 return spO2;
AVELARDEV 0:010b908e2187 71 }