upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
pulsensor.h
1 /*
2  * Author: Andrei Vasiliu <andrei.vasiliu@intel.com>
3  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
4  * Copyright (c) 2015 Intel Corporation.
5  *
6  * Credits to Adafruit.
7  * Based on Adafruit BMP085 library.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 #pragma once
29 
30 #include <string>
31 #include <math.h>
32 #include <mraa/pwm.hpp>
33 #include <mraa/aio.hpp>
34 #include <mraa/gpio.hpp>
35 #include <pthread.h>
36 
37 #define HIGH 1
38 #define LOW 0
39 
40 #define TRUE HIGH
41 #define FALSE LOW
42 
71 struct clbk_data {
73 };
74 
75 
76 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
77 #include "Callback.h"
78 #else
79 typedef void (* callback_handler) (clbk_data);
80 #endif
81 
86 class Pulsensor {
87 
88 public:
89 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
90  Pulsensor(Callback *callback);
91 #else
92  Pulsensor(callback_handler handler);
93 #endif
94  void start_sampler();
95  void stop_sampler();
96 
97 private:
98  static void *do_sample(void *arg);
99  pthread_t sample_thread;
100  uint32_t sample_counter;
101  uint32_t last_beat_time;
102  int threshold;
103  int ibi_rate[10];
104  int ibi;
105  int trough;
106  int peak;
107  int bpm;
108  int apmlitude;
109  uint8_t qs;
110  uint8_t is_pulse;
111  uint8_t first_beat;
112  uint8_t second_beat;
113  uint8_t pin;
114  uint8_t ret;
115  mraa::Aio pin_ctx;
116 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
117  Callback *obj_callback;
118 #else
119  callback_handler callback;
120 #endif
121  volatile uint16_t ctx_counter;
122 };
123 
The context for the heartbeat pulse sensor.
Definition: pulsensor.h:86
C++ API for the 3-Wire Pulse Sensor.
Definition: pulsensor.h:71
int is_heart_beat
Definition: pulsensor.h:72