2014-08-26 19:33:39 +00:00
|
|
|
/*
|
|
|
|
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
|
|
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <mraa/gpio.h>
|
|
|
|
|
#include <mraa/aio.h>
|
|
|
|
|
|
|
|
|
|
struct thresholdContext {
|
|
|
|
|
long averageReading;
|
|
|
|
|
long runningAverage;
|
|
|
|
|
int averagedOver;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace upm {
|
|
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* @brief Gas Sensor library
|
2014-11-25 11:59:39 -08:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* Library for air quality and gas detecting sensors. Base class Gas provides buffered
|
|
|
|
|
* sampling, threshold checking, basic printing function, and standard read function.
|
2014-11-25 11:59:39 -08:00
|
|
|
*
|
2014-09-22 16:37:36 +01:00
|
|
|
* @defgroup gas libupm-gas
|
2015-06-24 13:39:09 -07:00
|
|
|
* @ingroup seeed analog gaseous eak hak
|
2014-08-26 19:33:39 +00:00
|
|
|
*/
|
|
|
|
|
class Gas {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2014-11-25 11:59:39 -08:00
|
|
|
* Instantiates a Gas object
|
2014-08-26 19:33:39 +00:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @param gasPin Pin where gas is connected
|
2014-08-26 19:33:39 +00:00
|
|
|
*/
|
|
|
|
|
Gas(int gasPin);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gas object destructor
|
|
|
|
|
*/
|
|
|
|
|
~Gas();
|
|
|
|
|
|
|
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* Gets samples from the gas sensor according to the provided window and
|
2014-08-26 19:33:39 +00:00
|
|
|
* number of samples
|
|
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @param freqMS Time between each sample (in milliseconds)
|
|
|
|
|
* @param numberOfSamples Number of sample to sample for this window
|
|
|
|
|
* @param buffer Buffer with sampled data
|
2014-08-26 19:33:39 +00:00
|
|
|
*/
|
2015-09-07 19:00:30 +03:00
|
|
|
virtual int getSampledWindow (unsigned int freqMS, int numberOfSamples, uint16_t * buffer);
|
2014-08-26 19:33:39 +00:00
|
|
|
|
|
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* Given the sampled buffer, this method returns TRUE/FALSE if the threshold
|
|
|
|
|
* is reached
|
2014-08-26 19:33:39 +00:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @param ctx Threshold context
|
|
|
|
|
* @param threshold Sample threshold
|
|
|
|
|
* @param buffer Buffer with samples
|
|
|
|
|
* @param len Buffer length
|
2014-08-26 19:33:39 +00:00
|
|
|
*/
|
2015-09-07 19:00:30 +03:00
|
|
|
virtual int findThreshold (thresholdContext* ctx, unsigned int threshold, uint16_t * buffer, int len);
|
2014-08-26 19:33:39 +00:00
|
|
|
|
|
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* Returns average data for the sampled window
|
2014-08-26 19:33:39 +00:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @param ctx Threshold context
|
2014-08-26 19:33:39 +00:00
|
|
|
*/
|
|
|
|
|
virtual int getSampledData (thresholdContext* ctx);
|
|
|
|
|
|
|
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* Returns one sample from the sensor
|
2014-08-26 19:33:39 +00:00
|
|
|
*/
|
2014-11-04 19:13:21 +00:00
|
|
|
virtual int getSample ();
|
2014-08-26 19:33:39 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* Prints a running average of the threshold context
|
2014-08-26 19:33:39 +00:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @param ctx Threshold context
|
2014-08-26 19:33:39 +00:00
|
|
|
*/
|
|
|
|
|
virtual void printGraph (thresholdContext* ctx, uint8_t resolution);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
mraa_aio_context m_gasCtx;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|