upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
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 
70 struct clbk_data {
72 };
73 
74 typedef void (* callback_handler) (clbk_data);
75 
81  pthread_t sample_thread;
82  uint32_t sample_counter;
83  uint32_t last_beat_time;
84  int threshold;
85  int ibi_rate[10];
86  int ibi;
87  int trough;
88  int peak;
89  int bpm;
90  int apmlitude;
91  uint8_t qs;
92  uint8_t is_pulse;
93  uint8_t first_beat;
94  uint8_t second_beat;
95  uint8_t pin;
96  uint8_t ret;
97  mraa_aio_context pin_ctx;
99  callback_handler callback;
100 };
101 
102 static volatile uint16_t ctx_counter = 0;
103 
104 void init_pulsensor (pulsensor_context * ctx, callback_handler handler);
105 void start_sampler (pulsensor_context * ctx);
106 void stop_sampler (pulsensor_context * ctx);
107 
108 void * do_sample (void * arg);
int apmlitude
Definition: pulsensor.h:90
int threshold
Definition: pulsensor.h:84
uint32_t last_beat_time
Definition: pulsensor.h:83
int bpm
Definition: pulsensor.h:89
int trough
Definition: pulsensor.h:87
The context for the heartbeat pulse sensor.
Definition: pulsensor.h:80
pthread_t sample_thread
Definition: pulsensor.h:81
int peak
Definition: pulsensor.h:88
mraa_aio_context pin_ctx
Definition: pulsensor.h:97
uint8_t second_beat
Definition: pulsensor.h:94
C++ API for 3-wire pulse sensor.
Definition: pulsensor.h:70
uint8_t ret
Definition: pulsensor.h:96
int ibi_rate[10]
Definition: pulsensor.h:85
callback_handler callback
Definition: pulsensor.h:99
uint8_t qs
Definition: pulsensor.h:91
uint8_t pin
Definition: pulsensor.h:95
int is_heart_beat
Definition: pulsensor.h:71
int ibi
Definition: pulsensor.h:86
uint32_t sample_counter
Definition: pulsensor.h:82
uint8_t first_beat
Definition: pulsensor.h:93
uint8_t is_pulse
Definition: pulsensor.h:92