1 /* 2 * Author: Jon Trulson <jtrulson@ics.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 #pragma once 25 26 #include <stdint.h> 27 #include <sys/time.h> 28 29 #include <mraa/gpio.hpp> 30 31 #include <mraa/aio.hpp> 32 33 #define AD8232_DEFAULT_AREF 3.3 34 35 namespace upm { 36 37 /** 38 * @brief AD8232 Heart Rate Monitor library 39 * @defgroup ad8232 libupm-ad8232 40 * @ingroup sparkfun gpio medical 41 */ 42 43 /** 44 * @library ad8232 45 * @sensor ad8232 46 * @comname AD8232 Heart Rate Monitor 47 * @type medical 48 * @man sparkfun 49 * @web https://www.sparkfun.com/products/12650 50 * @con gpio aio 51 * 52 * @brief UPM module for the AD8232 Heart Rate Monitor 53 * 54 * Note: this sensor must be driven at 3.3V only. 55 * 56 * This module simply spits out the ADC values reported by the sensor, with 57 * the intent to send that data, via serial or network port, somewhere to 58 * another piece of software running on a computer that plots the data for 59 * you, like an EKG. 60 * 61 * Processing (https://www.processing.org/) is software 62 * that should work, using information from the SparkFun* website. 63 * 64 * This example just dumps the raw data: 65 * 66 * @image html ad8232.jpg 67 * <br><em>AD8232 Heart Rate Monitor image provided by SparkFun under 68 * <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/> 69 * CC BY-NC-SA-3.0</a>.</em> 70 * 71 * @snippet ad8232.cxx Interesting 72 */ 73 74 class AD8232 { 75 public: 76 77 /** 78 * AD8232 constructor 79 * 80 * @param loPlus Digital pin to use for LO+ 81 * @param loMinus Digital pin to use for LO- 82 * @param output Analog pin to read the data 83 */ 84 AD8232(int loPlus, int loMinus, int output, float aref=AD8232_DEFAULT_AREF); 85 86 /** 87 * AD8232 destructor 88 */ 89 ~AD8232(); 90 91 /** 92 * Returns the current ADC value for the device output pin. If an 93 * LO (leads off) event is detected, 0 is returned. 94 * 95 * @return ADC value 96 */ 97 int value(); 98 99 private: 100 mraa::Aio m_aioOUT; 101 mraa::Gpio m_gpioLOPlus; 102 mraa::Gpio m_gpioLOMinus; 103 104 float m_aref; 105 int m_ares; 106 107 }; 108 } 109 110 111