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
@ -86,12 +86,12 @@ ABP::ABP(std::string initStr) : mraaIo(initStr)
|
|||||||
m_abp->abp_pressure_min = 0;
|
m_abp->abp_pressure_min = 0;
|
||||||
|
|
||||||
for (std::string tok : upmTokens) {
|
for (std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,12) == "maxPressure:") {
|
if(tok.substr(0, 12) == "maxPressure:") {
|
||||||
int pmax = std::stoi(tok.substr(12),nullptr,0);
|
int pmax = std::stoi(tok.substr(12), nullptr, 0);
|
||||||
setMaxPressure(pmax);
|
setMaxPressure(pmax);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,12) == "minPressure:") {
|
if(tok.substr(0, 12) == "minPressure:") {
|
||||||
int pmin = std::stoi(tok.substr(12),nullptr,0);
|
int pmin = std::stoi(tok.substr(12), nullptr, 0);
|
||||||
setMinPressure(pmin);
|
setMinPressure(pmin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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];
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
}
|
||||||
": Failed to allocate memory for internal member");
|
else {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_gpio_init() must initialize two pins");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if(!mraaIo->gpios.empty())
|
|
||||||
{
|
|
||||||
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__) +
|
||||||
": 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;
|
||||||
|
@ -106,17 +106,17 @@ adafruitss::adafruitss(std::string initStr) : mraaIo(initStr)
|
|||||||
|
|
||||||
for(std::string tok : upmTokens)
|
for(std::string tok : upmTokens)
|
||||||
{
|
{
|
||||||
if(tok.substr(0,8) == "pwmFreq:")
|
if(tok.substr(0, 8) == "pwmFreq:")
|
||||||
{
|
{
|
||||||
float freq = std::stof(tok.substr(8));
|
float freq = std::stof(tok.substr(8));
|
||||||
setPWMFreq(freq);
|
setPWMFreq(freq);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,6) == "servo:")
|
if(tok.substr(0, 6) == "servo:")
|
||||||
{
|
{
|
||||||
uint8_t port = std::stoi(tok.substr(6),&sz,0);
|
uint8_t port = std::stoi(tok.substr(6), &sz, 0);
|
||||||
tok = tok.substr(6);
|
tok = tok.substr(6);
|
||||||
old_sz = sz+1;
|
old_sz = sz+1;
|
||||||
uint8_t servo_type = std::stoi(tok.substr(old_sz),&sz,0);
|
uint8_t servo_type = std::stoi(tok.substr(old_sz), &sz, 0);
|
||||||
tok = tok.substr(old_sz);
|
tok = tok.substr(old_sz);
|
||||||
float degrees = std::stof(tok.substr(sz+1));
|
float degrees = std::stof(tok.substr(sz+1));
|
||||||
servo(port, servo_type, degrees);
|
servo(port, servo_type, degrees);
|
||||||
|
@ -89,44 +89,44 @@ ADC121C021::ADC121C021(std::string initStr) : mraaIo(initStr)
|
|||||||
if(tok.substr(0, 5) == "vref:") {
|
if(tok.substr(0, 5) == "vref:") {
|
||||||
m_vref = std::stof(tok.substr(5));
|
m_vref = std::stof(tok.substr(5));
|
||||||
}
|
}
|
||||||
if(tok.substr(0,10) == "writeByte:") {
|
if(tok.substr(0, 10) == "writeByte:") {
|
||||||
uint8_t reg = std::stoi(tok.substr(10),&sz,0);
|
uint8_t reg = std::stoi(tok.substr(10), &sz, 0);
|
||||||
tok = tok.substr(10);
|
tok = tok.substr(10);
|
||||||
uint8_t byte = std::stoi(tok.substr(sz+1),nullptr,0);
|
uint8_t byte = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
writeByte(reg, byte);
|
writeByte(reg, byte);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,10) == "writeWord:") {
|
if(tok.substr(0,10) == "writeWord:") {
|
||||||
uint8_t reg = std::stoi(tok.substr(10),&sz,0);
|
uint8_t reg = std::stoi(tok.substr(10), &sz, 0);
|
||||||
tok = tok.substr(10);
|
tok = tok.substr(10);
|
||||||
uint16_t word = std::stoi(tok.substr(sz+1),nullptr,0);
|
uint16_t word = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
writeWord(reg, word);
|
writeWord(reg, word);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,16) == "enableAlertFlag:") {
|
if(tok.substr(0,16) == "enableAlertFlag:") {
|
||||||
bool enable = std::stoi(tok.substr(16),nullptr,0);
|
bool enable = std::stoi(tok.substr(16), nullptr, 0);
|
||||||
enableAlertFlag(enable);
|
enableAlertFlag(enable);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,15) == "enableAlertPin:") {
|
if(tok.substr(0,15) == "enableAlertPin:") {
|
||||||
bool enable = std::stoi(tok.substr(15),nullptr,0);
|
bool enable = std::stoi(tok.substr(15), nullptr, 0);
|
||||||
enableAlertPin(enable);
|
enableAlertPin(enable);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,16) == "enableAlertHold:") {
|
if(tok.substr(0,16) == "enableAlertHold:") {
|
||||||
bool enable = std::stoi(tok.substr(16),nullptr,0);
|
bool enable = std::stoi(tok.substr(16), nullptr, 0);
|
||||||
enableAlertHold(enable);
|
enableAlertHold(enable);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,27) == "enableAlertPinPolarityHigh:") {
|
if(tok.substr(0,27) == "enableAlertPinPolarityHigh:") {
|
||||||
bool enable = std::stoi(tok.substr(27),nullptr,0);
|
bool enable = std::stoi(tok.substr(27), nullptr, 0);
|
||||||
enableAlertPinPolarityHigh(enable);
|
enableAlertPinPolarityHigh(enable);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "setAlertLowLimit:") {
|
if(tok.substr(0,17) == "setAlertLowLimit:") {
|
||||||
uint16_t limit = std::stoi(tok.substr(17),nullptr,0);
|
uint16_t limit = std::stoi(tok.substr(17), nullptr, 0);
|
||||||
setAlertLowLimit(limit);
|
setAlertLowLimit(limit);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,18) == "setAlertHighLimit:") {
|
if(tok.substr(0,18) == "setAlertHighLimit:") {
|
||||||
uint16_t limit = std::stoi(tok.substr(18),nullptr,0);
|
uint16_t limit = std::stoi(tok.substr(18), nullptr, 0);
|
||||||
setAlertHighLimit(limit);
|
setAlertHighLimit(limit);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,14) == "setHysteresis:") {
|
if(tok.substr(0,14) == "setHysteresis:") {
|
||||||
uint16_t limit = std::stoi(tok.substr(14),nullptr,0);
|
uint16_t limit = std::stoi(tok.substr(14), nullptr, 0);
|
||||||
setHysteresis(limit);
|
setHysteresis(limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ ADIS16448::ADIS16448(std::string initStr) : mraaIo(initStr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configure I/O
|
// Configure I/O
|
||||||
//Initialize RST pin
|
// Initialize RST pin
|
||||||
if(!descs->gpios)
|
if(!descs->gpios)
|
||||||
{
|
{
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
@ -124,10 +124,10 @@ ADIS16448::ADIS16448(std::string initStr) : mraaIo(initStr)
|
|||||||
std::string::size_type sz;
|
std::string::size_type sz;
|
||||||
|
|
||||||
for (std::string tok : upmTokens) {
|
for (std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,9) == "regWrite:") {
|
if(tok.substr(0, 9) == "regWrite:") {
|
||||||
uint8_t regAddr = std::stoi(tok.substr(9),&sz,0);
|
uint8_t regAddr = std::stoi(tok.substr(9), &sz, 0);
|
||||||
tok = tok.substr(9);
|
tok = tok.substr(9);
|
||||||
uint16_t regData = std::stoi(tok.substr(sz+1),nullptr,0);
|
uint16_t regData = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
regWrite(regAddr, regData);
|
regWrite(regAddr, regData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,19 +32,24 @@
|
|||||||
|
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
ADS1X15::ADS1X15(int bus, uint8_t address){
|
static bool operator!(mraa::MraaIo &mraaIo)
|
||||||
|
{
|
||||||
|
return mraaIo.getMraaDescriptors() == NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if(!(i2c = new mraa::I2c(bus))){
|
ADS1X15::ADS1X15(int bus, uint8_t address) {
|
||||||
|
|
||||||
|
if(!(i2c = new mraa::I2c(bus))) {
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +": I2c.init() failed");
|
throw std::invalid_argument(std::string(__FUNCTION__) +": I2c.init() failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((i2c->address(address) != mraa::SUCCESS)){
|
if((i2c->address(address) != mraa::SUCCESS)) {
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.address() failed");
|
throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.address() failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i2c->frequency( mraa::I2C_FAST) != mraa::SUCCESS){
|
if(i2c->frequency( mraa::I2C_FAST) != mraa::SUCCESS) {
|
||||||
syslog(LOG_WARNING, "%s: I2c.frequency(I2C_FAST) failed, using default speed", std::string(__FUNCTION__).c_str());
|
syslog(LOG_WARNING, "%s: I2c.frequency(I2C_FAST) failed, using default speed", std::string(__FUNCTION__).c_str());
|
||||||
}
|
}
|
||||||
//Will be reset by sub class.
|
//Will be reset by sub class.
|
||||||
@ -54,24 +59,16 @@ 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 {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.init() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mraaIo->i2cs.empty())
|
if(i2c->frequency( mraa::I2C_FAST) != mraa::SUCCESS) {
|
||||||
{
|
|
||||||
i2c = &mraaIo->i2cs[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +": I2c.init() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i2c->frequency( mraa::I2C_FAST) != mraa::SUCCESS){
|
|
||||||
syslog(LOG_WARNING, "%s: I2c.frequency(I2C_FAST) failed, using default speed", std::string(__FUNCTION__).c_str());
|
syslog(LOG_WARNING, "%s: I2c.frequency(I2C_FAST) failed, using default speed", std::string(__FUNCTION__).c_str());
|
||||||
}
|
}
|
||||||
//Will be reset by sub class.
|
//Will be reset by sub class.
|
||||||
@ -81,40 +78,41 @@ 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;
|
||||||
|
|
||||||
for (std::string tok : upmTokens) {
|
for (std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,12) == "setCompMode:") {
|
if(tok.substr(0, 12) == "setCompMode:") {
|
||||||
bool mode = std::stoi(tok.substr(12),nullptr,0);
|
bool mode = std::stoi(tok.substr(12), nullptr, 0);
|
||||||
setCompMode(mode);
|
setCompMode(mode);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,11) == "setCompPol:") {
|
if(tok.substr(0, 11) == "setCompPol:") {
|
||||||
bool mode = std::stoi(tok.substr(11),nullptr,0);
|
bool mode = std::stoi(tok.substr(11), nullptr, 0);
|
||||||
setCompPol(mode);
|
setCompPol(mode);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,13) == "setCompLatch:") {
|
if(tok.substr(0, 13) == "setCompLatch:") {
|
||||||
bool mode = std::stoi(tok.substr(13),nullptr,0);
|
bool mode = std::stoi(tok.substr(13), nullptr, 0);
|
||||||
setCompLatch(mode);
|
setCompLatch(mode);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,14) == "setContinuous:") {
|
if(tok.substr(0, 14) == "setContinuous:") {
|
||||||
bool mode = std::stoi(tok.substr(14),nullptr,0);
|
bool mode = std::stoi(tok.substr(14), nullptr, 0);
|
||||||
setContinuous(mode);
|
setContinuous(mode);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,21) == "updateConfigRegister:") {
|
if(tok.substr(0, 21) == "updateConfigRegister:") {
|
||||||
uint16_t update = std::stoi(tok.substr(21),&sz,0);
|
uint16_t update = std::stoi(tok.substr(21),&sz,0);
|
||||||
tok = tok.substr(21);
|
tok = tok.substr(21);
|
||||||
bool read = std::stoi(tok.substr(sz+1),nullptr,0);
|
bool read = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
updateConfigRegister(update,read);
|
updateConfigRegister(update, read);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
};}
|
};}
|
||||||
|
@ -76,25 +76,32 @@ ADXL335::ADXL335(std::string initStr) : mraaIo(initStr)
|
|||||||
if(!descs->aios)
|
if(!descs->aios)
|
||||||
{
|
{
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
printf("ADXL335 else inside constructor\n");
|
printf("ADXL335 else inside constructor\n");
|
||||||
if( !(m_aioX = descs->aios[0]) )
|
if(descs->n_aio == 3)
|
||||||
|
{
|
||||||
|
if( !(m_aioX = descs->aios[0]) )
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_aio_init(X) failed, invalid pin?");
|
||||||
|
}
|
||||||
|
if( !(m_aioY = descs->aios[1]) )
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_aio_init(X) failed, invalid pin?");
|
||||||
|
}
|
||||||
|
if( !(m_aioZ = descs->aios[2]) )
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_aio_init(X) failed, invalid pin?");
|
||||||
|
}
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
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) must initialize three pins");
|
||||||
}
|
|
||||||
if( !(m_aioY = descs->aios[1]) )
|
|
||||||
{
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_aio_init(X) failed, invalid pin?");
|
|
||||||
}
|
|
||||||
if( !(m_aioZ = descs->aios[2]) )
|
|
||||||
{
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_aio_init(X) failed, invalid pin?");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +112,7 @@ ADXL335::ADXL335(std::string initStr) : mraaIo(initStr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (std::string tok : upmTokens) {
|
for (std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,5) == "aref:") {
|
if(tok.substr(0, 5) == "aref:") {
|
||||||
m_aref = std::stof(tok.substr(5));
|
m_aref = std::stof(tok.substr(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ ADXRS610::ADXRS610(std::string initStr) : mraaIo(new mraa::MraaIo(initStr))
|
|||||||
setDeadband(0.0);
|
setDeadband(0.0);
|
||||||
|
|
||||||
for (std::string tok : upmTokens) {
|
for (std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,5) == "aref:") {
|
if(tok.substr(0, 5) == "aref:") {
|
||||||
m_aref = std::stof(tok.substr(5));
|
m_aref = std::stof(tok.substr(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ AM2315::AM2315(std::string initStr) : mraaIo(initStr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (std::string tok : upmTokens) {
|
for (std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,13) == "updateValues:") {
|
if(tok.substr(0, 13) == "updateValues:") {
|
||||||
update_values();
|
update_values();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,12 +66,12 @@ APDS9930::APDS9930(std::string initStr) : mraaIo(initStr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (std::string tok : upmTokens) {
|
for (std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,16) == "enableProximity:") {
|
if(tok.substr(0, 16) == "enableProximity:") {
|
||||||
bool enable = std::stoi(tok.substr(16),nullptr,0);
|
bool enable = std::stoi(tok.substr(16), nullptr, 0);
|
||||||
enableProximity(enable);
|
enableProximity(enable);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,18) == "enableIlluminance:") {
|
if(tok.substr(0, 18) == "enableIlluminance:") {
|
||||||
bool enable = std::stoi(tok.substr(18),nullptr,0);
|
bool enable = std::stoi(tok.substr(18), nullptr, 0);
|
||||||
enableIlluminance(enable);
|
enableIlluminance(enable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ BH1750::BH1750(std::string initStr) : mraaIo(initStr)
|
|||||||
for (std::string tok : upmTokens)
|
for (std::string tok : upmTokens)
|
||||||
{
|
{
|
||||||
if(tok.substr(0, 5) == "mode:") {
|
if(tok.substr(0, 5) == "mode:") {
|
||||||
BH1750_OPMODES_T mode = (BH1750_OPMODES_T)std::stoi(tok.substr(5),nullptr,0);
|
BH1750_OPMODES_T mode = (BH1750_OPMODES_T)std::stoi(tok.substr(5), nullptr, 0);
|
||||||
if(bh1750_set_opmode(m_bh1750, mode) != UPM_SUCCESS)
|
if(bh1750_set_opmode(m_bh1750, mode) != UPM_SUCCESS)
|
||||||
{
|
{
|
||||||
bh1750_close(m_bh1750);
|
bh1750_close(m_bh1750);
|
||||||
@ -96,7 +96,7 @@ BH1750::BH1750(std::string initStr) : mraaIo(initStr)
|
|||||||
powerDown();
|
powerDown();
|
||||||
}
|
}
|
||||||
if(tok.substr(0, 12) == "sendCommand:") {
|
if(tok.substr(0, 12) == "sendCommand:") {
|
||||||
uint8_t mode = (uint8_t)std::stoi(tok.substr(12),nullptr,0);
|
uint8_t mode = (uint8_t)std::stoi(tok.substr(12), nullptr, 0);
|
||||||
sendCommand(mode);
|
sendCommand(mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,31 +106,31 @@ BMA220::BMA220(std::string initStr) : mraaIo(new mraa::MraaIo(initStr))
|
|||||||
|
|
||||||
for(std::string tok :upmTokens)
|
for(std::string tok :upmTokens)
|
||||||
{
|
{
|
||||||
if(tok.substr(0,9) == "writeReg:") {
|
if(tok.substr(0, 9) == "writeReg:") {
|
||||||
uint8_t reg = std::stoi(tok.substr(9),&sz,0);
|
uint8_t reg = std::stoi(tok.substr(9), &sz, 0);
|
||||||
tok = tok.substr(9);
|
tok = tok.substr(9);
|
||||||
uint8_t val = std::stoi(tok.substr(sz+1),nullptr,0);
|
uint8_t val = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
writeReg(reg, val);
|
writeReg(reg, val);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,22) == "setAccelerometerScale:") {
|
if(tok.substr(0, 22) == "setAccelerometerScale:") {
|
||||||
FSL_RANGE_T scale = (FSL_RANGE_T)std::stoi(tok.substr(22),nullptr,0);
|
FSL_RANGE_T scale = (FSL_RANGE_T)std::stoi(tok.substr(22), nullptr, 0);
|
||||||
setAccelerometerScale(scale);
|
setAccelerometerScale(scale);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,16) == "setFilterConfig:") {
|
if(tok.substr(0, 16) == "setFilterConfig:") {
|
||||||
FILTER_CONFIG_T filter = (FILTER_CONFIG_T)std::stoi(tok.substr(16),nullptr,0);
|
FILTER_CONFIG_T filter = (FILTER_CONFIG_T)std::stoi(tok.substr(16), nullptr, 0);
|
||||||
setFilterConfig(filter);
|
setFilterConfig(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tok.substr(0,16) == "setSerialHighBW:") {
|
if(tok.substr(0, 16) == "setSerialHighBW:") {
|
||||||
bool high = std::stoi(tok.substr(16),nullptr,0);
|
bool high = std::stoi(tok.substr(16), nullptr, 0);
|
||||||
setSerialHighBW(high);
|
setSerialHighBW(high);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,16) == "setFilterConfig:") {
|
if(tok.substr(0, 16) == "setFilterConfig:") {
|
||||||
FILTER_CONFIG_T filter = (FILTER_CONFIG_T)std::stoi(tok.substr(16),nullptr,0);
|
FILTER_CONFIG_T filter = (FILTER_CONFIG_T)std::stoi(tok.substr(16), nullptr, 0);
|
||||||
setFilterConfig(filter);
|
setFilterConfig(filter);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,16) == "setFilterConfig:") {
|
if(tok.substr(0, 16) == "setFilterConfig:") {
|
||||||
FILTER_CONFIG_T filter = (FILTER_CONFIG_T)std::stoi(tok.substr(16),nullptr,0);
|
FILTER_CONFIG_T filter = (FILTER_CONFIG_T)std::stoi(tok.substr(16), nullptr, 0);
|
||||||
setFilterConfig(filter);
|
setFilterConfig(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,81 +161,81 @@ BMA250E::BMA250E(std::string initStr) : mraaIo(initStr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string::size_type sz;
|
std::string::size_type sz;
|
||||||
for(std::string tok:upmTokens) {
|
for(std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,11) == "enableFIFO:") {
|
if(tok.substr(0, 11) == "enableFIFO:") {
|
||||||
bool useFIFO = std::stoi(tok.substr(11),&sz,0);
|
bool useFIFO = std::stoi(tok.substr(11), &sz, 0);
|
||||||
enableFIFO(useFIFO);
|
enableFIFO(useFIFO);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,9) == "writeReg:") {
|
if(tok.substr(0, 9) == "writeReg:") {
|
||||||
uint8_t reg = std::stoi(tok.substr(9),&sz,0);
|
uint8_t reg = std::stoi(tok.substr(9), &sz, 0);
|
||||||
tok = tok.substr(9);
|
tok = tok.substr(9);
|
||||||
uint8_t val = std::stoi(tok.substr(sz+1),nullptr,0);
|
uint8_t val = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
writeReg(reg, val);
|
writeReg(reg, val);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,9) == "setRange:") {
|
if(tok.substr(0, 9) == "setRange:") {
|
||||||
BMA250E_RANGE_T scale = (BMA250E_RANGE_T)std::stoi(tok.substr(9),nullptr,0);
|
BMA250E_RANGE_T scale = (BMA250E_RANGE_T)std::stoi(tok.substr(9), nullptr, 0);
|
||||||
setRange(scale);
|
setRange(scale);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,13) == "setBandwidth:") {
|
if(tok.substr(0, 13) == "setBandwidth:") {
|
||||||
BMA250E_BW_T bw = (BMA250E_BW_T)std::stoi(tok.substr(13),nullptr,0);
|
BMA250E_BW_T bw = (BMA250E_BW_T)std::stoi(tok.substr(13), nullptr, 0);
|
||||||
setBandwidth(bw);
|
setBandwidth(bw);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,13) == "setPowerMode:") {
|
if(tok.substr(0, 13) == "setPowerMode:") {
|
||||||
BMA250E_POWER_MODE_T power = (BMA250E_POWER_MODE_T)std::stoi(tok.substr(13),nullptr,0);
|
BMA250E_POWER_MODE_T power = (BMA250E_POWER_MODE_T)std::stoi(tok.substr(13), nullptr, 0);
|
||||||
setPowerMode(power);
|
setPowerMode(power);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "fifoSetWatermark:") {
|
if(tok.substr(0, 17) == "fifoSetWatermark:") {
|
||||||
BMA250E_RANGE_T wm = (BMA250E_RANGE_T)std::stoi(tok.substr(17),nullptr,0);
|
BMA250E_RANGE_T wm = (BMA250E_RANGE_T)std::stoi(tok.substr(17), nullptr, 0);
|
||||||
fifoSetWatermark(wm);
|
fifoSetWatermark(wm);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,11) == "fifoConfig:") {
|
if(tok.substr(0, 11) == "fifoConfig:") {
|
||||||
BMA250E_FIFO_MODE_T mode = (BMA250E_FIFO_MODE_T)std::stoi(tok.substr(11),&sz,0);
|
BMA250E_FIFO_MODE_T mode = (BMA250E_FIFO_MODE_T)std::stoi(tok.substr(11), &sz, 0);
|
||||||
tok = tok.substr(11);
|
tok = tok.substr(11);
|
||||||
BMA250E_FIFO_DATA_SEL_T axes = (BMA250E_FIFO_DATA_SEL_T)std::stoi(tok.substr(sz+1),nullptr,0);
|
BMA250E_FIFO_DATA_SEL_T axes = (BMA250E_FIFO_DATA_SEL_T)std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
fifoConfig(mode, axes);
|
fifoConfig(mode, axes);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,20) == "setInterruptEnable0:") {
|
if(tok.substr(0, 20) == "setInterruptEnable0:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(20),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(20), nullptr, 0);
|
||||||
setInterruptEnable0(bits);
|
setInterruptEnable0(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,20) == "setInterruptEnable1:") {
|
if(tok.substr(0, 20) == "setInterruptEnable1:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(20),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(20), nullptr, 0);
|
||||||
setInterruptEnable1(bits);
|
setInterruptEnable1(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,20) == "setInterruptEnable2:") {
|
if(tok.substr(0, 20) == "setInterruptEnable2:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(20),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(20), nullptr, 0);
|
||||||
setInterruptEnable2(bits);
|
setInterruptEnable2(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "setInterruptMap0:") {
|
if(tok.substr(0, 17) == "setInterruptMap0:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17), nullptr, 0);
|
||||||
setInterruptMap0(bits);
|
setInterruptMap0(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "setInterruptMap1:") {
|
if(tok.substr(0, 17) == "setInterruptMap1:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17), nullptr, 0);
|
||||||
setInterruptMap1(bits);
|
setInterruptMap1(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "setInterruptMap2:") {
|
if(tok.substr(0, 17) == "setInterruptMap2:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17), nullptr, 0);
|
||||||
setInterruptMap2(bits);
|
setInterruptMap2(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,16) == "setInterruptSrc:") {
|
if(tok.substr(0, 16) == "setInterruptSrc:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(16),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(16), nullptr, 0);
|
||||||
setInterruptSrc(bits);
|
setInterruptSrc(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,26) == "setInterruptOutputControl:") {
|
if(tok.substr(0, 26) == "setInterruptOutputControl:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(26),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(26), nullptr, 0);
|
||||||
setInterruptOutputControl(bits);
|
setInterruptOutputControl(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,26) == "setInterruptLatchBehavior:") {
|
if(tok.substr(0, 26) == "setInterruptLatchBehavior:") {
|
||||||
BMA250E_RST_LATCH_T latch = (BMA250E_RST_LATCH_T)std::stoi(tok.substr(26),nullptr,0);
|
BMA250E_RST_LATCH_T latch = (BMA250E_RST_LATCH_T)std::stoi(tok.substr(26), nullptr, 0);
|
||||||
setInterruptLatchBehavior(latch);
|
setInterruptLatchBehavior(latch);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,24) == "enableRegisterShadowing:") {
|
if(tok.substr(0, 24) == "enableRegisterShadowing:") {
|
||||||
bool shadow = std::stoi(tok.substr(24),nullptr,0);
|
bool shadow = std::stoi(tok.substr(24), nullptr, 0);
|
||||||
enableRegisterShadowing(shadow);
|
enableRegisterShadowing(shadow);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,22) == "enableOutputFiltering:") {
|
if(tok.substr(0, 22) == "enableOutputFiltering:") {
|
||||||
bool filter = std::stoi(tok.substr(22),nullptr,0);
|
bool filter = std::stoi(tok.substr(22), nullptr, 0);
|
||||||
enableOutputFiltering(filter);
|
enableOutputFiltering(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,68 +140,68 @@ BMG160::BMG160(std::string initStr) : mraaIo(initStr)
|
|||||||
|
|
||||||
std::string::size_type sz;
|
std::string::size_type sz;
|
||||||
for(std::string tok:upmTokens) {
|
for(std::string tok:upmTokens) {
|
||||||
if(tok.substr(0,11) == "enableFIFO:") {
|
if(tok.substr(0, 11) == "enableFIFO:") {
|
||||||
bool useFIFO = std::stoi(tok.substr(11),&sz,0);
|
bool useFIFO = std::stoi(tok.substr(11), &sz, 0);
|
||||||
enableFIFO(useFIFO);
|
enableFIFO(useFIFO);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,9) == "writeReg:") {
|
if(tok.substr(0, 9) == "writeReg:") {
|
||||||
uint8_t reg = std::stoi(tok.substr(9),&sz,0);
|
uint8_t reg = std::stoi(tok.substr(9), &sz, 0);
|
||||||
tok = tok.substr(9);
|
tok = tok.substr(9);
|
||||||
uint8_t val = std::stoi(tok.substr(sz+1),nullptr,0);
|
uint8_t val = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
writeReg(reg, val);
|
writeReg(reg, val);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,9) == "setRange:") {
|
if(tok.substr(0, 9) == "setRange:") {
|
||||||
BMG160_RANGE_T scale = (BMG160_RANGE_T)std::stoi(tok.substr(22),nullptr,0);
|
BMG160_RANGE_T scale = (BMG160_RANGE_T)std::stoi(tok.substr(22), nullptr, 0);
|
||||||
setRange(scale);
|
setRange(scale);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,13) == "setBandwidth:") {
|
if(tok.substr(0, 13) == "setBandwidth:") {
|
||||||
BMG160_BW_T bw = (BMG160_BW_T)std::stoi(tok.substr(13),nullptr,0);
|
BMG160_BW_T bw = (BMG160_BW_T)std::stoi(tok.substr(13), nullptr, 0);
|
||||||
setBandwidth(bw);
|
setBandwidth(bw);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,13) == "setPowerMode:") {
|
if(tok.substr(0, 13) == "setPowerMode:") {
|
||||||
BMG160_POWER_MODE_T power = (BMG160_POWER_MODE_T)std::stoi(tok.substr(13),nullptr,0);
|
BMG160_POWER_MODE_T power = (BMG160_POWER_MODE_T)std::stoi(tok.substr(13), nullptr, 0);
|
||||||
setPowerMode(power);
|
setPowerMode(power);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "fifoSetWatermark:") {
|
if(tok.substr(0, 17) == "fifoSetWatermark:") {
|
||||||
BMG160_RANGE_T wm = (BMG160_RANGE_T)std::stoi(tok.substr(17),nullptr,0);
|
BMG160_RANGE_T wm = (BMG160_RANGE_T)std::stoi(tok.substr(17), nullptr, 0);
|
||||||
fifoSetWatermark(wm);
|
fifoSetWatermark(wm);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,11) == "fifoConfig:") {
|
if(tok.substr(0, 11) == "fifoConfig:") {
|
||||||
BMG160_FIFO_MODE_T mode = (BMG160_FIFO_MODE_T)std::stoi(tok.substr(11),&sz,0);
|
BMG160_FIFO_MODE_T mode = (BMG160_FIFO_MODE_T)std::stoi(tok.substr(11), &sz, 0);
|
||||||
tok = tok.substr(11);
|
tok = tok.substr(11);
|
||||||
BMG160_FIFO_DATA_SEL_T axes = (BMG160_FIFO_DATA_SEL_T)std::stoi(tok.substr(sz+1),nullptr,0);
|
BMG160_FIFO_DATA_SEL_T axes = (BMG160_FIFO_DATA_SEL_T)std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
fifoConfig(mode, axes);
|
fifoConfig(mode, axes);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,20) == "setInterruptEnable0:") {
|
if(tok.substr(0, 20) == "setInterruptEnable0:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(20),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(20), nullptr, 0);
|
||||||
setInterruptEnable0(bits);
|
setInterruptEnable0(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "setInterruptMap0:") {
|
if(tok.substr(0, 17) == "setInterruptMap0:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17), nullptr, 0);
|
||||||
setInterruptMap0(bits);
|
setInterruptMap0(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "setInterruptMap1:") {
|
if(tok.substr(0, 17) == "setInterruptMap1:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(17), nullptr, 0);
|
||||||
setInterruptMap1(bits);
|
setInterruptMap1(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,16) == "setInterruptSrc:") {
|
if(tok.substr(0, 16) == "setInterruptSrc:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(16),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(16), nullptr, 0);
|
||||||
setInterruptSrc(bits);
|
setInterruptSrc(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,26) == "setInterruptOutputControl:") {
|
if(tok.substr(0, 26) == "setInterruptOutputControl:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(26),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(26), nullptr, 0);
|
||||||
setInterruptOutputControl(bits);
|
setInterruptOutputControl(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,26) == "setInterruptLatchBehavior:") {
|
if(tok.substr(0, 26) == "setInterruptLatchBehavior:") {
|
||||||
BMG160_RST_LATCH_T latch = (BMG160_RST_LATCH_T)std::stoi(tok.substr(26),nullptr,0);
|
BMG160_RST_LATCH_T latch = (BMG160_RST_LATCH_T)std::stoi(tok.substr(26), nullptr, 0);
|
||||||
setInterruptLatchBehavior(latch);
|
setInterruptLatchBehavior(latch);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,24) == "enableRegisterShadowing:") {
|
if(tok.substr(0, 24) == "enableRegisterShadowing:") {
|
||||||
bool shadow = std::stoi(tok.substr(24),nullptr,0);
|
bool shadow = std::stoi(tok.substr(24), nullptr, 0);
|
||||||
enableRegisterShadowing(shadow);
|
enableRegisterShadowing(shadow);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,22) == "enableOutputFiltering:") {
|
if(tok.substr(0, 22) == "enableOutputFiltering:") {
|
||||||
bool filter = std::stoi(tok.substr(22),nullptr,0);
|
bool filter = std::stoi(tok.substr(22), nullptr, 0);
|
||||||
enableOutputFiltering(filter);
|
enableOutputFiltering(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,47 +146,47 @@ BMM150::BMM150(std::string initStr) : mraaIo(initStr)
|
|||||||
|
|
||||||
std::string::size_type sz;
|
std::string::size_type sz;
|
||||||
for(std::string tok:upmTokens) {
|
for(std::string tok:upmTokens) {
|
||||||
if(tok.substr(0,5) == "init:") {
|
if(tok.substr(0, 5) == "init:") {
|
||||||
BMM150_USAGE_PRESETS_T usage = (BMM150_USAGE_PRESETS_T)std::stoi(tok.substr(5),nullptr,0);
|
BMM150_USAGE_PRESETS_T usage = (BMM150_USAGE_PRESETS_T)std::stoi(tok.substr(5), nullptr, 0);
|
||||||
init(usage);
|
init(usage);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,9) == "writeReg:") {
|
if(tok.substr(0, 9) == "writeReg:") {
|
||||||
uint8_t reg = std::stoi(tok.substr(9),&sz,0);
|
uint8_t reg = std::stoi(tok.substr(9), &sz, 0);
|
||||||
tok = tok.substr(9);
|
tok = tok.substr(9);
|
||||||
uint8_t val = std::stoi(tok.substr(sz+1),nullptr,0);
|
uint8_t val = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
writeReg(reg, val);
|
writeReg(reg, val);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,18) == "setOutputDataRate:") {
|
if(tok.substr(0, 18) == "setOutputDataRate:") {
|
||||||
BMM150_DATA_RATE_T odr = (BMM150_DATA_RATE_T)std::stoi(tok.substr(18),nullptr,0);
|
BMM150_DATA_RATE_T odr = (BMM150_DATA_RATE_T)std::stoi(tok.substr(18), nullptr, 0);
|
||||||
setOutputDataRate(odr);
|
setOutputDataRate(odr);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,12) == "setPowerBit:") {
|
if(tok.substr(0, 12) == "setPowerBit:") {
|
||||||
bool power = std::stoi(tok.substr(12),&sz,0);
|
bool power = std::stoi(tok.substr(12), &sz, 0);
|
||||||
setPowerBit(power);
|
setPowerBit(power);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tok.substr(0,10) == "setOpmode:") {
|
if(tok.substr(0, 10) == "setOpmode:") {
|
||||||
BMM150_OPERATION_MODE_T opmode = (BMM150_OPERATION_MODE_T)std::stoi(tok.substr(10),nullptr,0);
|
BMM150_OPERATION_MODE_T opmode = (BMM150_OPERATION_MODE_T)std::stoi(tok.substr(10), nullptr, 0);
|
||||||
setOpmode(opmode);
|
setOpmode(opmode);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,19) == "setInterruptEnable:") {
|
if(tok.substr(0, 19) == "setInterruptEnable:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(19),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(19), nullptr, 0);
|
||||||
setInterruptEnable(bits);
|
setInterruptEnable(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,19) == "setInterruptConfig:") {
|
if(tok.substr(0, 19) == "setInterruptConfig:") {
|
||||||
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(19),nullptr,0);
|
u_int8_t bits = (u_int8_t)std::stoi(tok.substr(19), nullptr, 0);
|
||||||
setInterruptConfig(bits);
|
setInterruptConfig(bits);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "setRepetitionsXY:") {
|
if(tok.substr(0, 17) == "setRepetitionsXY:") {
|
||||||
u_int8_t reps = (u_int8_t)std::stoi(tok.substr(17),nullptr,0);
|
u_int8_t reps = (u_int8_t)std::stoi(tok.substr(17), nullptr, 0);
|
||||||
setRepetitionsXY(reps);
|
setRepetitionsXY(reps);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,16) == "setRepetitionsZ:") {
|
if(tok.substr(0, 16) == "setRepetitionsZ:") {
|
||||||
u_int8_t reps = (u_int8_t)std::stoi(tok.substr(16),nullptr,0);
|
u_int8_t reps = (u_int8_t)std::stoi(tok.substr(16), nullptr, 0);
|
||||||
setRepetitionsZ(reps);
|
setRepetitionsZ(reps);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,14) == "setPresetMode:") {
|
if(tok.substr(0, 14) == "setPresetMode:") {
|
||||||
BMM150_USAGE_PRESETS_T usage = (BMM150_USAGE_PRESETS_T)std::stoi(tok.substr(14),nullptr,0);
|
BMM150_USAGE_PRESETS_T usage = (BMM150_USAGE_PRESETS_T)std::stoi(tok.substr(14), nullptr, 0);
|
||||||
setPresetMode(usage);
|
setPresetMode(usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,38 +165,38 @@ BMP280::BMP280(std::string initStr) : mraaIo(initStr)
|
|||||||
|
|
||||||
std::string::size_type sz;
|
std::string::size_type sz;
|
||||||
for(std::string tok:upmTokens) {
|
for(std::string tok:upmTokens) {
|
||||||
if(tok.substr(0,21) == "setSeaLevelPreassure:") {
|
if(tok.substr(0, 21) == "setSeaLevelPreassure:") {
|
||||||
float seaLevelhPA = std::stof(tok.substr(21));
|
float seaLevelhPA = std::stof(tok.substr(21));
|
||||||
setSeaLevelPreassure(seaLevelhPA);
|
setSeaLevelPreassure(seaLevelhPA);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,9) == "writeReg:") {
|
if(tok.substr(0, 9) == "writeReg:") {
|
||||||
uint8_t reg = std::stoi(tok.substr(9),&sz,0);
|
uint8_t reg = std::stoi(tok.substr(9), &sz, 0);
|
||||||
tok = tok.substr(9);
|
tok = tok.substr(9);
|
||||||
uint8_t val = std::stoi(tok.substr(sz+1),nullptr,0);
|
uint8_t val = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
writeReg(reg, val);
|
writeReg(reg, val);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,10) == "setFilter:") {
|
if(tok.substr(0, 10) == "setFilter:") {
|
||||||
BMP280_FILTER_T filter = (BMP280_FILTER_T)std::stoi(tok.substr(10),nullptr,0);
|
BMP280_FILTER_T filter = (BMP280_FILTER_T)std::stoi(tok.substr(10), nullptr, 0);
|
||||||
setFilter(filter);
|
setFilter(filter);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,16) == "setTimerStandby:") {
|
if(tok.substr(0, 16) == "setTimerStandby:") {
|
||||||
BMP280_T_SB_T tsb = (BMP280_T_SB_T)std::stoi(tok.substr(16),nullptr,0);
|
BMP280_T_SB_T tsb = (BMP280_T_SB_T)std::stoi(tok.substr(16), nullptr, 0);
|
||||||
setTimerStandby(tsb);
|
setTimerStandby(tsb);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,15) == "setMeasureMode:") {
|
if(tok.substr(0, 15) == "setMeasureMode:") {
|
||||||
BMP280_MODES_T mode = (BMP280_MODES_T)std::stoi(tok.substr(15),nullptr,0);
|
BMP280_MODES_T mode = (BMP280_MODES_T)std::stoi(tok.substr(15), nullptr, 0);
|
||||||
setMeasureMode(mode);
|
setMeasureMode(mode);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,26) == "setOversampleRatePressure:") {
|
if(tok.substr(0, 26) == "setOversampleRatePressure:") {
|
||||||
BMP280_OSRS_P_T rate = (BMP280_OSRS_P_T)std::stoi(tok.substr(26),nullptr,0);
|
BMP280_OSRS_P_T rate = (BMP280_OSRS_P_T)std::stoi(tok.substr(26), nullptr, 0);
|
||||||
setOversampleRatePressure(rate);
|
setOversampleRatePressure(rate);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,29) == "setOversampleRateTemperature:") {
|
if(tok.substr(0, 29) == "setOversampleRateTemperature:") {
|
||||||
BMP280_OSRS_T_T rate = (BMP280_OSRS_T_T)std::stoi(tok.substr(29),nullptr,0);
|
BMP280_OSRS_T_T rate = (BMP280_OSRS_T_T)std::stoi(tok.substr(29), nullptr, 0);
|
||||||
setOversampleRateTemperature(rate);
|
setOversampleRateTemperature(rate);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,13) == "setUsageMode:") {
|
if(tok.substr(0, 13) == "setUsageMode:") {
|
||||||
BMP280_USAGE_MODE_T mode = (BMP280_USAGE_MODE_T)std::stoi(tok.substr(13),nullptr,0);
|
BMP280_USAGE_MODE_T mode = (BMP280_USAGE_MODE_T)std::stoi(tok.substr(13), nullptr, 0);
|
||||||
setUsageMode(mode);
|
setUsageMode(mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,15 +104,15 @@ BMPX8X::BMPX8X(std::string initStr) : mraaIo(initStr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string::size_type sz;
|
std::string::size_type sz;
|
||||||
for(std::string tok:upmTokens) {
|
for(std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,16) == "setOversampling:") {
|
if(tok.substr(0, 16) == "setOversampling:") {
|
||||||
BMPX8X_OSS_T oss = (BMPX8X_OSS_T)std::stoi(tok.substr(16),nullptr,0);
|
BMPX8X_OSS_T oss = (BMPX8X_OSS_T)std::stoi(tok.substr(16), nullptr, 0);
|
||||||
setOversampling(oss);
|
setOversampling(oss);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,9) == "writeReg:") {
|
if(tok.substr(0, 9) == "writeReg:") {
|
||||||
uint8_t reg = std::stoi(tok.substr(9),&sz,0);
|
uint8_t reg = std::stoi(tok.substr(9), &sz, 0);
|
||||||
tok = tok.substr(9);
|
tok = tok.substr(9);
|
||||||
uint8_t val = std::stoi(tok.substr(sz+1),nullptr,0);
|
uint8_t val = std::stoi(tok.substr(sz+1), nullptr, 0);
|
||||||
writeReg(reg, val);
|
writeReg(reg, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,24 +84,24 @@ CJQ4435::CJQ4435(std::string initStr) : mraaIo(initStr)
|
|||||||
m_cjq4435->enabled = false;
|
m_cjq4435->enabled = false;
|
||||||
|
|
||||||
for(std::string tok : upmTokens) {
|
for(std::string tok : upmTokens) {
|
||||||
if(tok.substr(0,12) == "setPeriodUS:") {
|
if(tok.substr(0, 12) == "setPeriodUS:") {
|
||||||
int us = std::stoi(tok.substr(0,12),nullptr,0);
|
int us = std::stoi(tok.substr(0, 12), nullptr, 0);
|
||||||
setPeriodUS(us);
|
setPeriodUS(us);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,12) == "setPeriodMS:") {
|
if(tok.substr(0, 12) == "setPeriodMS:") {
|
||||||
int ms = std::stoi(tok.substr(0,12),nullptr,0);
|
int ms = std::stoi(tok.substr(0, 12), nullptr, 0);
|
||||||
setPeriodMS(ms);
|
setPeriodMS(ms);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,17) == "setPeriodSeconds:") {
|
if(tok.substr(0, 17) == "setPeriodSeconds:") {
|
||||||
float seconds = std::stof(tok.substr(0,17));
|
float seconds = std::stof(tok.substr(0, 17));
|
||||||
setPeriodSeconds(seconds);
|
setPeriodSeconds(seconds);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,7) == "enable:") {
|
if(tok.substr(0, 7) == "enable:") {
|
||||||
bool en = std::stoi(tok.substr(0,7),nullptr,0);
|
bool en = std::stoi(tok.substr(0, 7), nullptr, 0);
|
||||||
enable(en);
|
enable(en);
|
||||||
}
|
}
|
||||||
if(tok.substr(0,13) == "setDutyCycle:") {
|
if(tok.substr(0, 13) == "setDutyCycle:") {
|
||||||
float dutyCycle = std::stof(tok.substr(0,13));
|
float dutyCycle = std::stof(tok.substr(0, 13));
|
||||||
setDutyCycle(dutyCycle);
|
setDutyCycle(dutyCycle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,14 +123,14 @@ CWLSXXA::CWLSXXA(std::string initStr)
|
|||||||
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) == "aref:")
|
if(tok.substr(0, 5) == "aref:")
|
||||||
{
|
{
|
||||||
float aref = std::stof(tok.substr(5));
|
float aref = std::stof(tok.substr(5));
|
||||||
m_aref = aref;
|
m_aref = aref;
|
||||||
}
|
}
|
||||||
if(tok.substr(0,10) == "rResistor:")
|
if(tok.substr(0, 10) == "rResistor:")
|
||||||
{
|
{
|
||||||
float rResistor = std::stof(tok.substr(10));
|
float rResistor = std::stof(tok.substr(10));
|
||||||
m_rResistor = rResistor;
|
m_rResistor = rResistor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user