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 "cwlsxxa")
set (libdescription "Veris CWLSXXA CO2/Temperature/Humidity Transmitter")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
set (module_iface iGas.hpp iHumidity.hpp iTemperature.hpp)
upm_module_init(mraa)

View File

@ -160,8 +160,15 @@ float CWLSXXA::getTemperature(bool fahrenheit)
return m_temperature;
}
float CWLSXXA::getTemperature()
{
update();
return m_temperature;
}
float CWLSXXA::getHumidity()
{
update();
return m_humidity;
}
@ -170,6 +177,12 @@ float CWLSXXA::getCO2()
return m_co2;
}
float CWLSXXA::getConcentration()
{
update();
return m_co2;
}
int CWLSXXA::average(mraa::Aio *aio, int samples)
{
if (samples <= 0)

View File

@ -26,6 +26,10 @@
#include <string>
#include <iostream>
#include <interfaces/iGas.hpp>
#include <interfaces/iHumidity.hpp>
#include <interfaces/iTemperature.hpp>
#include <mraa/aio.hpp>
// Unlikey to be changable without external circuitry (voltage divider)
@ -85,7 +89,7 @@ namespace upm {
* @snippet cwlsxxa.cxx Interesting
*/
class CWLSXXA {
class CWLSXXA: virtual public iGas, virtual public iHumidity, virtual public iTemperature {
public:
/**
@ -134,7 +138,8 @@ namespace upm {
* The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit
*/
float getTemperature(bool fahrenheit=false);
float getTemperature(bool fahrenheit);
float getTemperature();
/**
* Get the current relative humidity. update() must have been called
@ -154,6 +159,14 @@ namespace upm {
*/
float getCO2();
/**
* Get the current CO2 concentration in Parts Per Million (PPM).
* update() must have been called prior to calling this method.
*
* @return The last CO2 reading
*/
float getConcentration();
protected:
// CO2 reporting is always supported

View File

@ -1,7 +1,17 @@
#ifdef SWIGPYTHON
%module (package="upm") cwlsxxa
#endif
%import "interfaces/interfaces.i"
%include "../common_top.i"
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
%typemap(javaimports) SWIGTYPE %{
import upm_interfaces.*;
%}
JAVA_JNI_LOADLIBRARY(javaupm_cwlsxxa)
#endif
/* END Java syntax */

View File

@ -4,5 +4,6 @@ upm_mixed_module_init (NAME gas
C_SRC mqx.c
CPP_HDR gas.hpp mq2.hpp mq3.hpp mq4.hpp mq5.hpp mq6.hpp mq7.hpp mq8.hpp mq9.hpp tp401.hpp
CPP_SRC gas.cxx mq2.cxx mq3.cxx mq4.cxx mq5.cxx mq6.cxx mq7.cxx mq8.cxx mq9.cxx tp401.cxx
IFACE_HDR iGas.hpp
FTI_SRC mqx_fti.c
REQUIRES mraa)

View File

@ -89,6 +89,11 @@ Gas::getSample () {
return m_aio.read();
}
float
Gas::getConcentration() {
return m_aio.read();
}
void
Gas::printGraph (thresholdContext* ctx, uint8_t resolution) {
std::cout << "(" << ctx->runningAverage << ") | ";

View File

@ -25,6 +25,7 @@
#include <string>
#include <mraa/aio.hpp>
#include <interfaces/iGas.hpp>
struct thresholdContext {
long averageReading;
@ -42,7 +43,7 @@ namespace upm {
* @defgroup gas libupm-gas
* @ingroup seeed analog gaseous eak hak
*/
class Gas {
class Gas: virtual public iGas {
public:
/**
* Instantiates a Gas object
@ -89,6 +90,11 @@ class Gas {
*/
virtual int getSample ();
/**
* Returns one sample from the sensor
*/
virtual float getConcentration ();
/**
*
* Prints a running average of the threshold context

View File

@ -1,7 +1,17 @@
#ifdef SWIGPYTHON
%module (package="upm") cwlsxxa
#endif
%import "interfaces/interfaces.i"
%include "../common_top.i"
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
%typemap(javaimports) SWIGTYPE %{
import upm_interfaces.*;
%}
%typemap(jni) (uint16_t *buffer, int len) "jshortArray";
%typemap(jtype) (uint16_t *buffer, int len) "short[]";
%typemap(jstype) (uint16_t *buffer, int len) "short[]";

View File

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

View File

@ -54,3 +54,23 @@ float GroveO2::voltageValue()
sensorVoltage = (sensorVoltage/201.0) * 10000.0;
return sensorVoltage;
}
float GroveO2::getConcentration()
{
float value;
/* Read normalized value */
value = mraa_aio_read_float(m_aio);
if (value < 0.0)
return -1;
/* Convert to %oxygen
Datasheet for grove o2 shows a linear response for the sensor. Assuming
20.5% oxygen @ 25 celsius, with an gain = 1 + 12k/100 = 121, a
dynamic range of 0->25% oxygen, and opamp rails of 0->3.3v (the grove o2
sensor uses a high-accuracy 3.3v regulator),
*/
value *= 25 * 5 / 3.3;
return value;
}

View File

@ -25,6 +25,7 @@
#include <string>
#include <mraa/aio.h>
#include <interfaces/iGas.hpp>
namespace upm {
/**
@ -50,7 +51,7 @@ namespace upm {
* @image html groveo2.jpg
* @snippet groveo2.cxx Interesting
*/
class GroveO2 {
class GroveO2: virtual public iGas {
public:
/**
* Grove O2 Oxygen Gas sensor constructor
@ -69,6 +70,13 @@ namespace upm {
*/
float voltageValue();
/**
* Measures O2 from the sensor
*
* @return Oxygen concentration as PPM
*/
float getConcentration();
private:
mraa_aio_context m_aio;
};

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

View File

@ -2,4 +2,5 @@ set (libname "mhz16")
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

@ -244,8 +244,15 @@ int MHZ16::getGas()
return gas;
}
int MHZ16::getTemperature()
float MHZ16::getConcentration()
{
getData();
return gas;
}
float MHZ16::getTemperature()
{
getData();
return temp;
}

View File

@ -38,6 +38,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <interfaces/iTemperature.hpp>
#include <interfaces/iGas.hpp>
#include <mraa/uart.h>
namespace upm {
@ -67,7 +70,7 @@ namespace upm {
* @image html mhz16.jpg
* @snippet mhz16.cxx Interesting
*/
class MHZ16 {
class MHZ16: virtual public iGas, virtual public iTemperature {
public:
@ -151,13 +154,14 @@ namespace upm {
* @return Gas concentration
*/
int getGas();
float getConcentration();
/**
* Returns the temperature data.
*
* @return Temperature in Celsius
*/
int getTemperature();
float getTemperature();
/**
* Sets the zero point of the sensor

View File

@ -1,7 +1,17 @@
#ifdef SWIGPYTHON
%module (package="upm") cwlsxxa
#endif
%import "interfaces/interfaces.i"
%include "../common_top.i"
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
%typemap(javaimports) SWIGTYPE %{
import upm_interfaces.*;
%}
%include "arrays_java.i";
%include "../java_buffer.i"

View File

@ -2,4 +2,5 @@ set (libname "micsv89")
set (libdescription "Low-power Air Quality Sensor")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
set (module_iface iGas.hpp)
upm_module_init(mraa)

View File

@ -66,6 +66,11 @@ float MICSV89::co2equ() {
return ((rx_buf[0] - 13) * (1600/229) + 400);
}
float MICSV89::getConcentration() {
update();
return ((rx_buf[0] - 13) * (1600/229) + 400);
}
int MICSV89::vocshort() {
return rx_buf[1];
}

View File

@ -27,6 +27,8 @@
#include <iostream>
#include <string>
#include <interfaces/iGas.hpp>
namespace mraa { class I2c;}
namespace upm {
@ -59,7 +61,7 @@ namespace upm {
* @image html micsv89.jpg
* @snippet micsv89.cxx Interesting
*/
class MICSV89 {
class MICSV89: virtual public iGas {
public:
/**
* MICSV89 constructor
@ -87,6 +89,11 @@ namespace upm {
*/
float co2equ();
/**
* Returns the CO2 equivalent value.
*/
float getConcentration();
/**
* Returns VOC Short value.
*/

View File

@ -5,4 +5,5 @@ upm_mixed_module_init (NAME o2
CPP_HDR o2.hpp
CPP_SRC o2.cxx
FTI_SRC o2_fti.c
IFACE_HDR iGas.hpp
REQUIRES mraa)

View File

@ -54,3 +54,22 @@ float O2::voltageValue()
sensorVoltage = (sensorVoltage/201.0) * 10000.0;
return sensorVoltage;
}
float O2::getConcentration()
{
float value;
/* Read normalized value */
value = mraa_aio_read_float(m_aio);
if (value < 0.0)
return -1;
/* Convert to %oxygen
Datasheet for grove o2 shows a linear response for the sensor. Assuming
20.5% oxygen @ 25 celsius, with an gain = 1 + 12k/100 = 121, a
dynamic range of 0->25% oxygen, and opamp rails of 0->3.3v (the grove o2
sensor uses a high-accuracy 3.3v regulator),
*/
value *= 25 * 5 / 3.3;
return value;
}

View File

@ -26,6 +26,8 @@
#include <string>
#include <mraa/aio.h>
#include <interfaces/iGas.hpp>
namespace upm {
/**
* @brief Oxygen Gas Sensor
@ -50,7 +52,7 @@ namespace upm {
* @image html o2.jpg
* @snippet o2.cxx Interesting
*/
class O2 {
class O2: virtual public iGas {
public:
/**
* Grove O2 Oxygen Gas sensor constructor
@ -69,6 +71,13 @@ namespace upm {
*/
float voltageValue();
/**
* Measures O2 from the sensor
*
* @return Oxygen concentration as PPM
*/
float getConcentration();
private:
mraa_aio_context m_aio;
};

View File

@ -2,4 +2,5 @@ set (libname "t6713")
set (libdescription "I2C/UART High Accuracy CO2 Sensor")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
set (module_iface iGas.hpp)
upm_module_init(mraa)

View File

@ -69,6 +69,11 @@ uint16_t T6713::getPpm ()
return(getSensorData(T6713_COMMAND_GET_GAS_PPM));
}
float T6713::getConcentration ()
{
return(getSensorData(T6713_COMMAND_GET_GAS_PPM));
}
uint16_t T6713::getSensorData (MODBUS_COMMANDS cmd)
{
uint16_t data ,readBytes ;

View File

@ -25,6 +25,8 @@
#include "mraa/i2c.hpp"
#include <interfaces/iGas.hpp>
namespace upm {
/**
* @brief Amphenol Telaire 6713 Series CO2 Module
@ -105,7 +107,7 @@ namespace t6713_co2
}FUNCTION_CODES;
}//namespace t6713_co2
class T6713 {
class T6713: virtual public iGas {
public:
/**
* Instantiates a T6713 object
@ -128,6 +130,12 @@ class T6713 {
* Get relative humidity measurement.
*/
uint16_t getPpm ();
/**
* Get relative humidity measurement.
*/
float getConcentration ();
/**
* Get the firmware version
*/

View File

@ -1,3 +1,9 @@
#ifdef SWIGPYTHON
%module (package="upm") cwlsxxa
#endif
%import "interfaces/interfaces.i"
%include "../common_top.i"
/* BEGIN Java syntax ------------------------------------------------------- */
@ -5,6 +11,11 @@
%include "arrays_java.i";
%include "../java_buffer.i"
%typemap(javaimports) SWIGTYPE %{
import upm_interfaces.*;
%}
JAVA_JNI_LOADLIBRARY(javaupm_t6713)
#endif
/* END Java syntax */