upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
max30100.hpp
1 /*
2  * Author: Noel Eck <noel.eck@intel.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include <iostream>
28 
29 #include "mraa/i2c.h"
30 #include "max30100.h"
31 
32 namespace upm {
33 
34 /* Callback class for continuously reading samples */
35 class Callback {
36  public:
37  virtual ~Callback() { }
38  /* Default run method, called for each new sample in continous
39  * sampling mode.
40  * Override this method */
41  virtual void run(max30100_value samp)
42  { std::cout << "Base sample IR: " << samp.IR << " R: " << samp.R << std::endl; }
43 };
44 
76 class MAX30100 {
77  public:
87  MAX30100(int16_t i2c_bus);
88 
92  virtual ~MAX30100() {};
93 
103  max30100_value sample();
104 
129  void sample_continuous(int gpio_pin, bool buffered, Callback *cb = NULL);
130 
134  void sample_stop();
135 
142  uint8_t read(MAX30100_REG reg);
143 
150  void write(MAX30100_REG reg, uint8_t wr_data);
151 
165  uint16_t version();
166 
172  float temperature();
173 
180  void mode(MAX30100_MODE mode);
181 
188  MAX30100_MODE mode();
189 
197  void high_res_enable(bool enable);
198 
205  bool high_res_enable();
206 
213  void sample_rate(MAX30100_SR sample_rate);
214 
221  MAX30100_SR sample_rate();
222 
229  void pulse_width(MAX30100_LED_PW pulse_width);
230 
237  MAX30100_LED_PW pulse_width();
238 
246  void current(MAX30100_LED_CURRENT ir, MAX30100_LED_CURRENT r);
247 
253  MAX30100_LED_CURRENT current_ir();
254 
260  MAX30100_LED_CURRENT current_r();
261 
274  void reset();
275 
284  void sleep(bool sleep);
285 
286  /* Callback pointer available for a user-specified callback */
287  Callback *_callback;
288  private:
289  /* base Callback instance to use if none provided */
290  Callback _default_callback;
291 
292  /* device context struct */
293  max30100_context* _dev;
294 };
295 }
virtual ~MAX30100()
Definition: max30100.hpp:92
Definition: max30100.h:51
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
Definition: max30100_regs.h:36
API for the Pulse oximeter and heart-rate sensor.
Definition: max30100.hpp:76
C API for the Pulse oximeter and heart-rate sensor.
Definition: max30100.hpp:35