Home | History | Annotate | Download | only in groveehr
      1 /*
      2  * Author: Jon Trulson <jtrulson (at) ics.com>
      3  * Copyright (c) 2014 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 <string>
     27 #include <stdint.h>
     28 #include <sys/time.h>
     29 #include <mraa/gpio.h>
     30 
     31 namespace upm {
     32   /**
     33    * @brief Grove Ear-clip Heart Rate Sensor library
     34    * @defgroup groveehr libupm-groveehr
     35    * @ingroup seeed gpio medical
     36    */
     37 
     38   /**
     39    * @library groveehr
     40    * @sensor groveehr
     41    * @comname Grove Ear-clip Heart Rate Sensor
     42    * @type medical
     43    * @man seeed
     44    * @con gpio
     45    *
     46    * @brief API for the Grove Ear-clip Heart Rate Sensor
     47    *
     48    * UPM module for the Grove ear-clip heart rate sensor. It is used to measure your
     49    * heart rate.
     50    *
     51    * @image html groveehr.jpg
     52    * @snippet groveehr.cxx Interesting
     53    */
     54   class GroveEHR {
     55   public:
     56     /**
     57      * GroveEHR constructor
     58      *
     59      * @param pin Digital pin to use
     60      */
     61     GroveEHR(int pin);
     62     /**
     63      * GroveEHR destructor
     64      */
     65     ~GroveEHR();
     66     /**
     67      * Returns the time of milliseconds elapsed since initClock()
     68      * was last called.
     69      *
     70      * @return Elapsed milliseconds
     71      */
     72     uint32_t getMillis();
     73 
     74     /**
     75      * Resets the clock
     76      *
     77      */
     78     void initClock();
     79 
     80     /**
     81      * Resets the beat counter to 0. The beat counter should be
     82      * stopped via stopBeatCounter() prior to calling this function.
     83      *
     84      */
     85     void clearBeatCounter();
     86 
     87     /**
     88      * Starts the beat counter
     89      *
     90      */
     91     void startBeatCounter();
     92 
     93     /**
     94      * Stops the beat counter
     95      *
     96      */
     97     void stopBeatCounter();
     98 
     99     /**
    100      * Gets the beat Counter
    101      *
    102      * @return Beat counter
    103      */
    104     uint32_t beatCounter();
    105 
    106     /**
    107      * Computes the heart rate
    108      *
    109      * @return Computed heart rate
    110      */
    111     int heartRate();
    112 
    113   private:
    114     /**
    115      * Beat interrupt service routine (ISR)
    116      *
    117      */
    118     static void beatISR(void *ctx);
    119 
    120     volatile uint32_t m_beatCounter;
    121     struct timeval m_startTime;
    122     mraa_gpio_context m_gpio;
    123   };
    124 }
    125 
    126 
    127