upm  0.1.8
Sensor/Actuator repository for libmraa (v0.4.5)
 All Data Structures Files Functions Variables Macros Pages
pulsensor.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Credits to Adafruit.
6  * Based on Adafruit BMP085 library.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #pragma once
28 
29 #include <string>
30 #include <math.h>
31 #include <mraa/pwm.h>
32 #include <mraa/aio.h>
33 #include <mraa/gpio.h>
34 #include <pthread.h>
35 
36 #define HIGH 1
37 #define LOW 0
38 
39 #define TRUE HIGH
40 #define FALSE LOW
41 
42 struct clbk_data {
43  int is_heart_beat;
44 };
45 
46 typedef void (* callback_handler) (clbk_data);
47 
49  pthread_t sample_thread;
50  uint32_t sample_counter;
51  uint32_t last_beat_time;
52  int threshold;
53  int ibi_rate[10];
54  int ibi;
55  int trough;
56  int peak;
57  int bpm;
58  int apmlitude;
59  uint8_t qs;
60  uint8_t is_pulse;
61  uint8_t first_beat;
62  uint8_t second_beat;
63  uint8_t pin;
64  uint8_t ret;
65  mraa_aio_context pin_ctx;
66 
67  callback_handler callback;
68 };
69 
70 static volatile uint16_t ctx_counter = 0;
71 
72 void init_pulsensor (pulsensor_context * ctx, callback_handler handler);
73 void start_sampler (pulsensor_context * ctx);
74 void stop_sampler (pulsensor_context * ctx);
75 
76 void * do_sample (void * arg);
Definition: pulsensor.h:48
Definition: pulsensor.h:42