From fcca8ada4587c7cbda26a857b05555aedf716521 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 7 Aug 2015 16:36:40 -0600 Subject: [PATCH] maxds3231m: remove custom exception and use standard ones Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/maxds3231m/maxds3231m.cxx | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/maxds3231m/maxds3231m.cxx b/src/maxds3231m/maxds3231m.cxx index 40af866f..9ebeed25 100644 --- a/src/maxds3231m/maxds3231m.cxx +++ b/src/maxds3231m/maxds3231m.cxx @@ -25,29 +25,28 @@ #include #include #include +#include #include "maxds3231m.h" using namespace upm; -struct DS3231Exception : public std::exception { - std::string message; - DS3231Exception (std::string msg) : message (msg) { } - ~DS3231Exception () throw () { } - const char* what() const throw () { return message.c_str(); } -}; - MAXDS3231M::MAXDS3231M (int bus, int devAddr) { m_name = "MAXDS3231M"; 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 DS3231Exception ("Couldn't initilize I2C."); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_i2c_address() failed"); } } @@ -109,10 +108,6 @@ uint16_t MAXDS3231M::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) { int readByte = 0; - if (m_i2Ctx == NULL) { - throw DS3231Exception ("Couldn't find initilized I2C."); - } - mraa_i2c_address(m_i2Ctx, m_i2cAddr); mraa_i2c_write_byte(m_i2Ctx, reg); @@ -125,10 +120,6 @@ mraa_result_t MAXDS3231M::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) { mraa_result_t error = MRAA_SUCCESS; - if (m_i2Ctx == NULL) { - throw DS3231Exception ("Couldn't find initilized I2C."); - } - error = mraa_i2c_address (m_i2Ctx, m_i2cAddr); error = mraa_i2c_write (m_i2Ctx, buffer, len);