ads1x15: changed error types to runtime errors on failed i2c ops

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Tudor Panu 2016-08-12 12:27:13 -07:00
parent 2b642ab7a4
commit 9a83bb7530

View File

@ -38,7 +38,7 @@ ADS1X15::ADS1X15(int bus, uint8_t address){
} }
if((i2c->address(address) != mraa::SUCCESS)){ if((i2c->address(address) != mraa::SUCCESS)){
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.address() failed"); throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.address() failed");
return; return;
} }
@ -125,11 +125,11 @@ ADS1X15::setThresh(ADSTHRESH reg, float value){
switch((int)reg){ switch((int)reg){
case 4: //set conversion_rdy operation case 4: //set conversion_rdy operation
if(i2c->writeWordReg(ADS1X15_REG_POINTER_LOWTHRESH, 0x0000) != mraa::SUCCESS){ if(i2c->writeWordReg(ADS1X15_REG_POINTER_LOWTHRESH, 0x0000) != mraa::SUCCESS){
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed"); throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.write() failed");
return; return;
} }
if(i2c->writeWordReg(ADS1X15_REG_POINTER_HITHRESH, 0x0080) != mraa::SUCCESS){ if(i2c->writeWordReg(ADS1X15_REG_POINTER_HITHRESH, 0x0080) != mraa::SUCCESS){
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed"); throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.write() failed");
return; return;
} }
break; break;
@ -138,18 +138,18 @@ ADS1X15::setThresh(ADSTHRESH reg, float value){
set_value = value / getMultiplier(); set_value = value / getMultiplier();
set_value = set_value << m_bitShift; set_value = set_value << m_bitShift;
if(i2c->writeWordReg(reg, swapWord(set_value)) != mraa::SUCCESS){ if(i2c->writeWordReg(reg, swapWord(set_value)) != mraa::SUCCESS){
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed"); throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.write() failed");
return; return;
} }
break; break;
case 5: //set default case 5: //set default
default: default:
if(i2c->writeWordReg(ADS1X15_REG_POINTER_LOWTHRESH, 0x0080) != mraa::SUCCESS){ if(i2c->writeWordReg(ADS1X15_REG_POINTER_LOWTHRESH, 0x0080) != mraa::SUCCESS){
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed"); throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.write() failed");
return; return;
} }
if(i2c->writeWordReg(ADS1X15_REG_POINTER_HITHRESH, 0xF07F) != mraa::SUCCESS){ if(i2c->writeWordReg(ADS1X15_REG_POINTER_HITHRESH, 0xF07F) != mraa::SUCCESS){
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed"); throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.write() failed");
return; return;
} }
break; break;
@ -171,7 +171,7 @@ ADS1X15::updateConfigRegister(uint16_t update, bool read){
//Mask out read bit if we are just updating the configuration. //Mask out read bit if we are just updating the configuration.
if(!read) temp = update & 0x7FFF; if(!read) temp = update & 0x7FFF;
if(i2c->writeWordReg(ADS1X15_REG_POINTER_CONFIG, swapWord(temp)) != mraa::SUCCESS){ if(i2c->writeWordReg(ADS1X15_REG_POINTER_CONFIG, swapWord(temp)) != mraa::SUCCESS){
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed"); throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.write() failed");
return; return;
} }
//If we update the configuration re-set the in memory copy. //If we update the configuration re-set the in memory copy.