mirror of
https://github.com/eclipse/upm.git
synced 2025-03-14 20:47:30 +03:00
BISS0001: Add string based constructor
Signed-off-by: Adelin Dobre <adelin.dobre@rinftech.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
55f749529f
commit
6103516884
@ -27,6 +27,7 @@
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#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);
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include <interfaces/iMotion.hpp>
|
||||
#include <biss0001.h>
|
||||
#include <mraa/initio.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user