mq303a: throw exception(s) on fatal errors

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson 2015-09-08 17:02:10 -06:00 committed by Mihai Tudor Panu
parent b00e81dfce
commit 7866e54e8d

View File

@ -23,6 +23,8 @@
*/
#include <iostream>
#include <string>
#include <stdexcept>
#include "mq303a.h"
@ -30,9 +32,19 @@ using namespace upm;
MQ303A::MQ303A(int pin, int heaterPin)
{
m_aio = mraa_aio_init(pin);
if ( !(m_aio = mraa_aio_init(pin)) )
{
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_gpio = mraa_gpio_init(heaterPin);
if ( !(m_gpio = mraa_gpio_init(heaterPin)) )
{
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
return;
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
}