From cca6a86268d55ac69b483ff0feb8a7a93f8f8133 Mon Sep 17 00:00:00 2001 From: Adelin Dobre Date: Wed, 11 Jul 2018 17:06:39 +0300 Subject: [PATCH] APDS-9002: Add string based constructor for Luminance Sensor Signed-off-by: Adelin Dobre Signed-off-by: Mihai Tudor Panu --- src/apds9002/apds9002.cxx | 21 +++++++++++++++++++++ src/apds9002/apds9002.hpp | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/src/apds9002/apds9002.cxx b/src/apds9002/apds9002.cxx index 02b2611e..7faa7c12 100644 --- a/src/apds9002/apds9002.cxx +++ b/src/apds9002/apds9002.cxx @@ -27,6 +27,7 @@ #include #include "apds9002.hpp" +#include "upm_string_parser.hpp" using namespace upm; @@ -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 8ad393a3..e248bcc2 100644 --- a/src/apds9002/apds9002.hpp +++ b/src/apds9002/apds9002.hpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace upm { @@ -61,6 +62,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 */ @@ -81,6 +88,7 @@ namespace upm { private: mraa_aio_context m_aio; + mraa::MraaIo mraaIo; }; }