From 60a3f6cd7efacb25693d98e34298c3905b822d32 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 11 Sep 2015 10:38:23 -0600 Subject: [PATCH] pulsesensor: throw exception(s) on fatal errors Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/pulsensor/pulsensor.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pulsensor/pulsensor.cxx b/src/pulsensor/pulsensor.cxx index 798a6eb9..e8634885 100644 --- a/src/pulsensor/pulsensor.cxx +++ b/src/pulsensor/pulsensor.cxx @@ -22,6 +22,8 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include +#include #include #include #include "pulsensor.h" @@ -29,7 +31,12 @@ void init_pulsensor (pulsensor_context * ctx, callback_handler handler) { ctx->callback = handler; - ctx->pin_ctx = mraa_aio_init(0); + if ( !(ctx->pin_ctx = mraa_aio_init(0)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } ctx->sample_counter = 0; ctx->last_beat_time = 0;