max30100: Initial commit - MAX30100 pulse oximeter

* c/c++ source
    * java/js/python/c/c++ examples
    * Doc image (png)
    * Tested on Intel Edison
    * TODO: Tuning for SpO2 reading

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2016-12-08 15:24:36 -08:00
parent 6ea65a16a4
commit bd47b9ed45
19 changed files with 2133 additions and 0 deletions

View File

@ -328,6 +328,7 @@ add_example (mb704x)
add_example (rf22-server)
add_example (rf22-client)
add_example (mcp2515)
add_example (max30100)
# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)

99
examples/c++/max30100.cxx Normal file
View File

@ -0,0 +1,99 @@
/*
* Author: Noel Eck <noel.eck@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "max30100.hpp"
using namespace upm;
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
// Example Callback handler
class mycallback : public Callback
{
public:
virtual void run(max30100_value samp)
{
std::cout << "My callback sample IR: "
<< samp.IR << " R: " << samp.R << std::endl;
}
};
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a MAX30100 instance using i2c bus 0
upm::MAX30100 sensor(0);
// Create an instance of the Callback class
mycallback cb;
// Read the temperature and version
std::cout << "Temperature: " << sensor.temperature() << " C" << std::endl;
std::cout << "Version: " << sensor.version() << std::endl;
// Set high-res (50 Hz, 16-bit)
sensor.high_res_enable(true);
// Set to sample SpO2
sensor.mode(MAX30100_MODE_SPO2_EN);
// Read continuously, stepping up the LED current every second,
// us GPIO 0 as the interrupt pin
sensor.sample_continuous(0, false, &cb);
for (int i = MAX30100_LED_CURRENT_0_0_MA;
i <= MAX30100_LED_CURRENT_50_0_MA && shouldRun; i++)
{
// Toggle the LED current
std::cout << "Setting LED current = " << i << std::endl;
sensor.current((MAX30100_LED_CURRENT)i, (MAX30100_LED_CURRENT)i);
upm_delay(1);
}
// Read individual samples
for (int i = 0; i < 10; i++)
{
max30100_value val = sensor.sample();
std::cout << "Single value IR: " << val.IR << " R: " << val.R << std::endl;
}
//! [Interesting]
std::cout << "Exiting..." << std::endl;
return 0;
}

View File

@ -142,6 +142,7 @@ add_example (ims)
add_example (ecezo)
add_example (mb704x)
add_example (mcp2515)
add_example (max30100)
# Custom examples
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)

130
examples/c/max30100.c Normal file
View File

@ -0,0 +1,130 @@
/*
* Author: Noel Eck <noel.eck@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include "max30100.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
void my_sample_handler(max30100_value sample, void* arg)
{
printf("My callback sample IR: %d R: %d\n",
sample.IR, sample.R);
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
max30100_context* sensor = max30100_init(0);
if (!sensor)
{
printf("max30100_init() failed\n");
return -1;
}
/* Get the temperature */
float temp;
if (max30100_get_temperature(sensor, &temp) != UPM_SUCCESS)
{
printf("max30100_get_temperature failed\n");
goto max30100_exit;
}
/* Get the version */
uint16_t version;
if (max30100_get_version(sensor, &version) != UPM_SUCCESS)
{
printf("max30100_get_version failed\n");
goto max30100_exit;
}
printf("Temperature: %f C\n", temp);
printf("Version: 0x%04x\n", version);
/* Set high-res (50 Hz, 16-bit) */
if (max30100_set_high_res(sensor, true) != UPM_SUCCESS)
{
printf("max30100_set_high_res failed\n");
goto max30100_exit;
}
/* Set to sample SpO2 */
if (max30100_set_mode(sensor, MAX30100_MODE_SPO2_EN) != UPM_SUCCESS)
{
printf("max30100_set_mode failed\n");
goto max30100_exit;
}
/* Read continuously, stepping up the LED current every second,
* us GPIO 0 as the interrupt pin */
max30100_sample_continuous(sensor, 0, false, &my_sample_handler, sensor);
for (int i = MAX30100_LED_CURRENT_0_0_MA;
i <= MAX30100_LED_CURRENT_50_0_MA && shouldRun; i++)
{
/* Toggle the LED current */
printf("Setting LED current = %d\n", i);
if ( max30100_set_current(sensor, (MAX30100_LED_CURRENT)i,
(MAX30100_LED_CURRENT)i) != UPM_SUCCESS )
{
printf("max30100_set_current failed\n");
goto max30100_exit;
}
upm_delay(1);
}
/* Read individual samples */
for (int i = 0; i < 10; i++)
{
max30100_value samp;
if (max30100_sample(sensor, &samp) != UPM_SUCCESS)
{
printf("max30100_sample failed\n");
goto max30100_exit;
}
printf("Single value IR: %d R: %d\n", samp.IR, samp.R);
}
max30100_exit:
//! [Interesting]
printf("Exiting\n");
max30100_close(sensor);
return 0;
}

View File

@ -162,6 +162,7 @@ add_example(IMS_Example ims)
add_example(MB704X_Example mb704x)
add_example(MCP2515_Example mcp2515)
add_example(Ads1015Sample ads1x15)
add_example(MAX30100_Example max30100)
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
add_example_with_path(Jhd1313m1Sample lcd i2clcd)

View File

@ -0,0 +1,88 @@
/*
* Author: Noel Eck <noel.eck@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_max30100.*;
public class MAX30100_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
// Instantiate a MAX30100 instance using bus 0
MAX30100 sensor = new MAX30100((short)0);
System.out.println("Oximeter sensor example...");
// Read the temperature and version
System.out.format("Temperature: %f C\n", sensor.temperature());
System.out.format("Version: 0x%04x\n", sensor.version());
// Set high-res (50 Hz, 16-bit)
sensor.high_res_enable(true);
// Set to sample SpO2
sensor.mode(MAX30100_MODE.MAX30100_MODE_SPO2_EN);
Callback cb = new JavaCallback();
// Read continuously, stepping up the LED current every second,
// us GPIO 0 as the interrupt pin
sensor.sample_continuous(0, false, cb);
for (int i = 0; i <= 15; i++)
{
// Toggle the LED current
System.out.format("Setting LED current = %d\n", i);
sensor.current(MAX30100_LED_CURRENT.swigToEnum(i),
MAX30100_LED_CURRENT.swigToEnum(i));
Thread.sleep(1000);
}
sensor.sample_stop();
// Read individual samples
for (int i = 0; i < 10; i++) {
max30100_value val = sensor.sample();
System.out.format("Single value IR: %d R: %d\n", val.getIR(), val.getR());
}
// ! [Interesting]
}
}
class JavaCallback extends Callback
{
public JavaCallback()
{
super();
}
public void run(max30100_value val)
{
System.out.format("My callback sample IR: %d R: %d\n", val.getIR(), val.getR());
}
}

View File

@ -0,0 +1,57 @@
/*
* Author: Noel Eck <noel.eck@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_max30100');
// Instantiate a MAX30100 instance using bus 0
var sensor = new sensorObj.MAX30100(0);
console.log('Oximeter sensor example...');
// Read the temperature and version
console.log ('Temperature: %d C', sensor.temperature());
console.log ('Version: 0x%s', sensor.version().toString(16));
// Set high-res (50 Hz, 16-bit)
sensor.high_res_enable(true);
// Set to sample SpO2
sensor.mode(sensorObj.MAX30100_MODE_SPO2_EN);
// Read individual samples
for (var i = 0; i < 10; i++)
{
var val = sensor.sample();
console.log('Single value IR: %d R: %d ', val.IR, val.R);
}
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log('Exiting.');
process.exit(0);
});

71
examples/python/max30100.py Executable file
View File

@ -0,0 +1,71 @@
#!/usr/bin/python
# Author: Noel Eck <noel.eck@intel.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_max30100
# Callback class derived from CXX Callback
class mycallback(pyupm_max30100.Callback):
def __init__(self):
self.count = 0
pyupm_max30100.Callback.__init__(self)
def run(self, samp):
print("My callback sample IR: %d R: %d" % (samp.IR, samp.R))
def main():
# Create an instance of the oximiter
# I2C bus 0
x = pyupm_max30100.MAX30100(0)
print ('Oximeter sensor example...')
# Create an instance of the mycallback class
cb = mycallback().__disown__()
# Read the temperature and version
print ("Temperature: %d C" % x.temperature())
print ("Version: 0x%04x" % x.version())
# Set high-res (50 Hz, 16-bit)
x.high_res_enable(True)
# Set to sample SpO2
x.mode(pyupm_max30100.MAX30100_MODE_SPO2_EN);
# Read continuously, stepping up the LED current every second,
# us GPIO 0 as the interrupt pin
x.sample_continuous(0, False, cb)
for i in range(16):
print("Setting LED current = %d" % i)
x.current(i, i)
time.sleep(1)
# Read individual samples
for i in range(10):
val = x.sample();
print("Single value IR: %d R: %d " % (val.IR, val.R))
if __name__ == '__main__':
main()