mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
mma7660: 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
4f5b4d5886
commit
427dd6e851
@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "mma7660.h"
|
||||
@ -39,7 +40,8 @@ MMA7660::MMA7660(int bus, uint8_t address)
|
||||
// setup our i2c link
|
||||
if ( !(m_i2c = mraa_i2c_init(bus)) )
|
||||
{
|
||||
cerr << "MMA7660: mraa_i2c_init() failed." << endl;
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_init() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -47,8 +49,8 @@ MMA7660::MMA7660(int bus, uint8_t address)
|
||||
|
||||
if ( (rv = mraa_i2c_address(m_i2c, m_addr)) != MRAA_SUCCESS)
|
||||
{
|
||||
cerr << "MMA7660: Could not initialize i2c bus. " << endl;
|
||||
mraa_result_print(rv);
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_address() failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -128,7 +130,8 @@ int MMA7660::getVerifiedAxis(MMA7660_REG_T axis)
|
||||
|
||||
if (axis > 2)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": axis must be 0, 1, or 2." << endl;
|
||||
throw std::out_of_range(std::string(__FUNCTION__) +
|
||||
": axis must be 0, 1, or 2.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -161,7 +164,6 @@ uint8_t MMA7660::getVerifiedTilt()
|
||||
// check alert bit
|
||||
} while (val & 0x40);
|
||||
|
||||
// shift the sign bit over, and compensate
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -218,7 +220,8 @@ void MMA7660::installISR(int pin, void (*isr)(void *), void *arg)
|
||||
|
||||
if ( !(m_gpio = mraa_gpio_init(pin)) )
|
||||
{
|
||||
cerr << __FUNCTION__ << ": mraa_gpio_init() failed" << endl;
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_gpio_init() failed, invalid pin?");
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user