From ab20e34c596a1dfe72c8ba7c0ac1f0d958a096d4 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Thu, 10 Sep 2015 14:11:06 -0600 Subject: [PATCH] max44000: throw exception(s) on fatal errors Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/max44000/max44000.cxx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/max44000/max44000.cxx b/src/max44000/max44000.cxx index 86365e2c..13eb43a9 100644 --- a/src/max44000/max44000.cxx +++ b/src/max44000/max44000.cxx @@ -23,6 +23,8 @@ */ #include +#include +#include #include #include @@ -36,9 +38,17 @@ MAX44000::MAX44000 (int bus, int devAddr) : m_i2cMaxControlCtx(bus) { m_maxControlAddr = devAddr; m_bus = bus; + if ( !(m_i2cMaxControlCtx = mraa_i2c_init(m_bus)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_i2c_init() failed"); + return; + } + mraa::Result ret = m_i2cMaxControlCtx.address(m_maxControlAddr); if (ret != mraa::SUCCESS) { - fprintf(stderr, "Messed up i2c bus\n"); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_i2c_address() failed"); } // i2cWriteReg (MCR, 0x2C);