From 3d702a6e6478928ec12923145d9bb220da4d24e5 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Mon, 14 Sep 2015 13:11:42 -0600 Subject: [PATCH] gas: switch to mraa c++ Aio API Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/gas/gas.cxx | 16 +++------------- src/gas/gas.h | 5 ++--- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/gas/gas.cxx b/src/gas/gas.cxx index c6b5144c..a43b82c3 100644 --- a/src/gas/gas.cxx +++ b/src/gas/gas.cxx @@ -32,20 +32,10 @@ using namespace upm; -Gas::Gas(int gasPin) { - // initialise analog gas input - if (!(m_gasCtx = mraa_aio_init(gasPin))) - throw std::invalid_argument(std::string(__FUNCTION__) + - ": mraa_aio_init() failed, invalid pin?"); +Gas::Gas(int gasPin) : m_aio(gasPin) { } Gas::~Gas() { - // close analog input - mraa_result_t error; - error = mraa_aio_close(m_gasCtx); - if (error != MRAA_SUCCESS) { - mraa_result_print(error); - } } int @@ -64,7 +54,7 @@ Gas::getSampledWindow (unsigned int freqMS, int numberOfSamples, } while (sampleIdx < numberOfSamples) { - buffer[sampleIdx++] = mraa_aio_read (m_gasCtx); + buffer[sampleIdx++] = getSample(); usleep(freqMS * 1000); } @@ -96,7 +86,7 @@ Gas::getSampledData (thresholdContext* ctx) { int Gas::getSample () { - return mraa_aio_read (m_gasCtx); + return m_aio.read(); } void diff --git a/src/gas/gas.h b/src/gas/gas.h index 50e21679..19bd7812 100644 --- a/src/gas/gas.h +++ b/src/gas/gas.h @@ -24,8 +24,7 @@ #pragma once #include -#include -#include +#include struct thresholdContext { long averageReading; @@ -99,7 +98,7 @@ class Gas { virtual void printGraph (thresholdContext* ctx, uint8_t resolution); protected: - mraa_aio_context m_gasCtx; + mraa::Aio m_aio; }; }