diff --git a/src/apds9002/apds9002.cxx b/src/apds9002/apds9002.cxx index b417d1b1..4e206338 100644 --- a/src/apds9002/apds9002.cxx +++ b/src/apds9002/apds9002.cxx @@ -27,12 +27,13 @@ #include #include "apds9002.hpp" +#include "upm_string_parser.hpp" using namespace upm; APDS9002::APDS9002(int pin) { - if ( !(m_aio = mraa_aio_init(pin)) ) + if ( !(m_aio = mraa_aio_init(pin)) ) { throw std::invalid_argument(std::string(__FUNCTION__) + ": mraa_aio_init() failed, invalid pin?"); @@ -40,6 +41,26 @@ APDS9002::APDS9002(int pin) } } +APDS9002::APDS9002(std::string initStr) : mraaIo(initStr) +{ + mraa_io_descriptor* descs = mraaIo.getMraaDescriptors(); + + if(!descs->aios) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + } + else + { + if( !(m_aio = descs->aios[0]) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + + } + } +} + APDS9002::~APDS9002() { mraa_aio_close(m_aio); diff --git a/src/apds9002/apds9002.hpp b/src/apds9002/apds9002.hpp index 062525b1..d0406ee1 100644 --- a/src/apds9002/apds9002.hpp +++ b/src/apds9002/apds9002.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace upm { /** @@ -60,6 +61,12 @@ namespace upm { * @param pin Analog pin to use */ APDS9002(int pin); + /** + * Instantiates APDS-9002 Luminance Sensor based on a given string. + * + * @param initStr string containing specific information for APDS-9002 initialization. + */ + APDS9002(std::string initStr); /** * APDS9002 destructor */ @@ -73,6 +80,7 @@ namespace upm { private: mraa_aio_context m_aio; + mraa::MraaIo mraaIo; }; }