mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
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:
parent
cd30c7d71f
commit
3d702a6e64
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user