mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
APDS9930: Add string based constructor for Digital Proximity and Ambient Light Sensor
Signed-off-by: Adelin Dobre <adelin.dobre@rinftech.com>
This commit is contained in:
parent
dad2e1f81a
commit
60a5500260
@ -27,6 +27,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "apds9930.hpp"
|
#include "apds9930.hpp"
|
||||||
|
#include "upm_string_parser.hpp"
|
||||||
|
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
@ -39,6 +40,44 @@ APDS9930::APDS9930(int device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
APDS9930::APDS9930(std::string initStr) : mraaIo(initStr)
|
||||||
|
{
|
||||||
|
mraa_io_descriptor* descs = mraaIo.getMraaDescriptors();
|
||||||
|
|
||||||
|
if(!descs->iios)
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_iio_init() failed");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!(m_iio = descs->iios[0]))
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_iio_init() failed");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> upmTokens;
|
||||||
|
|
||||||
|
if (!mraaIo.getLeftoverStr().empty()) {
|
||||||
|
upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::string tok : upmTokens) {
|
||||||
|
if(tok.substr(0,16) == "enableProximity:") {
|
||||||
|
bool enable = std::stoi(tok.substr(16),nullptr,0);
|
||||||
|
enableProximity(enable);
|
||||||
|
}
|
||||||
|
if(tok.substr(0,18) == "enableIlluminance:") {
|
||||||
|
bool enable = std::stoi(tok.substr(18),nullptr,0);
|
||||||
|
enableIlluminance(enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
APDS9930::~APDS9930()
|
APDS9930::~APDS9930()
|
||||||
{
|
{
|
||||||
if (m_iio)
|
if (m_iio)
|
||||||
@ -81,4 +120,4 @@ APDS9930::enableIlluminance(bool enable)
|
|||||||
mraa_iio_write_int(m_iio, "in_illuminance_en", 0);
|
mraa_iio_write_int(m_iio, "in_illuminance_en", 0);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mraa/iio.h>
|
#include <mraa/iio.h>
|
||||||
|
#include <mraa/initio.hpp>
|
||||||
|
|
||||||
namespace upm
|
namespace upm
|
||||||
{
|
{
|
||||||
@ -60,6 +61,12 @@ class APDS9930
|
|||||||
* @param device iio device number
|
* @param device iio device number
|
||||||
*/
|
*/
|
||||||
APDS9930(int device);
|
APDS9930(int device);
|
||||||
|
/**
|
||||||
|
* Instantiates APDS9930 Digital Proximity and Ambient Light Sensor based on a given string.
|
||||||
|
*
|
||||||
|
* @param initStr string containing specific information for APDS9930 initialization.
|
||||||
|
*/
|
||||||
|
APDS9930(std::string initStr);
|
||||||
/**
|
/**
|
||||||
* APDS9930 destructor
|
* APDS9930 destructor
|
||||||
*/
|
*/
|
||||||
@ -89,5 +96,6 @@ class APDS9930
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mraa_iio_context m_iio;
|
mraa_iio_context m_iio;
|
||||||
|
mraa::MraaIo mraaIo;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user