gas: switch to mraa c++ Aio API

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-14 13:11:42 -06:00 committed by Mihai Tudor Panu
parent cd30c7d71f
commit 3d702a6e64
2 changed files with 5 additions and 16 deletions

View File

@ -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

View File

@ -24,8 +24,7 @@
#pragma once
#include <string>
#include <mraa/gpio.h>
#include <mraa/aio.h>
#include <mraa/aio.hpp>
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;
};
}