EHR: Add string based constructor

Signed-off-by: Adelin Dobre <adelin.dobre@rinftech.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Adelin Dobre 2018-11-01 18:47:39 +02:00 committed by Mihai Tudor Panu
parent 402739fa74
commit bd445385a7
2 changed files with 26 additions and 0 deletions

View File

@ -46,6 +46,23 @@ EHR::EHR(int pin)
m_beatCounter = 0; m_beatCounter = 0;
} }
EHR::EHR(std::string initStr) : mraaIo(initStr)
{
mraa_io_descriptor* descs = mraaIo.getMraaDescriptors();
if(!descs->gpios) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
} else {
m_gpio = descs->gpios[0];
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
initClock();
m_beatCounter = 0;
}
EHR::~EHR() EHR::~EHR()
{ {
mraa_gpio_close(m_gpio); mraa_gpio_close(m_gpio);

View File

@ -27,6 +27,7 @@
#include <stdint.h> #include <stdint.h>
#include <sys/time.h> #include <sys/time.h>
#include <mraa/gpio.h> #include <mraa/gpio.h>
#include <mraa/initio.hpp>
#include <interfaces/iHeartRate.hpp> #include <interfaces/iHeartRate.hpp>
namespace upm { namespace upm {
@ -60,6 +61,13 @@ namespace upm {
* @param pin Digital pin to use * @param pin Digital pin to use
*/ */
EHR(int pin); EHR(int pin);
/**
* Instantiates EHR Heart Rate sensor based on a given string.
*
* @param initStr string containing specific information for EHR initialization.
*/
EHR(std::string initStr);
/** /**
* EHR destructor * EHR destructor
*/ */
@ -128,5 +136,6 @@ namespace upm {
volatile uint32_t m_beatCounter; volatile uint32_t m_beatCounter;
struct timeval m_startTime; struct timeval m_startTime;
mraa_gpio_context m_gpio; mraa_gpio_context m_gpio;
mraa::MraaIo mraaIo;
}; };
} }