mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
mlx90614: remove custom exception and use standard ones
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
fcca8ada45
commit
8dac9f7356
@ -25,29 +25,28 @@
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "mlx90614.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
struct MLX90614Exception : public std::exception {
|
||||
std::string message;
|
||||
MLX90614Exception (std::string msg) : message (msg) { }
|
||||
~MLX90614Exception () throw () { }
|
||||
const char* what() const throw () { return message.c_str(); }
|
||||
};
|
||||
|
||||
MLX90614::MLX90614 (int bus, int devAddr) {
|
||||
m_name = "MLX90614";
|
||||
|
||||
m_i2cAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2Ctx = mraa_i2c_init(m_bus);
|
||||
if (!(m_i2Ctx = mraa_i2c_init(m_bus)))
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_init() failed");
|
||||
}
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
throw MLX90614Exception ("Couldn't initilize I2C.");
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_i2c_address() failed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,10 +83,6 @@ uint16_t
|
||||
MLX90614::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
|
||||
int readByte = 0;
|
||||
|
||||
if (m_i2Ctx == NULL) {
|
||||
throw MLX90614Exception ("Couldn't find initilized I2C.");
|
||||
}
|
||||
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
mraa_i2c_write_byte(m_i2Ctx, reg);
|
||||
|
||||
@ -99,10 +94,6 @@ mraa_result_t
|
||||
MLX90614::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
if (m_i2Ctx == NULL) {
|
||||
throw MLX90614Exception ("Couldn't find initilized I2C.");
|
||||
}
|
||||
|
||||
error = mraa_i2c_address (m_i2Ctx, m_i2cAddr);
|
||||
error = mraa_i2c_write (m_i2Ctx, buffer, len);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user