From e4f106a0c7d9d9de2bb08e9a485dea3473918efd Mon Sep 17 00:00:00 2001 From: Serban Waltter Date: Mon, 8 Oct 2018 16:43:42 +0300 Subject: [PATCH] Added iGas interface Signed-off-by: Serban Waltter Signed-off-by: Mihai Tudor Panu --- examples/java/CMakeLists.txt | 18 ++++++------ include/interfaces/CMakeLists.txt | 1 + include/interfaces/iGas.hpp | 46 +++++++++++++++++++++++++++++++ include/interfaces/interfaces.cxx | 1 + include/interfaces/interfaces.i | 3 ++ src/cwlsxxa/CMakeLists.txt | 1 + src/cwlsxxa/cwlsxxa.cxx | 13 +++++++++ src/cwlsxxa/cwlsxxa.hpp | 17 ++++++++++-- src/cwlsxxa/cwlsxxa.i | 10 +++++++ src/gas/CMakeLists.txt | 1 + src/gas/gas.cxx | 5 ++++ src/gas/gas.hpp | 8 +++++- src/gas/gas.i | 10 +++++++ src/groveo2/CMakeLists.txt | 1 + src/groveo2/groveo2.cxx | 20 ++++++++++++++ src/groveo2/groveo2.hpp | 10 ++++++- src/mg811/CMakeLists.txt | 1 + src/mg811/mg811.cxx | 14 ++++++++++ src/mg811/mg811.hpp | 7 +++-- src/mhz16/CMakeLists.txt | 1 + src/mhz16/mhz16.cxx | 9 +++++- src/mhz16/mhz16.hpp | 8 ++++-- src/mhz16/mhz16.i | 10 +++++++ src/micsv89/CMakeLists.txt | 1 + src/micsv89/micsv89.cxx | 5 ++++ src/micsv89/micsv89.hpp | 9 +++++- src/o2/CMakeLists.txt | 1 + src/o2/o2.cxx | 19 +++++++++++++ src/o2/o2.hpp | 11 +++++++- src/t6713/CMakeLists.txt | 1 + src/t6713/t6713.cxx | 5 ++++ src/t6713/t6713.hpp | 10 ++++++- src/t6713/t6713.i | 11 ++++++++ 33 files changed, 267 insertions(+), 21 deletions(-) create mode 100644 include/interfaces/iGas.hpp diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index a47c9110..d5ef8260 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -92,7 +92,7 @@ add_example(Button_intr_Example "button;interfaces") add_example(Buzzer_Example buzzer) add_example(CJQ4435_Example cjq4435) add_example(Collision_Example "collision;interfaces") -add_example(CWLSXXA_Example cwlsxxa) +add_example(CWLSXXA_Example "cwlsxxa;interfaces") add_example(DFREC_Example "dfrec;interfaces") add_example(DFRORP_Example "dfrorp;interfaces") add_example(DS1307_Example ds1307) @@ -116,9 +116,9 @@ add_example(GroveLight_Example "grove;interfaces") add_example(GroveLineFinder_Example "grovelinefinder;interfaces") add_example(GroveMD_Example grovemd) add_example(GroveMoisture_Example "grovemoisture;interfaces") -add_example(GroveMQ3_Example gas) -add_example(GroveMQ9_Example gas) -add_example(GroveO2_Example groveo2) +add_example(GroveMQ3_Example "gas;interfaces") +add_example(GroveMQ9_Example "gas;interfaces") +add_example(GroveO2_Example "groveo2;interfaces") add_example(GroveQTouch_Example at42qt1070) add_example(GroveRelay_Example grove) add_example(GroveRotary_Example "grove;interfaces") @@ -169,7 +169,7 @@ add_example(MB704X_Example "mb704x;interfaces") add_example(MCP2515_Example mcp2515) add_example(MCP2515_TXRX_Example mcp2515) add_example(MD_Example md) -add_example(MHZ16_Example mhz16) +add_example(MHZ16_Example "mhz16;interfaces") add_example(Microphone_Example mic) add_example(MMA7361_Example mma7361) add_example(MMA7455_Example "mma7455;interfaces") @@ -178,16 +178,16 @@ add_example(Moisture_Example "moisture;interfaces") add_example(MPL3115A2_Example "mpl3115a2;interfaces") add_example(MPR121_Example mpr121) add_example(MPU9150_Example "mpu9150;interfaces") -add_example(MQ2_Example gas) +add_example(MQ2_Example "gas;interfaces") add_example(MQ303A_Example mq303a) -add_example(MQ5_Example gas) +add_example(MQ5_Example "gas;interfaces") add_example(MS5803_Example "ms5803;interfaces") add_example(NMEAGPS_Example nmea_gps) add_example(NMEAGPS_I2C_Example nmea_gps) add_example(NRF24L01_receiver_Example nrf24l01) add_example(NRF24L01_transmitter_Example nrf24l01) add_example(NUNCHUCK_Example nunchuck) -add_example(O2_Example o2) +add_example(O2_Example "o2;interfaces") add_example(OTP538U_Example "otp538u;interfaces") add_example(P9813_Example p9813) add_example(PPD42NS_Example ppd42ns) @@ -216,7 +216,7 @@ add_example(Temperature_Example "temperature;interfaces") add_example(TEX00_Example "tex00;interfaces") add_example(Th02_Example "th02;interfaces") add_example(TM1637_Example tm1637) -add_example(TP401_Example gas) +add_example(TP401_Example "gas;interfaces") add_example(TSL2561_Example "tsl2561;interfaces") add_example(TTP223_Example "ttp223;interfaces") add_example(ULN200XA_Example uln200xa) diff --git a/include/interfaces/CMakeLists.txt b/include/interfaces/CMakeLists.txt index 9140a353..68ab9f4c 100644 --- a/include/interfaces/CMakeLists.txt +++ b/include/interfaces/CMakeLists.txt @@ -18,6 +18,7 @@ set (module_hpp iClock.hpp iHallEffect.hpp iHeartRate.hpp iHumidity.hpp + iGas.hpp iGyroscope.hpp iLight.hpp iLineFinder.hpp diff --git a/include/interfaces/iGas.hpp b/include/interfaces/iGas.hpp new file mode 100644 index 00000000..2acccce6 --- /dev/null +++ b/include/interfaces/iGas.hpp @@ -0,0 +1,46 @@ +/* + * Author: Serban Waltter + * Copyright (c) 2018 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 + +namespace upm +{ + /** + * @brief Interface for acceleration sensors + */ + class iGas + { + public: + virtual ~iGas() {} + + /** + * Return gas concentration in PPM + * + * @return gas concentration in float + */ + virtual float getConcentration() = 0; + }; +} // upm diff --git a/include/interfaces/interfaces.cxx b/include/interfaces/interfaces.cxx index 53472964..7385fdcd 100644 --- a/include/interfaces/interfaces.cxx +++ b/include/interfaces/interfaces.cxx @@ -8,6 +8,7 @@ #include "iEC.hpp" #include "iElectromagnet.hpp" #include "iEmg.hpp" +#include "iGas.hpp" #include "iGps.hpp" #include "iGyroscope.hpp" #include "iHallEffect.hpp" diff --git a/include/interfaces/interfaces.i b/include/interfaces/interfaces.i index 87ac7123..3180393a 100644 --- a/include/interfaces/interfaces.i +++ b/include/interfaces/interfaces.i @@ -49,6 +49,7 @@ import java.lang.Float; %interface_impl (upm::iEC); %interface_impl (upm::iElectromagnet); %interface_impl (upm::iEmg); + %interface_impl (upm::iGas); %interface_impl (upm::iGps); %interface_impl (upm::iGyroscope); %interface_impl (upm::iHallEffect); @@ -79,6 +80,7 @@ import java.lang.Float; #include "iEC.hpp" #include "iElectromagnet.hpp" #include "iEmg.hpp" + #include "iGas.hpp" #include "iGps.hpp" #include "iGyroscope.hpp" #include "iHallEffect.hpp" @@ -108,6 +110,7 @@ import java.lang.Float; %include "iEC.hpp" %include "iElectromagnet.hpp" %include "iEmg.hpp" +%include "iGas.hpp" %include "iGps.hpp" %include "iGyroscope.hpp" %include "iHallEffect.hpp" diff --git a/src/cwlsxxa/CMakeLists.txt b/src/cwlsxxa/CMakeLists.txt index 9dcfe7f9..18955d47 100644 --- a/src/cwlsxxa/CMakeLists.txt +++ b/src/cwlsxxa/CMakeLists.txt @@ -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) diff --git a/src/cwlsxxa/cwlsxxa.cxx b/src/cwlsxxa/cwlsxxa.cxx index 1369ab8a..52f02bf5 100644 --- a/src/cwlsxxa/cwlsxxa.cxx +++ b/src/cwlsxxa/cwlsxxa.cxx @@ -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) diff --git a/src/cwlsxxa/cwlsxxa.hpp b/src/cwlsxxa/cwlsxxa.hpp index 27419017..03586787 100644 --- a/src/cwlsxxa/cwlsxxa.hpp +++ b/src/cwlsxxa/cwlsxxa.hpp @@ -26,6 +26,10 @@ #include #include +#include +#include +#include + #include // 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 diff --git a/src/cwlsxxa/cwlsxxa.i b/src/cwlsxxa/cwlsxxa.i index f233e3c4..46dbe74f 100644 --- a/src/cwlsxxa/cwlsxxa.i +++ b/src/cwlsxxa/cwlsxxa.i @@ -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 */ diff --git a/src/gas/CMakeLists.txt b/src/gas/CMakeLists.txt index 4f93589a..97991621 100644 --- a/src/gas/CMakeLists.txt +++ b/src/gas/CMakeLists.txt @@ -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) diff --git a/src/gas/gas.cxx b/src/gas/gas.cxx index ac261102..1fdf0023 100644 --- a/src/gas/gas.cxx +++ b/src/gas/gas.cxx @@ -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 << ") | "; diff --git a/src/gas/gas.hpp b/src/gas/gas.hpp index c7edf63f..b452ba85 100644 --- a/src/gas/gas.hpp +++ b/src/gas/gas.hpp @@ -25,6 +25,7 @@ #include #include +#include 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 diff --git a/src/gas/gas.i b/src/gas/gas.i index fb2effef..514981c8 100644 --- a/src/gas/gas.i +++ b/src/gas/gas.i @@ -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[]"; diff --git a/src/groveo2/CMakeLists.txt b/src/groveo2/CMakeLists.txt index c83dd9cb..82309125 100644 --- a/src/groveo2/CMakeLists.txt +++ b/src/groveo2/CMakeLists.txt @@ -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) diff --git a/src/groveo2/groveo2.cxx b/src/groveo2/groveo2.cxx index b982d3ff..3ddfa9f1 100644 --- a/src/groveo2/groveo2.cxx +++ b/src/groveo2/groveo2.cxx @@ -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; +} + diff --git a/src/groveo2/groveo2.hpp b/src/groveo2/groveo2.hpp index 0a3d776a..7f9acee1 100644 --- a/src/groveo2/groveo2.hpp +++ b/src/groveo2/groveo2.hpp @@ -25,6 +25,7 @@ #include #include +#include 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; }; diff --git a/src/mg811/CMakeLists.txt b/src/mg811/CMakeLists.txt index 1709499a..4edfde89 100644 --- a/src/mg811/CMakeLists.txt +++ b/src/mg811/CMakeLists.txt @@ -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) diff --git a/src/mg811/mg811.cxx b/src/mg811/mg811.cxx index 8330f88a..a50d2126 100644 --- a/src/mg811/mg811.cxx +++ b/src/mg811/mg811.cxx @@ -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); diff --git a/src/mg811/mg811.hpp b/src/mg811/mg811.hpp index ae26d446..ccc246ad 100644 --- a/src/mg811/mg811.hpp +++ b/src/mg811/mg811.hpp @@ -28,6 +28,8 @@ #include #include +#include + 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 diff --git a/src/mhz16/CMakeLists.txt b/src/mhz16/CMakeLists.txt index 66373a61..0cdf294d 100644 --- a/src/mhz16/CMakeLists.txt +++ b/src/mhz16/CMakeLists.txt @@ -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) diff --git a/src/mhz16/mhz16.cxx b/src/mhz16/mhz16.cxx index 98096177..80eb5ef8 100644 --- a/src/mhz16/mhz16.cxx +++ b/src/mhz16/mhz16.cxx @@ -244,8 +244,15 @@ int MHZ16::getGas() return gas; } -int MHZ16::getTemperature() +float MHZ16::getConcentration() { + getData(); + return gas; +} + +float MHZ16::getTemperature() +{ + getData(); return temp; } diff --git a/src/mhz16/mhz16.hpp b/src/mhz16/mhz16.hpp index 435195ee..f5bca462 100644 --- a/src/mhz16/mhz16.hpp +++ b/src/mhz16/mhz16.hpp @@ -38,6 +38,9 @@ #include #include +#include +#include + #include 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 diff --git a/src/mhz16/mhz16.i b/src/mhz16/mhz16.i index 4f3dca0a..670cdc89 100644 --- a/src/mhz16/mhz16.i +++ b/src/mhz16/mhz16.i @@ -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" diff --git a/src/micsv89/CMakeLists.txt b/src/micsv89/CMakeLists.txt index 9c9d126e..98b86336 100644 --- a/src/micsv89/CMakeLists.txt +++ b/src/micsv89/CMakeLists.txt @@ -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) diff --git a/src/micsv89/micsv89.cxx b/src/micsv89/micsv89.cxx index 602101a8..20d37a8b 100644 --- a/src/micsv89/micsv89.cxx +++ b/src/micsv89/micsv89.cxx @@ -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]; } diff --git a/src/micsv89/micsv89.hpp b/src/micsv89/micsv89.hpp index ca4d822d..44688969 100644 --- a/src/micsv89/micsv89.hpp +++ b/src/micsv89/micsv89.hpp @@ -27,6 +27,8 @@ #include #include +#include + 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. */ diff --git a/src/o2/CMakeLists.txt b/src/o2/CMakeLists.txt index 1d36e446..d981d096 100644 --- a/src/o2/CMakeLists.txt +++ b/src/o2/CMakeLists.txt @@ -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) diff --git a/src/o2/o2.cxx b/src/o2/o2.cxx index 30c0f2d5..985d8063 100644 --- a/src/o2/o2.cxx +++ b/src/o2/o2.cxx @@ -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; +} diff --git a/src/o2/o2.hpp b/src/o2/o2.hpp index 0c94795f..0fb72394 100644 --- a/src/o2/o2.hpp +++ b/src/o2/o2.hpp @@ -26,6 +26,8 @@ #include #include +#include + 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; }; diff --git a/src/t6713/CMakeLists.txt b/src/t6713/CMakeLists.txt index 71059acd..7115b246 100644 --- a/src/t6713/CMakeLists.txt +++ b/src/t6713/CMakeLists.txt @@ -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) diff --git a/src/t6713/t6713.cxx b/src/t6713/t6713.cxx index eb23f5c9..7f57d387 100644 --- a/src/t6713/t6713.cxx +++ b/src/t6713/t6713.cxx @@ -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 ; diff --git a/src/t6713/t6713.hpp b/src/t6713/t6713.hpp index eb942cd8..6070ce35 100644 --- a/src/t6713/t6713.hpp +++ b/src/t6713/t6713.hpp @@ -25,6 +25,8 @@ #include "mraa/i2c.hpp" +#include + 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 */ diff --git a/src/t6713/t6713.i b/src/t6713/t6713.i index d3d4b047..a65add7f 100644 --- a/src/t6713/t6713.i +++ b/src/t6713/t6713.i @@ -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 */