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 "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;
};