diff --git a/src/ad8232/ad8232.cxx b/src/ad8232/ad8232.cxx index de8d650e..88934acb 100644 --- a/src/ad8232/ad8232.cxx +++ b/src/ad8232/ad8232.cxx @@ -23,7 +23,7 @@ */ #include - +#include "upm_string_parser.hpp" #include "ad8232.hpp" using namespace upm; @@ -34,11 +34,31 @@ AD8232::AD8232(int loPlus, int loMinus, int output, float aref) : { m_gpioLOPlus.dir(mraa::DIR_IN); m_gpioLOMinus.dir(mraa::DIR_IN); - + m_aref = aref; m_ares = (1 << m_aioOUT.getBit()); } +AD8232::AD8232(std::string initStr) : mraaIo(initStr), m_gpioLOPlus(mraaIo.gpios[0]), + m_gpioLOMinus(mraaIo.gpios[1]), m_aioOUT(mraaIo.aios[0]) +{ + std::vector upmTokens; + + if(mraaIo.getLeftoverStr() != "") + { + upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr()); + } + + for (std::string tok : upmTokens) + { + if(tok.substr(0,5) == "volt:") + { + m_aref = std::stof(tok.substr(5)); + } + } + m_ares = (1 << m_aioOUT.getBit()); +} + AD8232::~AD8232() { } diff --git a/src/ad8232/ad8232.hpp b/src/ad8232/ad8232.hpp index 59eb7687..a90d9da7 100644 --- a/src/ad8232/ad8232.hpp +++ b/src/ad8232/ad8232.hpp @@ -27,8 +27,8 @@ #include #include - #include +#include #define AD8232_DEFAULT_AREF 3.3 @@ -57,7 +57,7 @@ namespace upm { * the intent to send that data, via serial or network port, somewhere to * another piece of software running on a computer that plots the data for * you, like an EKG. - * + * * Processing (https://www.processing.org/) is software * that should work, using information from the SparkFun* website. * @@ -84,6 +84,13 @@ namespace upm { */ AD8232(int loPlus, int loMinus, int output, float aref=AD8232_DEFAULT_AREF); + /** + * Instantiates AD8232 sensor object based on a given string. + * + * @param initStr string containing specific information for AD8232 sensor initialization. + */ + AD8232(std::string initStr); + /** * AD8232 destructor */ @@ -98,6 +105,7 @@ namespace upm { int value(); private: + mraa::MraaIo mraaIo; mraa::Gpio m_gpioLOPlus; mraa::Gpio m_gpioLOMinus; mraa::Aio m_aioOUT;