upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
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 
46 struct clbk_data {
48 };
49 
50 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
51 #include "Callback.h"
52 #else
53 typedef void (* callback_handler) (clbk_data);
54 #endif
55 
56 namespace upm {
80 class Pulsensor {
81 
82 public:
83 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
84  Pulsensor(Callback *callback);
85 #else
86  Pulsensor(callback_handler handler);
87 #endif
88  void start_sampler();
89  void stop_sampler();
90 
91 private:
92  static void *do_sample(void *arg);
93  pthread_t sample_thread;
94  uint32_t sample_counter;
95  uint32_t last_beat_time;
96  int threshold;
97  int ibi_rate[10];
98  int ibi;
99  int trough;
100  int peak;
101  int bpm;
102  int apmlitude;
103  uint8_t qs;
104  uint8_t is_pulse;
105  uint8_t first_beat;
106  uint8_t second_beat;
107  uint8_t pin;
108  uint8_t ret;
109  mraa::Aio pin_ctx;
110 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
111  Callback *obj_callback;
112 #else
113  callback_handler callback;
114 #endif
115  volatile uint16_t ctx_counter;
116 };
117 }
Definition: pulsensor.h:46
C++ API for the 3-Wire Pulse Sensor.
Definition: pulsensor.h:80
int is_heart_beat
Definition: pulsensor.h:47