mpu9150: throw exception(s) on fatal errors

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson 2015-09-10 16:20:13 -06:00 committed by Mihai Tudor Panu
parent a24f8209bc
commit 5cc8c90251

View File

@ -53,8 +53,8 @@ MPU60X0::MPU60X0(int bus, uint8_t address) :
mraa::Result rv; mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS) if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{ {
cerr << __FUNCTION__ << ": Could not initialize i2c address. " << endl; throw std::runtime_error(std::string(__FUNCTION__) +
printError(rv); ": I2c.address() failed");
return; return;
} }
} }
@ -69,7 +69,8 @@ bool MPU60X0::init()
// first, take the device out of sleep mode // first, take the device out of sleep mode
if (!setSleep(false)) if (!setSleep(false))
{ {
cerr << __FUNCTION__ << ": Unable to wake up device" << endl; throw std::runtime_error(std::string(__FUNCTION__) +
": Unable to wake up device");
return false; return false;
} }
@ -77,7 +78,8 @@ bool MPU60X0::init()
// internal clock for stability // internal clock for stability
if (!setClockSource(PLL_XG)) if (!setClockSource(PLL_XG))
{ {
cerr << __FUNCTION__ << ": Unable to set clock source" << endl; throw std::runtime_error(std::string(__FUNCTION__) +
": Unable to set clock source");
return false; return false;
} }
@ -149,8 +151,13 @@ bool MPU60X0::writeReg(uint8_t reg, uint8_t val)
mraa::Result rv; mraa::Result rv;
if ((rv = m_i2c.writeReg(reg, val)) != mraa::SUCCESS) if ((rv = m_i2c.writeReg(reg, val)) != mraa::SUCCESS)
{ {
<<<<<<< HEAD
cerr << __FUNCTION__ << ": failed:" << endl; cerr << __FUNCTION__ << ": failed:" << endl;
printError(rv); printError(rv);
=======
throw std::runtime_error(std::string(__FUNCTION__) +
": I2c.writeReg() failed");
>>>>>>> 9378f17... mpu9150: throw exception(s) on fatal errors
return false; return false;
} }
@ -215,7 +222,8 @@ bool MPU60X0::setGyroscopeScale(FS_SEL_T scale)
default: // should never occur, but... default: // should never occur, but...
m_gyroScale = 1.0; // set a safe, though incorrect value m_gyroScale = 1.0; // set a safe, though incorrect value
cerr << __FUNCTION__ << ": internal error, unsupported scale" << endl; throw std::logic_error(string(__FUNCTION__) +
": internal error, unsupported scale");
break; break;
} }
@ -257,7 +265,8 @@ bool MPU60X0::setAccelerometerScale(AFS_SEL_T scale)
default: // should never occur, but... default: // should never occur, but...
m_accelScale = 1.0; // set a safe, though incorrect value m_accelScale = 1.0; // set a safe, though incorrect value
cerr << __FUNCTION__ << ": internal error, unsupported scale" << endl; throw std::logic_error(string(__FUNCTION__) +
": internal error, unsupported scale");
break; break;
} }