mirror of
https://github.com/eclipse/upm.git
synced 2025-03-28 03:10:06 +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;
|
using namespace upm;
|
||||||
|
|
||||||
Gas::Gas(int gasPin) {
|
Gas::Gas(int gasPin) : m_aio(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() {
|
Gas::~Gas() {
|
||||||
// close analog input
|
|
||||||
mraa_result_t error;
|
|
||||||
error = mraa_aio_close(m_gasCtx);
|
|
||||||
if (error != MRAA_SUCCESS) {
|
|
||||||
mraa_result_print(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -64,7 +54,7 @@ Gas::getSampledWindow (unsigned int freqMS, int numberOfSamples,
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (sampleIdx < numberOfSamples) {
|
while (sampleIdx < numberOfSamples) {
|
||||||
buffer[sampleIdx++] = mraa_aio_read (m_gasCtx);
|
buffer[sampleIdx++] = getSample();
|
||||||
usleep(freqMS * 1000);
|
usleep(freqMS * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +86,7 @@ Gas::getSampledData (thresholdContext* ctx) {
|
|||||||
|
|
||||||
int
|
int
|
||||||
Gas::getSample () {
|
Gas::getSample () {
|
||||||
return mraa_aio_read (m_gasCtx);
|
return m_aio.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -24,8 +24,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mraa/gpio.h>
|
#include <mraa/aio.hpp>
|
||||||
#include <mraa/aio.h>
|
|
||||||
|
|
||||||
struct thresholdContext {
|
struct thresholdContext {
|
||||||
long averageReading;
|
long averageReading;
|
||||||
@ -99,7 +98,7 @@ class Gas {
|
|||||||
virtual void printGraph (thresholdContext* ctx, uint8_t resolution);
|
virtual void printGraph (thresholdContext* ctx, uint8_t resolution);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mraa_aio_context m_gasCtx;
|
mraa::Aio m_aio;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user