diff --git a/docs/images/grovegsr.jpg b/docs/images/gsr.jpg similarity index 100% rename from docs/images/grovegsr.jpg rename to docs/images/gsr.jpg diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 23a87e24..6f4291fe 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -171,7 +171,7 @@ add_example (grovecollision) add_example (groveelectromagnet) add_example (emg) add_example (o2) -add_example (grovegsr) +add_example (gsr) add_example (ina132) add_example (l298) add_example (l298-stepper) diff --git a/examples/c++/grovegsr.cxx b/examples/c++/gsr.cxx similarity index 89% rename from examples/c++/grovegsr.cxx rename to examples/c++/gsr.cxx index 6068e791..08034060 100644 --- a/examples/c++/grovegsr.cxx +++ b/examples/c++/gsr.cxx @@ -25,7 +25,7 @@ #include #include #include -#include "grovegsr.hpp" +#include "gsr.hpp" using namespace std; @@ -42,10 +42,10 @@ int main() signal(SIGINT, sig_handler); //! [Interesting] - // The was tested with the GroveGSR Galvanic Skin Response Sensor module. + // The was tested with the GSR Galvanic Skin Response Sensor module. - // Instantiate a GroveGSR on analog pin A0 - upm::GroveGSR *gsr = new upm::GroveGSR(0); + // Instantiate a GSR on analog pin A0 + upm::GSR *gsr = new upm::GSR(0); cout << "Calibrating...." << endl; gsr->calibrate(); diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index ed66f496..6dc10a13 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -98,6 +98,7 @@ add_example (vdiv) add_example (mqx) add_example (o2) add_example (emg) +add_example (gsr) # Custom examples add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps) diff --git a/examples/c/gsr.c b/examples/c/gsr.c new file mode 100644 index 00000000..d0eea26a --- /dev/null +++ b/examples/c/gsr.c @@ -0,0 +1,86 @@ +/* + * 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 "gsr.h" + +bool shouldRun = true; + +void sig_handler(int signo) +{ + if (signo == SIGINT) + shouldRun = false; +} + +int main() +{ + signal(SIGINT, sig_handler); + + //! [Interesting] + + // Instantiate a gsr sensor on analog pin A0 + gsr_context sensor = gsr_init(0); + + if (!sensor) + { + printf("gsr_init() failed.\n"); + return -1; + } + + // Set the aref, scale, and offset + gsr_set_aref(sensor, 5.0); + gsr_set_scale(sensor, 1.0); + gsr_set_offset(sensor, -.1); + printf("aRef: %0.03f scale: %0.03f offset: %0.03f\n\n", + gsr_get_aref(sensor), + gsr_get_scale(sensor), + gsr_get_offset(sensor)); + + // Every half a second, sample the sensor output + while (shouldRun) + { + float normalized = 0.0; + float raw_volts = 0.0; + float volts = 0.0; + + gsr_get_normalized(sensor, &normalized); + gsr_get_raw_volts(sensor, &raw_volts); + gsr_get_volts(sensor, &volts); + + printf("Normalized output: %0.03f, raw gsr sensor output: %0.03f v " + "adjusted output: %0.03f v\n", normalized, raw_volts, volts); + + usleep(500000); + } + + //! [Interesting] + + printf("Exiting\n"); + + gsr_close(sensor); + + return 0; +} diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index 4fa33ea0..ce3b6832 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -35,7 +35,7 @@ add_example(GroveButton_intrSample grove) add_example(GroveCollision grovecollision) add_example(GroveEHRSample groveehr) add_example(Emg emg) -add_example(GroveGsr grovegsr) +add_example(Gsr gsr) add_example(GroveLed_multiSample grove) add_example(GroveLEDSample grove) add_example(GroveLightSample grove) diff --git a/examples/java/GroveGsr.java b/examples/java/Gsr.java similarity index 95% rename from examples/java/GroveGsr.java rename to examples/java/Gsr.java index d7e9a69c..13e9e78e 100644 --- a/examples/java/GroveGsr.java +++ b/examples/java/Gsr.java @@ -22,16 +22,16 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import upm_grovegsr.GroveGSR; +import upm_gsr.GSR; -public class GroveGsr { +public class Gsr { public static void main(String[] args) { // TODO Auto-generated method stub //! [Interesting] // Instantiate a Grove GSR sensor on analog pin A0 - GroveGSR gsr = new GroveGSR(0); + GSR gsr = new GSR(0); System.out.println("Calibrating..."); gsr.calibrate(); diff --git a/examples/javascript/grovegsr.js b/examples/javascript/gsr.js similarity index 80% rename from examples/javascript/grovegsr.js rename to examples/javascript/gsr.js index 6b98af19..c5e06f73 100644 --- a/examples/javascript/grovegsr.js +++ b/examples/javascript/gsr.js @@ -22,18 +22,18 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var grovegsr_lib = require("jsupm_grovegsr"); +var gsr_lib = require("jsupm_gsr"); -// The was tested with the GroveGSR Galvanic Skin Response Sensor module. +// The was tested with the GSR Galvanic Skin Response Sensor module. -// Instantiate a GroveGSR on analog pin A0 -var grovegsr_obj = new grovegsr_lib.GroveGSR(0); +// Instantiate a GSR on analog pin A0 +var gsr_obj = new gsr_lib.GSR(0); console.log("Calibrating...."); -grovegsr_obj.calibrate(); +gsr_obj.calibrate(); var myInterval = setInterval(function() { - console.log(grovegsr_obj.value()); + console.log(gsr_obj.value()); }, 500); @@ -41,9 +41,9 @@ var myInterval = setInterval(function() process.on('SIGINT', function() { clearInterval(myInterval); - grovegsr_obj = null; - grovegsr_lib.cleanUp(); - grovegsr_lib = null; + gsr_obj = null; + gsr_lib.cleanUp(); + gsr_lib = null; console.log("Exiting..."); process.exit(0); }); diff --git a/examples/python/grovegsr.py b/examples/python/gsr.py similarity index 90% rename from examples/python/grovegsr.py rename to examples/python/gsr.py index 993a6b0f..43ff809a 100644 --- a/examples/python/grovegsr.py +++ b/examples/python/gsr.py @@ -22,12 +22,12 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import time, sys, signal, atexit -import pyupm_grovegsr as upmGrovegsr +import pyupm_gsr as upmGsr -# Tested with the GroveGSR Galvanic Skin Response Sensor module. +# Tested with the GSR Galvanic Skin Response Sensor module. -# Instantiate a GroveGSR on analog pin A0 -myGSR = upmGrovegsr.GroveGSR(0) +# Instantiate a GSR on analog pin A0 +myGSR = upmGsr.GSR(0) ## Exit handlers ## diff --git a/src/grovegsr/CMakeLists.txt b/src/grovegsr/CMakeLists.txt deleted file mode 100644 index d352cdd7..00000000 --- a/src/grovegsr/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -set (libname "grovegsr") -set (libdescription "upm grovegsr galvanic skin response sensor module") -set (module_src ${libname}.cxx) -set (module_hpp ${libname}.hpp) -upm_module_init() diff --git a/src/grovegsr/jsupm_grovegsr.i b/src/grovegsr/jsupm_grovegsr.i deleted file mode 100644 index 5ee875bc..00000000 --- a/src/grovegsr/jsupm_grovegsr.i +++ /dev/null @@ -1,8 +0,0 @@ -%module jsupm_grovegsr -%include "../upm.i" - -%{ - #include "grovegsr.hpp" -%} - -%include "grovegsr.hpp" diff --git a/src/gsr/CMakeLists.txt b/src/gsr/CMakeLists.txt new file mode 100644 index 00000000..b42d8f56 --- /dev/null +++ b/src/gsr/CMakeLists.txt @@ -0,0 +1,8 @@ +upm_mixed_module_init (NAME gsr + DESCRIPTION "upm gsr galvanic skin response sensor module" + C_HDR gsr.h + C_SRC gsr.c + CPP_HDR gsr.hpp + CPP_SRC gsr.cxx + FTI_SRC gsr_fti.c + REQUIRES mraa) diff --git a/src/gsr/gsr.c b/src/gsr/gsr.c new file mode 100644 index 00000000..6cc90eb9 --- /dev/null +++ b/src/gsr/gsr.c @@ -0,0 +1,127 @@ +/* + * 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 "gsr.h" + +gsr_context gsr_init(int16_t pin) +{ + gsr_context dev = (gsr_context) malloc(sizeof(struct _gsr_context)); + + if (dev == NULL) + return NULL; + + /* Init aio pin */ + dev->aio = mraa_aio_init(pin); + + if (dev->aio == NULL) { + free(dev); + return NULL; + } + + /* Set the ADC ref, scale, and offset defaults */ + dev->m_aRef = 5.0; + dev->m_scale = 1.0; + dev->m_offset = 0.0; + + return dev; +} + +void gsr_close(gsr_context dev) +{ + mraa_aio_close(dev->aio); + free(dev); +} + +upm_result_t gsr_set_aref(const gsr_context dev, float aref) +{ + dev->m_aRef = aref; + return UPM_SUCCESS; +} + +upm_result_t gsr_set_scale(const gsr_context dev, float scale) +{ + dev->m_scale = scale; + return UPM_SUCCESS; +} + +upm_result_t gsr_set_offset(const gsr_context dev, float offset) +{ + dev->m_offset = offset; + return UPM_SUCCESS; +} + +float gsr_get_aref(const gsr_context dev) +{ + return dev->m_aRef; +} + +float gsr_get_scale(const gsr_context dev) +{ + return dev->m_scale; +} + +float gsr_get_offset(const gsr_context dev) +{ + return dev->m_offset; +} + +upm_result_t gsr_get_normalized(const gsr_context dev, float *value) +{ + *value = mraa_aio_read_float(dev->aio); + if (*value < 0) + return UPM_ERROR_OPERATION_FAILED; +} + +upm_result_t gsr_get_raw_volts(const gsr_context dev, float *value) +{ + *value = mraa_aio_read_float(dev->aio); + if (*value < 0) + return UPM_ERROR_OPERATION_FAILED; + + /* Scale by the ADC reference voltage */ + *value *= dev->m_aRef; + + return UPM_SUCCESS; +} + +upm_result_t gsr_get_volts(const gsr_context dev, float *value) +{ + *value = mraa_aio_read_float(dev->aio); + if (*value < 0) + return UPM_ERROR_OPERATION_FAILED; + + /* Apply raw scale */ + *value *= dev->m_scale; + + /* Scale to aRef */ + *value *= dev->m_aRef; + + /* Apply the offset in volts */ + *value += dev->m_offset; + + return UPM_SUCCESS; +} diff --git a/src/grovegsr/grovegsr.cxx b/src/gsr/gsr.cxx similarity index 66% rename from src/grovegsr/grovegsr.cxx rename to src/gsr/gsr.cxx index 17b19c58..19d4f3e6 100644 --- a/src/grovegsr/grovegsr.cxx +++ b/src/gsr/gsr.cxx @@ -26,45 +26,42 @@ #include #include -#include "grovegsr.hpp" +#include "gsr.hpp" using namespace upm; using namespace std; -GroveGSR::GroveGSR(int pin) +GSR::GSR(int pin) { if ( !(m_aio = mraa_aio_init(pin)) ) + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); +} + +GSR::~GSR() +{ + mraa_aio_close(m_aio); +} + +void GSR::calibrate() +{ + int val, threshold, sum = 0; + + for(int i=0; i<500; i++) { - throw std::invalid_argument(std::string(__FUNCTION__) + - ": mraa_aio_init() failed, invalid pin?"); - return; + val = mraa_aio_read(m_aio); + if (val < 0) + throw std::runtime_error(std::string(__FUNCTION__) + + ": Failed to do an aio read."); + sum += val; + usleep(5000); } + threshold = sum / 500; + cout << "Threshold = " << threshold << endl; } -GroveGSR::~GroveGSR() +int GSR::value() { - mraa_aio_close(m_aio); -} - -void GroveGSR::calibrate() -{ - sleep(1); - int val, threshold, sum = 0; - - for(int i=0; i<500; i++) - { - val = mraa_aio_read(m_aio); - if (val != -1) throw std::runtime_error(std::string(__FUNCTION__) + - ": Failed to do an aio read."); - sum += val; - usleep(5000); - } - threshold = sum / 500; - cout << "Threshold = " << threshold << endl; -} - -int GroveGSR::value() -{ - int val = mraa_aio_read(m_aio); - return val; + int val = mraa_aio_read(m_aio); + return val; } diff --git a/src/gsr/gsr.h b/src/gsr/gsr.h new file mode 100644 index 00000000..d541169c --- /dev/null +++ b/src/gsr/gsr.h @@ -0,0 +1,133 @@ +/* + * 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 + +/** + * driver context + */ +typedef struct _gsr_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; +} *gsr_context; + +/** + * Initialize analog sensor + * @param pin Analog pin + * @return sensor context + */ +gsr_context gsr_init(int16_t pin); + +/** + * Analog sensor destructor + * @param sensor context pointer + */ +void gsr_close(gsr_context dev); + +/** + * Set ADC reference voltage + * @param dev sensor context pointer + * @param aref ADC reference voltage + * @return Function result code + */ +upm_result_t gsr_set_aref(const gsr_context dev, float aref); + +/** + * Set sensor scale. This scale is applied to the return value: + * counts = counts * scale + * @param dev sensor context pointer + * @param scale count scale value used + * @return Function result code + */ +upm_result_t gsr_set_scale(const gsr_context dev, float scale); + +/** + * Set sensor offset. This offset is applied to the return value: + * value = value + offset + * @param dev sensor context pointer + * @param offset count offset value used + * @return Function result code + */ +upm_result_t gsr_set_offset(const gsr_context dev, float offset); + +/** + * Get sensor aref + * @param dev sensor context pointer + * @return Sensor ADC reference voltage + */ +float gsr_get_aref(const gsr_context dev); + +/** + * Get sensor scale + * @param dev sensor context pointer + * @return Sensor scale + */ +float gsr_get_scale(const gsr_context dev); + +/** + * Get sensor offset + * @param dev sensor context pointer + * @return Sensor offset + */ +float gsr_get_offset(const gsr_context dev); + +/** + * Read normalized value for sensor + * @param dev sensor context pointer + * @param *value Normalized value (0.0 -> 1.0) + * @return Function result code + */ +upm_result_t gsr_get_normalized(const gsr_context dev, float *value); + +/** + * Read raw voltage from the sensor + * @param dev sensor context pointer + * @param *value Raw sensor voltage + * @return Function result code + */ +upm_result_t gsr_get_raw_volts(const gsr_context dev, float *value); + +/** + * Read scaled/offset voltage from the sensor + * @param dev sensor context pointer + * @param *value Adjusted sensor voltage + * @return Function result code + */ +upm_result_t gsr_get_volts(const gsr_context dev, float *value); +#ifdef __cplusplus +} +#endif diff --git a/src/grovegsr/grovegsr.hpp b/src/gsr/gsr.hpp similarity index 89% rename from src/grovegsr/grovegsr.hpp rename to src/gsr/gsr.hpp index 32666abf..fd55305e 100644 --- a/src/grovegsr/grovegsr.hpp +++ b/src/gsr/gsr.hpp @@ -29,13 +29,13 @@ namespace upm { /** * @brief Grove GSR Galvanic Skin Response Sensor library - * @defgroup grovegsr libupm-grovegsr + * @defgroup gsr libupm-gsr * @ingroup seeed analog electric */ /** - * @library grovegsr - * @sensor grovegsr + * @library gsr + * @sensor gsr * @comname Grove GSR Sensor * @type electric * @man seeed @@ -48,21 +48,21 @@ namespace upm { * In other words, it measures sweat on your fingers * as an indicator of strong emotional reactions. * - * @image html grovegsr.jpg - * @snippet grovegsr.cxx Interesting + * @image html gsr.jpg + * @snippet gsr.cxx Interesting */ - class GroveGSR { + class GSR { public: /** * Grove GSR sensor constructor * * @param pin Analog pin to use */ - GroveGSR(int pin); + GSR(int pin); /** - * GroveGSR destructor + * GSR destructor */ - ~GroveGSR(); + ~GSR(); /** * Calibrates the Grove GSR sensor diff --git a/src/gsr/gsr_fti.c b/src/gsr/gsr_fti.c new file mode 100644 index 00000000..602ae566 --- /dev/null +++ b/src/gsr/gsr_fti.c @@ -0,0 +1,119 @@ +/* + * 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 "gsr.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_gsr_name[] = "GSR"; +const char upm_gsr_description[] = "Analog gsr sensor"; +const upm_protocol_t upm_gsr_protocol[] = {UPM_ANALOG}; +const upm_sensor_t upm_gsr_category[] = {UPM_RAW}; + +// forward declarations +const void* upm_gsr_get_ft(upm_sensor_t sensor_type); +void* upm_gsr_init_str(const char* protocol, const char* params); +void upm_gsr_close(void* dev); +const upm_sensor_descriptor_t upm_gsr_get_descriptor(); +upm_result_t upm_gsr_set_offset(const void* dev, float offset); +upm_result_t upm_gsr_set_scale(const void* dev, float scale); +upm_result_t upm_gsr_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_gsr_init_str, + .upm_sensor_close = &upm_gsr_close, + .upm_sensor_get_descriptor = &upm_gsr_get_descriptor +}; + +/* 2. RAW function table */ +static const upm_raw_ft ft_raw = +{ + .upm_raw_set_offset = &upm_gsr_set_offset, + .upm_raw_set_scale = &upm_gsr_set_scale, + .upm_raw_get_value = &upm_gsr_get_value +}; + +const void* upm_gsr_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_gsr_init_str(const char* protocol, const char* params) +{ + fprintf(stderr, "String initialization - not implemented, using ain0: %s\n", __FILENAME__); + return gsr_init(0); +} + +void upm_gsr_close(void* dev) +{ + gsr_close((gsr_context)dev); +} + +const upm_sensor_descriptor_t upm_gsr_get_descriptor() +{ + /* Fill in the descriptor */ + upm_sensor_descriptor_t usd; + usd.name = upm_gsr_name; + usd.description = upm_gsr_description; + usd.protocol_size = 1; + usd.protocol = upm_gsr_protocol; + usd.category_size = 1; + usd.category = upm_gsr_category; + + return usd; +} + +upm_result_t upm_gsr_set_offset(const void* dev, float offset) +{ + return gsr_set_offset((gsr_context)dev, offset); +} + +upm_result_t upm_gsr_set_scale(const void* dev, float scale) +{ + return gsr_set_scale((gsr_context)dev, scale); +} + +upm_result_t upm_gsr_get_value(const void* dev, float *value) +{ + return gsr_get_volts((gsr_context)dev, value); +} diff --git a/src/grovegsr/javaupm_grovegsr.i b/src/gsr/javaupm_gsr.i similarity index 66% rename from src/grovegsr/javaupm_grovegsr.i rename to src/gsr/javaupm_gsr.i index 22e27b0c..4d058129 100644 --- a/src/grovegsr/javaupm_grovegsr.i +++ b/src/gsr/javaupm_gsr.i @@ -1,16 +1,16 @@ -%module javaupm_grovegsr +%module javaupm_gsr %include "../upm.i" %{ - #include "grovegsr.hpp" + #include "gsr.hpp" %} -%include "grovegsr.hpp" +%include "gsr.hpp" %pragma(java) jniclasscode=%{ static { try { - System.loadLibrary("javaupm_grovegsr"); + System.loadLibrary("javaupm_gsr"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load. \n" + e); System.exit(1); diff --git a/src/gsr/jsupm_gsr.i b/src/gsr/jsupm_gsr.i new file mode 100644 index 00000000..c7960dc2 --- /dev/null +++ b/src/gsr/jsupm_gsr.i @@ -0,0 +1,8 @@ +%module jsupm_gsr +%include "../upm.i" + +%{ + #include "gsr.hpp" +%} + +%include "gsr.hpp" diff --git a/src/grovegsr/pyupm_grovegsr.i b/src/gsr/pyupm_gsr.i similarity index 62% rename from src/grovegsr/pyupm_grovegsr.i rename to src/gsr/pyupm_gsr.i index 92a30c2f..8cc6014e 100644 --- a/src/grovegsr/pyupm_grovegsr.i +++ b/src/gsr/pyupm_gsr.i @@ -1,11 +1,11 @@ // Include doxygen-generated documentation %include "pyupm_doxy2swig.i" -%module pyupm_grovegsr +%module pyupm_gsr %include "../upm.i" %feature("autodoc", "3"); -%include "grovegsr.hpp" +%include "gsr.hpp" %{ - #include "grovegsr.hpp" + #include "gsr.hpp" %}