From d0d89b579ddb2cae8627ea5969c5b4eb87d29e8d Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Thu, 10 Sep 2015 14:07:57 -0600 Subject: [PATCH] max31855: throw exception(s) on fatal errors Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/max31855/max31855.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/max31855/max31855.cxx b/src/max31855/max31855.cxx index 072b6653..3037aaf3 100644 --- a/src/max31855/max31855.cxx +++ b/src/max31855/max31855.cxx @@ -23,6 +23,8 @@ */ #include +#include +#include #include #include #include @@ -36,7 +38,12 @@ using namespace upm; MAX31855::MAX31855(int bus, int cs) { // initialise chip select as a normal gpio - m_gpio = mraa_gpio_init(cs); + if ( !(m_gpio = mraa_gpio_init(cs)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(cs) failed, invalid pin?"); + return; + } mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT); // initialise the spi bus with a 2Mhz clock