mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
lsm9ds0: 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:
parent
9e20268bb8
commit
36237ae596
@ -89,7 +89,8 @@ bool LSM9DS0::init()
|
|||||||
// power up
|
// power up
|
||||||
if (!setGyroscopePowerDown(false))
|
if (!setGyroscopePowerDown(false))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to wake up gyro" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to wake up gyro");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,21 +98,24 @@ bool LSM9DS0::init()
|
|||||||
if (!setGyroscopeEnableAxes(CTRL_REG1_G_YEN |CTRL_REG1_G_XEN |
|
if (!setGyroscopeEnableAxes(CTRL_REG1_G_YEN |CTRL_REG1_G_XEN |
|
||||||
CTRL_REG1_G_ZEN))
|
CTRL_REG1_G_ZEN))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to enable gyro axes" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to enable gyro axes");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set gyro ODR
|
// set gyro ODR
|
||||||
if (!setGyroscopeODR(G_ODR_95_25))
|
if (!setGyroscopeODR(G_ODR_95_25))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to set gyro ODR" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to set gyro ODR");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set gyro scale
|
// set gyro scale
|
||||||
if (!setGyroscopeScale(G_FS_245))
|
if (!setGyroscopeScale(G_FS_245))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to set gyro scale" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to set gyro scale");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +124,8 @@ bool LSM9DS0::init()
|
|||||||
// power up and set ODR
|
// power up and set ODR
|
||||||
if (!setAccelerometerODR(XM_AODR_100))
|
if (!setAccelerometerODR(XM_AODR_100))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to set accel ODR" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to set accel ODR");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,14 +133,16 @@ bool LSM9DS0::init()
|
|||||||
if (!setAccelerometerEnableAxes(CTRL_REG1_XM_AXEN |CTRL_REG1_XM_AYEN |
|
if (!setAccelerometerEnableAxes(CTRL_REG1_XM_AXEN |CTRL_REG1_XM_AYEN |
|
||||||
CTRL_REG1_XM_AZEN))
|
CTRL_REG1_XM_AZEN))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to enable accel axes" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to enable accel axes");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set scaling rate
|
// set scaling rate
|
||||||
if (!setAccelerometerScale(XM_AFS_2))
|
if (!setAccelerometerScale(XM_AFS_2))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to set accel scale" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to set accel scale");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +151,8 @@ bool LSM9DS0::init()
|
|||||||
// enable the temperature sensor
|
// enable the temperature sensor
|
||||||
if (!enableTemperatureSensor(true))
|
if (!enableTemperatureSensor(true))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to enable temp sensor" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to enable temp sensor");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,35 +161,40 @@ bool LSM9DS0::init()
|
|||||||
// set mode (this also powers it up if not XM_MD_POWERDOWN)
|
// set mode (this also powers it up if not XM_MD_POWERDOWN)
|
||||||
if (!setMagnetometerMode(XM_MD_CONTINUOUS))
|
if (!setMagnetometerMode(XM_MD_CONTINUOUS))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to set mag scale" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to set mag scale");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// turn LPM off
|
// turn LPM off
|
||||||
if (!setMagnetometerLPM(false))
|
if (!setMagnetometerLPM(false))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to disable mag LPM" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to disable mag LPM");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set resolution
|
// set resolution
|
||||||
if (!setMagnetometerResolution(XM_RES_LOW))
|
if (!setMagnetometerResolution(XM_RES_LOW))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to set mag res" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to set mag res");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set ODR
|
// set ODR
|
||||||
if (!setMagnetometerODR(XM_ODR_12_5))
|
if (!setMagnetometerODR(XM_ODR_12_5))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to set mag ODR" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to set mag ODR");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set scale
|
// set scale
|
||||||
if (!setMagnetometerScale(XM_MFS_2))
|
if (!setMagnetometerScale(XM_MFS_2))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": Unable to set mag scale" << endl;
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Unable to set mag scale");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +293,8 @@ uint8_t LSM9DS0::readReg(DEVICE_T dev, uint8_t reg)
|
|||||||
case DEV_GYRO: device = &m_i2cG; break;
|
case DEV_GYRO: device = &m_i2cG; break;
|
||||||
case DEV_XM: device = &m_i2cXM; break;
|
case DEV_XM: device = &m_i2cXM; break;
|
||||||
default:
|
default:
|
||||||
cerr << __FUNCTION__ << ": Internal error, invalid device" << endl;
|
throw std::logic_error(string(__FUNCTION__) +
|
||||||
|
": Internal error, invalid device specified");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,7 +310,8 @@ void LSM9DS0::readRegs(DEVICE_T dev, uint8_t reg, uint8_t *buffer, int len)
|
|||||||
case DEV_GYRO: device = &m_i2cG; break;
|
case DEV_GYRO: device = &m_i2cG; break;
|
||||||
case DEV_XM: device = &m_i2cXM; break;
|
case DEV_XM: device = &m_i2cXM; break;
|
||||||
default:
|
default:
|
||||||
cerr << __FUNCTION__ << ": Internal error, invalid device" << endl;
|
throw std::logic_error(string(__FUNCTION__) +
|
||||||
|
": Internal error, invalid device specified");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,15 +329,16 @@ bool LSM9DS0::writeReg(DEVICE_T dev, uint8_t reg, uint8_t val)
|
|||||||
case DEV_GYRO: device = &m_i2cG; break;
|
case DEV_GYRO: device = &m_i2cG; break;
|
||||||
case DEV_XM: device = &m_i2cXM; break;
|
case DEV_XM: device = &m_i2cXM; break;
|
||||||
default:
|
default:
|
||||||
cerr << __FUNCTION__ << ": Internal error, invalid device" << endl;
|
throw std::logic_error(string(__FUNCTION__) +
|
||||||
|
": Internal error, invalid device specified");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mraa::Result rv;
|
mraa::Result rv;
|
||||||
if ((rv = device->writeReg(reg, val)) != mraa::SUCCESS)
|
if ((rv = device->writeReg(reg, val)) != mraa::SUCCESS)
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << ": failed:" << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
printError(rv);
|
": I2c.writeReg() failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +415,8 @@ bool LSM9DS0::setGyroscopeScale(G_FS_T scale)
|
|||||||
|
|
||||||
default: // should never occur, but...
|
default: // should never occur, but...
|
||||||
m_gyroScale = 0.0; // set a safe, though incorrect value
|
m_gyroScale = 0.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,7 +489,8 @@ bool LSM9DS0::setAccelerometerScale(XM_AFS_T scale)
|
|||||||
|
|
||||||
default: // should never occur, but...
|
default: // should never occur, but...
|
||||||
m_accelScale = 0.0; // set a safe, though incorrect value
|
m_accelScale = 0.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,7 +577,8 @@ bool LSM9DS0::setMagnetometerScale(XM_MFS_T scale)
|
|||||||
|
|
||||||
default: // should never occur, but...
|
default: // should never occur, but...
|
||||||
m_magScale = 0.0; // set a safe, though incorrect value
|
m_magScale = 0.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user