From 3585761ecf772ee77d7a339ccb0c834c85a02a35 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 11 Sep 2015 12:05:54 -0600 Subject: [PATCH] stepmotor: throw exception(s) on fatal errors Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/stepmotor/stepmotor.cxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/stepmotor/stepmotor.cxx b/src/stepmotor/stepmotor.cxx index b3f918d7..7e146ae0 100644 --- a/src/stepmotor/stepmotor.cxx +++ b/src/stepmotor/stepmotor.cxx @@ -23,6 +23,8 @@ */ #include +#include +#include #include #include @@ -40,6 +42,20 @@ StepMotor::StepMotor (int dirPin, int stePin) m_stePin = stePin; m_dirPin = dirPin; + m_pwmStepContext = mraa_pwm_init (m_stePin); + if (m_pwmStepContext == NULL) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_pwm_init() failed, invalid pin?"); + + return; + } + m_dirPinCtx = mraa_gpio_init (m_dirPin); + if (m_dirPinCtx == NULL) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init() failed, invalid pin?"); + + return; + } error = m_dirPinCtx.dir (mraa::DIR_OUT); if (error != mraa::SUCCESS) { mraa::printError (error);