From 8dac9f735687471b163dd58611213135ef96b576 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 7 Aug 2015 16:37:07 -0600 Subject: [PATCH] mlx90614: remove custom exception and use standard ones Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/mlx90614/mlx90614.cxx | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/mlx90614/mlx90614.cxx b/src/mlx90614/mlx90614.cxx index ad3e6454..7da71be8 100644 --- a/src/mlx90614/mlx90614.cxx +++ b/src/mlx90614/mlx90614.cxx @@ -25,29 +25,28 @@ #include #include #include +#include #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);