From 610351688401a287e3d26d2b6d7107249ebcde4a Mon Sep 17 00:00:00 2001 From: Adelin Dobre Date: Mon, 16 Jul 2018 12:36:30 +0300 Subject: [PATCH] BISS0001: Add string based constructor Signed-off-by: Adelin Dobre Signed-off-by: Mihai Tudor Panu --- src/biss0001/biss0001.cxx | 36 ++++++++++++++++++++++++++++++++++++ src/biss0001/biss0001.hpp | 9 +++++++++ 2 files changed, 45 insertions(+) diff --git a/src/biss0001/biss0001.cxx b/src/biss0001/biss0001.cxx index 5e0d274c..c9356c8c 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 79f2e9e1..8e2924d6 100644 --- a/src/biss0001/biss0001.hpp +++ b/src/biss0001/biss0001.hpp @@ -26,6 +26,7 @@ #include #include +#include namespace upm { /** @@ -67,6 +68,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 */ @@ -94,6 +102,7 @@ namespace upm { BISS0001 &operator=(const BISS0001&) = delete; biss0001_context m_biss0001; + mraa::MraaIo mraaIo; }; }