Added iGas interface

Signed-off-by: Serban Waltter <serban.waltter@rinftech.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Serban Waltter
2018-10-08 16:43:42 +03:00
committed by Mihai Tudor Panu
parent f28a6d2561
commit e4f106a0c7
33 changed files with 267 additions and 21 deletions

View File

@ -2,4 +2,5 @@ set (libname "mg811")
set (libdescription "CO2 Sensor")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
set (module_iface iGas.hpp)
upm_module_init(mraa)

View File

@ -88,6 +88,20 @@ float MG811::ppm()
(m_reactionValue / (log400-log1000))+log400);
}
float MG811::getConcentration()
{
static const float log400 = log10f(400);
static const float log1000 = log10f(1000);
float val = volts();
if ((val / dcGain) >= m_zeroPointValue)
return 0.0;
else
return powf(10.0, ((val/dcGain)-m_zeroPointValue) /
(m_reactionValue / (log400-log1000))+log400);
}
bool MG811::thresholdReached()
{
return (m_gpio.read() ? true : false);

View File

@ -28,6 +28,8 @@
#include <mraa/aio.hpp>
#include <mraa/gpio.hpp>
#include <interfaces/iGas.hpp>
namespace upm {
/**
* @brief MG811 CO2 Sensor
@ -68,7 +70,7 @@ namespace upm {
* @snippet mg811.cxx Interesting
*/
class MG811 {
class MG811: virtual public iGas {
public:
/**
@ -83,7 +85,7 @@ namespace upm {
/**
* MG811 destructor
*/
~MG811();
virtual ~MG811();
/**
* Return a cumputed reference voltage to be used in calibration.
@ -118,6 +120,7 @@ namespace upm {
* @return The computed CO2 concentration in ppm
*/
float ppm();
float getConcentration();
/**
* Read the digital pin and return true if the set threshold has