diff --git a/src/biss0001/biss0001.cxx b/src/biss0001/biss0001.cxx index c7a0e0d8..d8766118 100644 --- a/src/biss0001/biss0001.cxx +++ b/src/biss0001/biss0001.cxx @@ -27,6 +27,7 @@ #include #include +#include "upm_string_parser.hpp" #include "biss0001.hpp" using namespace upm; @@ -39,6 +40,41 @@ BISS0001::BISS0001(unsigned int pin) : ": biss0001_init() failed"); } +BISS0001::BISS0001(std::string initStr) : mraaIo(initStr) +{ + mraa_io_descriptor* descs = mraaIo.getMraaDescriptors(); + + m_biss0001 = (biss0001_context)malloc(sizeof(struct _biss0001_context)); + + if(!m_biss0001) + throw std::runtime_error(std::string(__FUNCTION__) + + ": biss0001_init() failed"); + + m_biss0001->gpio = NULL; + + // make sure MRAA is initialized + int mraa_rv; + if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) { + biss0001_close(m_biss0001); + throw std::runtime_error(std::string(__FUNCTION__) + + ": biss0001_init() failed"); + } + + // initialize the MRAA context + if(!descs->gpios) { + throw std::runtime_error(std::string(__FUNCTION__) + + ": mraa_gpio_init() failed"); + } + else { + if( !(m_biss0001->gpio = descs->gpios[0]) ) { + biss0001_close(m_biss0001); + throw std::runtime_error(std::string(__FUNCTION__) + + ": mraa_gpio_init() failed"); + } + } + mraa_gpio_dir(m_biss0001->gpio, MRAA_GPIO_IN); +} + BISS0001::~BISS0001() { biss0001_close(m_biss0001); diff --git a/src/biss0001/biss0001.hpp b/src/biss0001/biss0001.hpp index 80c3511b..812013cc 100644 --- a/src/biss0001/biss0001.hpp +++ b/src/biss0001/biss0001.hpp @@ -25,6 +25,7 @@ #pragma once #include +#include namespace upm { /** @@ -66,6 +67,13 @@ namespace upm { */ BISS0001(unsigned int pin); + /** + * Instantiates BISS0001 Motion Sensor object based on a given string. + * + * @param initStr string containing specific information for BISS0001 initialization. + */ + BISS0001(std::string initStr); + /** * BISS0001 destructor */ @@ -93,6 +101,7 @@ namespace upm { BISS0001 &operator=(const BISS0001&) = delete; biss0001_context m_biss0001; + mraa::MraaIo mraaIo; }; }