diff --git a/src/ecs1030/ecs1030.cxx b/src/ecs1030/ecs1030.cxx index 4995f24f..12d01fdc 100644 --- a/src/ecs1030/ecs1030.cxx +++ b/src/ecs1030/ecs1030.cxx @@ -35,13 +35,26 @@ using namespace upm; ECS1030::ECS1030 (int pinNumber) { m_dataPinCtx = mraa_aio_init(pinNumber); if (m_dataPinCtx == NULL) { - throw std::invalid_argument(std::string(__FUNCTION__) + + throw std::invalid_argument(std::string(__FUNCTION__) + ": mraa_aio_init() failed"); } m_calibration = 111.1; } +ECS1030::ECS1030 (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"); + } else { + m_dataPinCtx = descs->aios[0]; + } + + m_calibration = 111.1; +} + ECS1030::~ECS1030 () { mraa_result_t error = MRAA_SUCCESS; diff --git a/src/ecs1030/ecs1030.hpp b/src/ecs1030/ecs1030.hpp index 67ea0ee4..b2d2b18b 100644 --- a/src/ecs1030/ecs1030.hpp +++ b/src/ecs1030/ecs1030.hpp @@ -24,9 +24,11 @@ #pragma once #include +#include #include #include #include +#include namespace upm { @@ -85,6 +87,13 @@ class ECS1030 { */ ECS1030 (int pinNumber); + /** + * Instantiates ECS1030 sensor object based on a given string. + * + * @param initStr string containing specific information for ECS1030 sensor initialization. + */ + ECS1030 (std::string initStr); + /** * ECS1030 object destructor; basically, it closes the GPIO. */ @@ -119,6 +128,7 @@ class ECS1030 { private: std::string m_name; mraa_aio_context m_dataPinCtx; + mraa::MraaIo mraaIo; double m_calibration; int m_lastSample;