mirror of
https://github.com/eclipse/upm.git
synced 2025-06-09 23:00:23 +03:00
ak8975: 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
5cc8c90251
commit
9c4a4d0ff0
@ -25,6 +25,7 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "ak8975.h"
|
||||
|
||||
@ -43,8 +44,8 @@ AK8975::AK8975(int bus, uint8_t address):
|
||||
mraa::Result rv;
|
||||
if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": Could not initialize i2c address. " << endl;
|
||||
printError(rv);
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": I2c.address() failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -62,13 +63,15 @@ bool AK8975::init()
|
||||
|
||||
if (!setMode(CNTL_PWRDWN))
|
||||
{
|
||||
cerr << __FUNCTION__ << ": Unable to set PWRDWN mode" << endl;
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": Unable to set PWRDWN mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!setMode(CNTL_FUSE_ACCESS))
|
||||
{
|
||||
cerr << __FUNCTION__ << ": Unable to set FUSE mode" << endl;
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": Unable to set FUSE mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -80,7 +83,8 @@ bool AK8975::init()
|
||||
// now, place back in power down mode
|
||||
if (!setMode(CNTL_PWRDWN))
|
||||
{
|
||||
cerr << __FUNCTION__ << ": Unable to reset PWRDWN mode" << endl;
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": Unable to set reset PWRDWN mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -92,8 +96,8 @@ bool AK8975::setMode(CNTL_MODES_T mode)
|
||||
mraa::Result rv;
|
||||
if ((rv = m_i2c.writeReg(REG_CNTL, mode)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": failed:" << endl;
|
||||
printError(rv);
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": I2c.writeReg() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -128,8 +132,8 @@ bool AK8975::waitforDeviceReady()
|
||||
retries++;
|
||||
}
|
||||
|
||||
cerr << __FUNCTION__ << ": timeout waiting for device to become ready"
|
||||
<< endl;
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": timeout waiting for device to become ready");
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -145,7 +149,8 @@ bool AK8975::update(bool selfTest)
|
||||
// First set measurement mode (take a measurement)
|
||||
if (!setMode(CNTL_MEASURE))
|
||||
{
|
||||
cerr << __FUNCTION__ << ": Unable to set MEASURE mode" << endl;
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": Unable to set MEASURE mode");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -176,22 +181,24 @@ bool AK8975::selfTest()
|
||||
// set power down first
|
||||
if (!setMode(CNTL_PWRDWN))
|
||||
{
|
||||
cerr << __FUNCTION__ << ": Unable to set PWRDWN mode" << endl;
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": Unable to set PWRDWN mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
// enable self test bit
|
||||
if ((rv = m_i2c.writeReg(REG_ASTC, ASTC_SELF)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": failed to enable self test:" << endl;
|
||||
printError(rv);
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": failed to enable self test");
|
||||
return false;
|
||||
}
|
||||
|
||||
// now set self test mode
|
||||
if (!setMode(CNTL_SELFTEST))
|
||||
{
|
||||
cerr << __FUNCTION__ << ": Unable to set SELFTEST mode" << endl;
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": Unable to set SELFTEST mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -203,8 +210,8 @@ bool AK8975::selfTest()
|
||||
reg &= ~ASTC_SELF;
|
||||
if ((rv = m_i2c.writeReg(REG_ASTC, reg)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": failed to disable self test:" << endl;
|
||||
printError(rv);
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": failed to disable self test");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user