diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index d97ed32a..bcb1d648 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -170,7 +170,7 @@ add_example (otp538u) add_example (grovecollision) add_example (groveelectromagnet) add_example (groveemg) -add_example (groveo2) +add_example (o2) add_example (grovegsr) add_example (ina132) add_example (l298) diff --git a/examples/c++/groveo2.cxx b/examples/c++/o2.cxx similarity index 93% rename from examples/c++/groveo2.cxx rename to examples/c++/o2.cxx index 79741b52..25140cc3 100644 --- a/examples/c++/groveo2.cxx +++ b/examples/c++/o2.cxx @@ -24,7 +24,7 @@ #include #include #include -#include "groveo2.hpp" +#include "o2.hpp" using namespace std; @@ -42,8 +42,8 @@ int main(int argc, char **argv) //! [Interesting] // The was tested with the O2 Oxygen Concentration Sensor Module - // Instantiate a GroveO2 on analog pin A0 - upm::GroveO2 *O2 = new upm::GroveO2(0); + // Instantiate a O2 on analog pin A0 + upm::O2 *O2 = new upm::O2(0); while (shouldRun) { cout << "The output voltage is: " << O2->voltageValue() << "mV" << endl; diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index 03d74762..30b8a425 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -96,6 +96,7 @@ add_example (hka5) add_example (dfrorp) add_example (vdiv) add_example (mqx) +add_example (o2) # Custom examples add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps) diff --git a/examples/c/o2.c b/examples/c/o2.c new file mode 100644 index 00000000..3fed7555 --- /dev/null +++ b/examples/c/o2.c @@ -0,0 +1,75 @@ +/* + * Author: Jon Trulson + * Copyright (c) 2016 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. + */ + +#include +#include + +#include "o2.h" + +bool shouldRun = true; + +void sig_handler(int signo) +{ + if (signo == SIGINT) + shouldRun = false; +} + +int main() +{ + signal(SIGINT, sig_handler); + + //! [Interesting] + + // Instantiate a o2 sensor on analog pin A0 + o2_context sensor = o2_init(0); + + if (!sensor) + { + printf("o2_init() failed.\n"); + return -1; + } + + // Every half a second, sample the sensor output + while (shouldRun) + { + float raw_volts = 0.0; + float o2_percent = 0.0; + + o2_get_raw_volts(sensor, &raw_volts); + o2_get_value(sensor, &o2_percent); + + printf("O2 raw volts: %0.03f v, o2: %0.03f %\n", + raw_volts, o2_percent); + + usleep(500000); + } + + //! [Interesting] + + printf("Exiting\n"); + + o2_close(sensor); + + return 0; +} diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index 4f0f0941..3331f828 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -44,7 +44,7 @@ add_example(GroveMDSample grovemd) add_example(GroveMoistureSample grovemoisture) add_example(GroveMQ3 gas) add_example(GroveMQ9 gas) -add_example(GroveO2Example groveo2) +add_example(O2Example o2) add_example(GroveQTouch at42qt1070) add_example(GroveRelaySample grove) add_example(GroveRotarySample grove) diff --git a/examples/java/GroveO2Example.java b/examples/java/O2Example.java similarity index 94% rename from examples/java/GroveO2Example.java rename to examples/java/O2Example.java index 6ef0e61e..e366815d 100644 --- a/examples/java/GroveO2Example.java +++ b/examples/java/O2Example.java @@ -22,15 +22,15 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import upm_groveo2.GroveO2; +import upm_o2.O2; -public class GroveO2Example { +public class O2Example { public static void main(String[] args) { // TODO Auto-generated method stub //! [Interesting] // Initializing the Grove O2 sensor on the A) analog pin - GroveO2 o2 = new GroveO2(0); + O2 o2 = new O2(0); while(true){ System.out.println("The output voltage is: "+o2.voltageValue()); diff --git a/examples/javascript/groveo2.js b/examples/javascript/o2.js similarity index 84% rename from examples/javascript/groveo2.js rename to examples/javascript/o2.js index fcf3755c..71fe4250 100644 --- a/examples/javascript/groveo2.js +++ b/examples/javascript/o2.js @@ -21,15 +21,15 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var groveO2_lib = require("jsupm_groveo2"); +var O2_lib = require("jsupm_o2"); // The was tested with the O2 Oxygen Concentration Sensor Module -// Instantiate a GroveO2 on analog pin A0 -var groveO2_obj = new groveO2_lib.GroveO2(0); +// Instantiate a O2 on analog pin A0 +var O2_obj = new O2_lib.O2(0); var myInterval = setInterval(function() { - console.log("The output voltage is: " + roundNum(groveO2_obj.voltageValue(), 5) + "mV"); + console.log("The output voltage is: " + roundNum(O2_obj.voltageValue(), 5) + "mV"); }, 100); function roundNum(num, decimalPlaces) @@ -42,9 +42,9 @@ function roundNum(num, decimalPlaces) process.on('SIGINT', function() { clearInterval(myInterval); - groveO2_obj = null; - groveO2_lib.cleanUp(); - groveO2_lib = null; + O2_obj = null; + O2_lib.cleanUp(); + O2_lib = null; console.log("Exiting..."); process.exit(0); }); diff --git a/examples/python/groveo2.py b/examples/python/o2.py similarity index 88% rename from examples/python/groveo2.py rename to examples/python/o2.py index 03f612bb..55c34849 100644 --- a/examples/python/groveo2.py +++ b/examples/python/o2.py @@ -22,11 +22,11 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import time, sys, signal, atexit -import pyupm_groveo2 as upmGroveo2 +import pyupm_o2 as upmO2 # This was tested with the O2 Oxygen Concentration Sensor Module -# Instantiate a GroveO2 on analog pin A0 -myGroveO2 = upmGroveo2.GroveO2(0) +# Instantiate a O2 on analog pin A0 +myO2 = upmO2.O2(0) ## Exit handlers ## @@ -34,7 +34,7 @@ myGroveO2 = upmGroveo2.GroveO2(0) def SIGINTHandler(signum, frame): raise SystemExit -# This lets you run code on exit, including functions from myGroveO2 +# This lets you run code on exit, including functions from myO2 def exitHandler(): print "Exiting" sys.exit(0) @@ -46,6 +46,6 @@ signal.signal(signal.SIGINT, SIGINTHandler) while(1): print "The output voltage is: {0}mV".format( - myGroveO2.voltageValue()) + myO2.voltageValue()) time.sleep(.1) diff --git a/src/groveo2/CMakeLists.txt b/src/groveo2/CMakeLists.txt deleted file mode 100644 index d0be3539..00000000 --- a/src/groveo2/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -set (libname "groveo2") -set (libdescription "upm groveO2 oxygen concentration sensor module") -set (module_src ${libname}.cxx) -set (module_hpp ${libname}.hpp) -upm_module_init() diff --git a/src/groveo2/jsupm_groveo2.i b/src/groveo2/jsupm_groveo2.i deleted file mode 100644 index 11d849e2..00000000 --- a/src/groveo2/jsupm_groveo2.i +++ /dev/null @@ -1,8 +0,0 @@ -%module jsupm_groveo2 -%include "../upm.i" - -%{ - #include "groveo2.hpp" -%} - -%include "groveo2.hpp" diff --git a/src/o2/CMakeLists.txt b/src/o2/CMakeLists.txt new file mode 100644 index 00000000..44d50ea6 --- /dev/null +++ b/src/o2/CMakeLists.txt @@ -0,0 +1,8 @@ +upm_mixed_module_init (NAME o2 + DESCRIPTION "upm O2 oxygen concentration sensor module" + C_HDR o2.h + C_SRC o2.c + CPP_HDR o2.hpp + CPP_SRC o2.cxx + FTI_SRC o2_fti.c + REQUIRES mraa) diff --git a/src/groveo2/javaupm_groveo2.i b/src/o2/javaupm_o2.i similarity index 66% rename from src/groveo2/javaupm_groveo2.i rename to src/o2/javaupm_o2.i index a7611088..d4c93fcb 100644 --- a/src/groveo2/javaupm_groveo2.i +++ b/src/o2/javaupm_o2.i @@ -1,16 +1,16 @@ -%module javaupm_groveo2 +%module javaupm_o2 %include "../upm.i" %{ - #include "groveo2.hpp" + #include "o2.hpp" %} -%include "groveo2.hpp" +%include "o2.hpp" %pragma(java) jniclasscode=%{ static { try { - System.loadLibrary("javaupm_groveo2"); + System.loadLibrary("javaupm_o2"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load. \n" + e); System.exit(1); diff --git a/src/o2/jsupm_o2.i b/src/o2/jsupm_o2.i new file mode 100644 index 00000000..79a7a9bc --- /dev/null +++ b/src/o2/jsupm_o2.i @@ -0,0 +1,8 @@ +%module jsupm_o2 +%include "../upm.i" + +%{ + #include "o2.hpp" +%} + +%include "o2.hpp" diff --git a/src/o2/o2.c b/src/o2/o2.c new file mode 100644 index 00000000..2fe6c500 --- /dev/null +++ b/src/o2/o2.c @@ -0,0 +1,131 @@ +/* + * Author: + * Copyright (c) 2015 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. + */ + +#include +#include + +#include "o2.h" +o2_context o2_init(int16_t pin) +{ + o2_context dev = (o2_context)malloc(sizeof(struct _o2_context)); + + if(dev == NULL) return NULL; + + /* Init aio pin */ + dev->aio = mraa_aio_init(pin); + if(dev->aio == NULL) { + free(dev); + return NULL; + } + + /* Set defaults */ + dev->m_aRef = 5.0; + dev->m_offset = 0.0; + dev->m_scale = 1.0; + + return dev; +} + +void o2_close(o2_context dev) +{ + mraa_aio_close(dev->aio); + free(dev); +} + +upm_result_t o2_set_aref(const o2_context dev, float aref) +{ + dev->m_aRef = aref; + return UPM_SUCCESS; +} + +float o2_get_aref(const o2_context dev) +{ + return dev->m_aRef; +} + +upm_result_t o2_set_offset(const o2_context dev, float offset) +{ + dev->m_offset = offset; + return UPM_SUCCESS; +} + +float o2_get_offset(const o2_context dev) +{ + return dev->m_offset; +} + +upm_result_t o2_set_scale(const o2_context dev, float scale) +{ + dev->m_scale = scale; + return UPM_SUCCESS; +} + +float o2_get_scale(const o2_context dev) +{ + return dev->m_scale; +} + +upm_result_t o2_get_counts(const o2_context dev, int *value) +{ + /* Read counts */ + *value = mraa_aio_read(dev->aio); + if (*value < 0) return UPM_ERROR_OPERATION_FAILED; + return UPM_SUCCESS; +} + +upm_result_t o2_get_raw_volts(const o2_context dev, float *value) +{ + /* Read normalized adc value */ + *value = mraa_aio_read_float(dev->aio); + if (*value < 0.0) return UPM_ERROR_OPERATION_FAILED; + + /* Convert normalized value to voltage via aRef */ + *value *= dev->m_aRef; + + return UPM_SUCCESS; +} + +upm_result_t o2_get_value(const o2_context dev, float *value) +{ + /* Read normalized value */ + *value = mraa_aio_read_float(dev->aio); + if (*value < 0.0) + return UPM_ERROR_OPERATION_FAILED; + + /* Apply raw scale */ + *value *= dev->m_scale; + + /* 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 * dev->m_aRef/3.3; + + *value += dev->m_offset; + + return UPM_SUCCESS; +} + diff --git a/src/groveo2/groveo2.cxx b/src/o2/o2.cxx similarity index 94% rename from src/groveo2/groveo2.cxx rename to src/o2/o2.cxx index b982d3ff..30c0f2d5 100644 --- a/src/groveo2/groveo2.cxx +++ b/src/o2/o2.cxx @@ -26,12 +26,12 @@ #include #include -#include "groveo2.hpp" +#include "o2.hpp" using namespace upm; using namespace std; -GroveO2::GroveO2(int pin) +O2::O2(int pin) { if ( !(m_aio = mraa_aio_init(pin)) ) { @@ -41,12 +41,12 @@ GroveO2::GroveO2(int pin) } } -GroveO2::~GroveO2() +O2::~O2() { mraa_aio_close(m_aio); } -float GroveO2::voltageValue() +float O2::voltageValue() { int val = mraa_aio_read(m_aio); if (val == -1) return -1.0f; diff --git a/src/o2/o2.h b/src/o2/o2.h new file mode 100644 index 00000000..59880510 --- /dev/null +++ b/src/o2/o2.h @@ -0,0 +1,135 @@ +/* + * Author: + * Copyright (c) 2015 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 "upm.h" +#include "mraa/aio.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * device context + */ +typedef struct _o2_context { + /* mraa aio pin context */ + mraa_aio_context aio; + /* Analog voltage reference */ + float m_aRef; + /* Scale */ + float m_scale; + /* Offset in sensor units */ + float m_offset; +} *o2_context; + +/** + * Initialize analog sensor + * @param pin is Analog pin + * @return sensor context as void pointer + */ +o2_context o2_init(int16_t pin); + +/** + * Analog sensor destructor + * @param sensor context pointer deallocate memory + */ +void o2_close(o2_context dev); + +/** + * Set sensor adc vref. + * @param dev sensor context pointer + * @param aref Voltage reference routed to ADC ref pin + * @return Function result code + */ +upm_result_t o2_set_aref(const o2_context dev, float aref); + +/** + * Get sensor adc vref + * @param dev sensor context pointer + * @return Current adc vref + */ +float o2_get_aref(const o2_context dev); + +/** + * Set sensor offset. This offset is applied to the return value: + * counts = counts * scale + offset * scale + * @param dev sensor context pointer + * @param offset count offset value used + * @return Function result code + */ +upm_result_t o2_set_offset(const o2_context dev, float offset); + +/** + * Get sensor offset + * @param dev sensor context pointer + * @return Current sensor offset + */ +float o2_get_offset(const o2_context dev); + +/** + * Set sensor scale. This scale is applied to the return value: + * counts = counts * scale + offset * scale + * @param dev sensor context pointer + * @param scale count scale value used + * @return Function result code + */ +upm_result_t o2_set_scale(const o2_context dev, float scale); + +/** + * Get sensor scale + * @param dev sensor context pointer + * @return Current sensor scale + */ +float o2_get_scale(const o2_context dev); + +/** + * Read raw adc counts from sensor + * @param dev sensor context pointer + * @param *value Raw adc value + * @return Function result code + */ +upm_result_t o2_get_counts(const o2_context dev, int *value); + +/** + * Read voltage from sensor + * @param dev sensor context pointer + * @param *value Voltage (v) + * @return Function result code + */ +upm_result_t o2_get_raw_volts(const o2_context dev, float *value); + +/** + * Read value from sensor + * @param dev sensor context pointer + * @param *value O2 percentage + * @return Function result code + */ +upm_result_t o2_get_value(const o2_context dev, float *value); + +#ifdef __cplusplus +} +#endif diff --git a/src/groveo2/groveo2.hpp b/src/o2/o2.hpp similarity index 88% rename from src/groveo2/groveo2.hpp rename to src/o2/o2.hpp index 16081d23..a62341b1 100644 --- a/src/groveo2/groveo2.hpp +++ b/src/o2/o2.hpp @@ -29,13 +29,13 @@ namespace upm { /** * @brief Grove O2 Oxygen Gas Sensor library - * @defgroup groveo2 libupm-groveo2 + * @defgroup o2 libupm-o2 * @ingroup seeed analog gaseous */ /** - * @library groveo2 - * @sensor groveo2 + * @library o2 + * @sensor o2 * @comname Grove O2 Sensor * @type gaseous * @man seeed @@ -45,21 +45,21 @@ namespace upm { * * The Grove O2 Oxygen Gas sensor measures the oxygen concentration in the air * - * @image html groveo2.jpg - * @snippet groveo2.cxx Interesting + * @image html o2.jpg + * @snippet o2.cxx Interesting */ - class GroveO2 { + class O2 { public: /** * Grove O2 Oxygen Gas sensor constructor * * @param pin Analog pin to use */ - GroveO2(int pin); + O2(int pin); /** - * GroveO2 destructor + * O2 destructor */ - ~GroveO2(); + ~O2(); /** * Measures O2 from the sensor * diff --git a/src/o2/o2_fti.c b/src/o2/o2_fti.c new file mode 100644 index 00000000..489e1b8e --- /dev/null +++ b/src/o2/o2_fti.c @@ -0,0 +1,116 @@ +/* + * Author: + * Copyright (c) 2015 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. + */ + +#include "o2.h" +#include "upm_fti.h" +#include "fti/upm_sensor.h" +#include "fti/upm_raw.h" + +/** + * This file implements the Function Table Interface (FTI) for this sensor + */ + +const char upm_o2_name[] = "O2"; +const char upm_o2_description[] = "Analog oxygen sensor"; +const upm_protocol_t upm_o2_protocol[] = {UPM_ANALOG}; +const upm_sensor_t upm_o2_category[] = {UPM_RAW}; + +// forward declarations +const void* upm_o2_get_ft(upm_sensor_t sensor_type); +void* upm_o2_init_str(const char* protocol, const char* params); +void upm_o2_close(void* dev); +const upm_sensor_descriptor_t upm_o2_get_descriptor(); +upm_result_t upm_o2_set_offset(const void* dev, float offset); +upm_result_t upm_o2_set_scale(const void* dev, float scale); +upm_result_t upm_o2_get_value(const void* dev, float *value); + +/* This sensor implementes 2 function tables */ +/* 1. Generic base function table */ +static const upm_sensor_ft ft_gen = +{ + .upm_sensor_init_name = &upm_o2_init_str, + .upm_sensor_close = &upm_o2_close, + .upm_sensor_get_descriptor = &upm_o2_get_descriptor +}; + +/* 2. RAW function table */ +static const upm_raw_ft ft_raw = +{ + .upm_raw_set_offset = &upm_o2_set_offset, + .upm_raw_set_scale = &upm_o2_set_scale, + .upm_raw_get_value = &upm_o2_get_value +}; + +const void* upm_o2_get_ft(upm_sensor_t sensor_type) +{ + switch(sensor_type) + { + case UPM_SENSOR: + return &ft_gen; + case UPM_RAW: + return &ft_raw; + default: + return NULL; + } +} + +void* upm_o2_init_str(const char* protocol, const char* params) +{ + fprintf(stderr, "String initialization - not implemented, using ain0: %s\n", __FILE__); + return o2_init(0); +} + +void upm_o2_close(void* dev) +{ + o2_close((o2_context)dev); +} + +const upm_sensor_descriptor_t upm_o2_get_descriptor() +{ + /* Fill in the descriptor */ + upm_sensor_descriptor_t usd; + usd.name = upm_o2_name; + usd.description = upm_o2_description; + usd.protocol_size = 1; + usd.protocol = upm_o2_protocol; + usd.category_size = 1; + usd.category = upm_o2_category; + + return usd; +} + +upm_result_t upm_o2_set_offset(const void* dev, float offset) +{ + return o2_set_offset((o2_context)dev, offset); +} + +upm_result_t upm_o2_set_scale(const void* dev, float scale) +{ + return o2_set_scale((o2_context)dev, scale); +} + +upm_result_t upm_o2_get_value(const void* dev, float *value) +{ + return o2_get_value((o2_context)dev, value); +} diff --git a/src/groveo2/pyupm_groveo2.i b/src/o2/pyupm_o2.i similarity index 63% rename from src/groveo2/pyupm_groveo2.i rename to src/o2/pyupm_o2.i index 79bf2061..b501e21d 100644 --- a/src/groveo2/pyupm_groveo2.i +++ b/src/o2/pyupm_o2.i @@ -1,11 +1,11 @@ // Include doxygen-generated documentation %include "pyupm_doxy2swig.i" -%module pyupm_groveo2 +%module pyupm_o2 %include "../upm.i" %feature("autodoc", "3"); -%include "groveo2.hpp" +%include "o2.hpp" %{ - #include "groveo2.hpp" + #include "o2.hpp" %}