mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
Fix some issues for string based constructors
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
8f11061de3
commit
2975bae075
@ -31,6 +31,11 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static bool operator!(mraa::MraaIo &mraaIo)
|
||||||
|
{
|
||||||
|
return mraaIo.getMraaDescriptors() == NULL;
|
||||||
|
}
|
||||||
|
|
||||||
AD8232::AD8232(int loPlus, int loMinus, int output, float aref) {
|
AD8232::AD8232(int loPlus, int loMinus, int output, float aref) {
|
||||||
m_gpioLOPlus = new mraa::Gpio(loPlus);
|
m_gpioLOPlus = new mraa::Gpio(loPlus);
|
||||||
m_gpioLOMinus = new mraa::Gpio(loMinus);
|
m_gpioLOMinus = new mraa::Gpio(loMinus);
|
||||||
@ -43,47 +48,38 @@ AD8232::AD8232(int loPlus, int loMinus, int output, float aref) {
|
|||||||
m_ares = (1 << m_aioOUT->getBit());
|
m_ares = (1 << m_aioOUT->getBit());
|
||||||
}
|
}
|
||||||
|
|
||||||
AD8232::AD8232(std::string initStr)
|
AD8232::AD8232(std::string initStr) : mraaIo(initStr) {
|
||||||
{
|
if(!mraaIo.gpios.empty()) {
|
||||||
mraaIo = new mraa::MraaIo(initStr);
|
if(mraaIo.gpios.size() == 2) {
|
||||||
if(mraaIo == NULL)
|
m_gpioLOPlus = &mraaIo.gpios[0];
|
||||||
{
|
m_gpioLOMinus = &mraaIo.gpios[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
": Failed to allocate memory for internal member");
|
": mraa_gpio_init() must initialize two pins");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mraaIo->gpios.empty())
|
|
||||||
{
|
|
||||||
m_gpioLOPlus = &mraaIo->gpios[0];
|
|
||||||
m_gpioLOMinus = &mraaIo->gpios[1];
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
": mraa_gpio_init() failed, invalid pin?");
|
": mraa_gpio_init() failed, invalid pin?");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mraaIo->aios.empty())
|
if(!mraaIo.aios.empty()) {
|
||||||
{
|
m_aioOUT = &mraaIo.aios[0];
|
||||||
m_aioOUT = &mraaIo->aios[0];
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
": mraa_aio_init() failed, invalid pin?");
|
": mraa_aio_init() failed, invalid pin?");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> upmTokens;
|
std::vector<std::string> upmTokens;
|
||||||
|
|
||||||
if(!mraaIo->getLeftoverStr().empty())
|
if(!mraaIo.getLeftoverStr().empty()) {
|
||||||
{
|
upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr());
|
||||||
upmTokens = UpmStringParser::parse(mraaIo->getLeftoverStr());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::string tok : upmTokens)
|
for (std::string tok : upmTokens) {
|
||||||
{
|
if(tok.substr(0, 5) == "volt:") {
|
||||||
if(tok.substr(0,5) == "volt:")
|
|
||||||
{
|
|
||||||
m_aref = std::stof(tok.substr(5));
|
m_aref = std::stof(tok.substr(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,12 +88,7 @@ AD8232::AD8232(std::string initStr)
|
|||||||
|
|
||||||
AD8232::~AD8232()
|
AD8232::~AD8232()
|
||||||
{
|
{
|
||||||
if(mraaIo != NULL)
|
if(!mraaIo) {
|
||||||
{
|
|
||||||
delete mraaIo;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete m_gpioLOPlus;
|
delete m_gpioLOPlus;
|
||||||
delete m_gpioLOMinus;
|
delete m_gpioLOMinus;
|
||||||
delete m_aioOUT;
|
delete m_aioOUT;
|
||||||
|
@ -105,7 +105,7 @@ namespace upm {
|
|||||||
int value();
|
int value();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mraa::MraaIo *mraaIo = NULL;
|
mraa::MraaIo mraaIo;
|
||||||
mraa::Gpio *m_gpioLOPlus = NULL;
|
mraa::Gpio *m_gpioLOPlus = NULL;
|
||||||
mraa::Gpio *m_gpioLOMinus = NULL;
|
mraa::Gpio *m_gpioLOMinus = NULL;
|
||||||
mraa::Aio *m_aioOUT = NULL;
|
mraa::Aio *m_aioOUT = NULL;
|
||||||
|
@ -58,7 +58,7 @@ ADS1015::ADS1015(int bus, uint8_t address, float vref) : ADS1X15(bus, address) {
|
|||||||
|
|
||||||
ADS1015::ADS1015(std::string initStr) : ADS1X15(initStr)
|
ADS1015::ADS1015(std::string initStr) : ADS1X15(initStr)
|
||||||
{
|
{
|
||||||
float vref;
|
float vref = ADS1015_VREF;
|
||||||
m_name = "ADS1015";
|
m_name = "ADS1015";
|
||||||
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
||||||
m_bitShift = 4;
|
m_bitShift = 4;
|
||||||
@ -67,14 +67,11 @@ ADS1015::ADS1015(std::string initStr) : ADS1X15(initStr)
|
|||||||
std::string leftoverString = ADS1X15::getLeftoverStr();
|
std::string leftoverString = ADS1X15::getLeftoverStr();
|
||||||
std::vector<std::string> upmTokens;
|
std::vector<std::string> upmTokens;
|
||||||
|
|
||||||
if(!leftoverString.empty())
|
if(!leftoverString.empty()) {
|
||||||
{
|
upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr());
|
||||||
upmTokens = UpmStringParser::parse(mraaIo->getLeftoverStr());
|
|
||||||
}
|
}
|
||||||
for (std::string tok : upmTokens)
|
for (std::string tok : upmTokens) {
|
||||||
{
|
if(tok.substr(0, 5) == "vref:") {
|
||||||
if(tok.substr(0,5) == "vref:")
|
|
||||||
{
|
|
||||||
vref = std::stof(tok.substr(5));
|
vref = std::stof(tok.substr(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,11 @@
|
|||||||
|
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
|
static bool operator!(mraa::MraaIo &mraaIo)
|
||||||
|
{
|
||||||
|
return mraaIo.getMraaDescriptors() == NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ADS1X15::ADS1X15(int bus, uint8_t address) {
|
ADS1X15::ADS1X15(int bus, uint8_t address) {
|
||||||
|
|
||||||
if(!(i2c = new mraa::I2c(bus))) {
|
if(!(i2c = new mraa::I2c(bus))) {
|
||||||
@ -54,20 +59,12 @@ ADS1X15::ADS1X15(int bus, uint8_t address){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ADS1X15::ADS1X15(std::string initStr)
|
ADS1X15::ADS1X15(std::string initStr) : mraaIo(initStr)
|
||||||
{
|
{
|
||||||
mraaIo = new mraa::MraaIo(initStr);
|
if(!mraaIo.i2cs.empty()) {
|
||||||
if(mraaIo == NULL)
|
i2c = &mraaIo.i2cs[0];
|
||||||
{
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": Failed to allocate memory for internal member");
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if(!mraaIo->i2cs.empty())
|
|
||||||
{
|
|
||||||
i2c = &mraaIo->i2cs[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.init() failed");
|
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.init() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,8 +78,8 @@ ADS1X15::ADS1X15(std::string initStr)
|
|||||||
|
|
||||||
std::vector<std::string> upmTokens;
|
std::vector<std::string> upmTokens;
|
||||||
|
|
||||||
if(!mraaIo->getLeftoverStr().empty()) {
|
if(!mraaIo.getLeftoverStr().empty()) {
|
||||||
upmTokens = UpmStringParser::parse(mraaIo->getLeftoverStr());
|
upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string::size_type sz;
|
std::string::size_type sz;
|
||||||
@ -114,7 +111,8 @@ ADS1X15::ADS1X15(std::string initStr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ADS1X15::~ADS1X15() {
|
ADS1X15::~ADS1X15() {
|
||||||
delete mraaIo;
|
if(!mraaIo)
|
||||||
|
delete i2c;
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
@ -250,7 +248,7 @@ ADS1X15::swapWord(uint16_t value){
|
|||||||
|
|
||||||
std::string
|
std::string
|
||||||
ADS1X15::getLeftoverStr(){
|
ADS1X15::getLeftoverStr(){
|
||||||
return mraaIo->getLeftoverStr();
|
return mraaIo.getLeftoverStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -432,7 +432,7 @@ namespace upm {
|
|||||||
void updateConfigRegister(uint16_t update, bool read = false);
|
void updateConfigRegister(uint16_t update, bool read = false);
|
||||||
uint16_t swapWord(uint16_t value);
|
uint16_t swapWord(uint16_t value);
|
||||||
|
|
||||||
mraa::MraaIo* mraaIo = NULL;
|
mraa::MraaIo mraaIo;
|
||||||
mraa::I2c* i2c;
|
mraa::I2c* i2c;
|
||||||
|
|
||||||
};}
|
};}
|
||||||
|
@ -81,6 +81,8 @@ ADXL335::ADXL335(std::string initStr) : mraaIo(initStr)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("ADXL335 else inside constructor\n");
|
printf("ADXL335 else inside constructor\n");
|
||||||
|
if(descs->n_aio == 3)
|
||||||
|
{
|
||||||
if( !(m_aioX = descs->aios[0]) )
|
if( !(m_aioX = descs->aios[0]) )
|
||||||
{
|
{
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
@ -96,6 +98,11 @@ ADXL335::ADXL335(std::string initStr) : mraaIo(initStr)
|
|||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
": mraa_aio_init(X) failed, invalid pin?");
|
": mraa_aio_init(X) failed, invalid pin?");
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_aio_init(X) must initialize three pins");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> upmTokens;
|
std::vector<std::string> upmTokens;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user