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>
This commit is contained in:
parent
5a42e44c86
commit
b13cef3ebb
@ -31,6 +31,11 @@
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
static bool operator!(mraa::MraaIo &mraaIo)
|
||||
{
|
||||
return mraaIo.getMraaDescriptors() == NULL;
|
||||
}
|
||||
|
||||
AD8232::AD8232(int loPlus, int loMinus, int output, float aref) {
|
||||
m_gpioLOPlus = new mraa::Gpio(loPlus);
|
||||
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());
|
||||
}
|
||||
|
||||
AD8232::AD8232(std::string initStr)
|
||||
{
|
||||
mraaIo = new mraa::MraaIo(initStr);
|
||||
if(mraaIo == NULL)
|
||||
{
|
||||
AD8232::AD8232(std::string initStr) : mraaIo(initStr) {
|
||||
if(!mraaIo.gpios.empty()) {
|
||||
if(mraaIo.gpios.size() == 2) {
|
||||
m_gpioLOPlus = &mraaIo.gpios[0];
|
||||
m_gpioLOMinus = &mraaIo.gpios[1];
|
||||
}
|
||||
else {
|
||||
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__) +
|
||||
": mraa_gpio_init() failed, invalid pin?");
|
||||
}
|
||||
|
||||
if(!mraaIo->aios.empty())
|
||||
{
|
||||
m_aioOUT = &mraaIo->aios[0];
|
||||
if(!mraaIo.aios.empty()) {
|
||||
m_aioOUT = &mraaIo.aios[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_aio_init() failed, invalid pin?");
|
||||
}
|
||||
|
||||
std::vector<std::string> upmTokens;
|
||||
|
||||
if(!mraaIo->getLeftoverStr().empty())
|
||||
{
|
||||
upmTokens = UpmStringParser::parse(mraaIo->getLeftoverStr());
|
||||
if(!mraaIo.getLeftoverStr().empty()) {
|
||||
upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr());
|
||||
}
|
||||
|
||||
for (std::string tok : upmTokens)
|
||||
{
|
||||
if(tok.substr(0,5) == "volt:")
|
||||
{
|
||||
for (std::string tok : upmTokens) {
|
||||
if(tok.substr(0, 5) == "volt:") {
|
||||
m_aref = std::stof(tok.substr(5));
|
||||
}
|
||||
}
|
||||
@ -92,12 +88,7 @@ AD8232::AD8232(std::string initStr)
|
||||
|
||||
AD8232::~AD8232()
|
||||
{
|
||||
if(mraaIo != NULL)
|
||||
{
|
||||
delete mraaIo;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!mraaIo) {
|
||||
delete m_gpioLOPlus;
|
||||
delete m_gpioLOMinus;
|
||||
delete m_aioOUT;
|
||||
|
@ -105,7 +105,7 @@ namespace upm {
|
||||
int value();
|
||||
|
||||
private:
|
||||
mraa::MraaIo *mraaIo = NULL;
|
||||
mraa::MraaIo mraaIo;
|
||||
mraa::Gpio *m_gpioLOPlus = NULL;
|
||||
mraa::Gpio *m_gpioLOMinus = 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)
|
||||
{
|
||||
float vref;
|
||||
float vref = ADS1015_VREF;
|
||||
m_name = "ADS1015";
|
||||
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
||||
m_bitShift = 4;
|
||||
@ -67,14 +67,11 @@ ADS1015::ADS1015(std::string initStr) : ADS1X15(initStr)
|
||||
std::string leftoverString = ADS1X15::getLeftoverStr();
|
||||
std::vector<std::string> upmTokens;
|
||||
|
||||
if(!leftoverString.empty())
|
||||
{
|
||||
upmTokens = UpmStringParser::parse(mraaIo->getLeftoverStr());
|
||||
if(!leftoverString.empty()) {
|
||||
upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr());
|
||||
}
|
||||
for (std::string tok : upmTokens)
|
||||
{
|
||||
if(tok.substr(0,5) == "vref:")
|
||||
{
|
||||
for (std::string tok : upmTokens) {
|
||||
if(tok.substr(0, 5) == "vref:") {
|
||||
vref = std::stof(tok.substr(5));
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,11 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
static bool operator!(mraa::MraaIo &mraaIo)
|
||||
{
|
||||
return mraaIo.getMraaDescriptors() == NULL;
|
||||
}
|
||||
|
||||
ADS1X15::ADS1X15(int bus, uint8_t address) {
|
||||
|
||||
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 == NULL)
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": Failed to allocate memory for internal member");
|
||||
if(!mraaIo.i2cs.empty()) {
|
||||
i2c = &mraaIo.i2cs[0];
|
||||
}
|
||||
|
||||
if(!mraaIo->i2cs.empty())
|
||||
{
|
||||
i2c = &mraaIo->i2cs[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.init() failed");
|
||||
}
|
||||
|
||||
@ -81,8 +78,8 @@ ADS1X15::ADS1X15(std::string initStr)
|
||||
|
||||
std::vector<std::string> upmTokens;
|
||||
|
||||
if(!mraaIo->getLeftoverStr().empty()) {
|
||||
upmTokens = UpmStringParser::parse(mraaIo->getLeftoverStr());
|
||||
if(!mraaIo.getLeftoverStr().empty()) {
|
||||
upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr());
|
||||
}
|
||||
|
||||
std::string::size_type sz;
|
||||
@ -114,7 +111,8 @@ ADS1X15::ADS1X15(std::string initStr)
|
||||
}
|
||||
|
||||
ADS1X15::~ADS1X15() {
|
||||
delete mraaIo;
|
||||
if(!mraaIo)
|
||||
delete i2c;
|
||||
}
|
||||
|
||||
float
|
||||
@ -250,7 +248,7 @@ ADS1X15::swapWord(uint16_t value){
|
||||
|
||||
std::string
|
||||
ADS1X15::getLeftoverStr(){
|
||||
return mraaIo->getLeftoverStr();
|
||||
return mraaIo.getLeftoverStr();
|
||||
}
|
||||
|
||||
|
||||
|
@ -432,7 +432,7 @@ namespace upm {
|
||||
void updateConfigRegister(uint16_t update, bool read = false);
|
||||
uint16_t swapWord(uint16_t value);
|
||||
|
||||
mraa::MraaIo* mraaIo = NULL;
|
||||
mraa::MraaIo mraaIo;
|
||||
mraa::I2c* i2c;
|
||||
|
||||
};}
|
||||
|
@ -81,6 +81,8 @@ ADXL335::ADXL335(std::string initStr) : mraaIo(initStr)
|
||||
else
|
||||
{
|
||||
printf("ADXL335 else inside constructor\n");
|
||||
if(descs->n_aio == 3)
|
||||
{
|
||||
if( !(m_aioX = descs->aios[0]) )
|
||||
{
|
||||
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__) +
|
||||
": 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user