From a19678948b1ff59ee4021722c1b5201a8fe4d9fb Mon Sep 17 00:00:00 2001 From: Noel Eck Date: Thu, 8 Sep 2016 12:35:41 -0700 Subject: [PATCH] emg: Added emg sensor C source Added the C source for the emg sensor with necessary changes to cmake, examples, docs. * Renamed all files with groveemg to emg * Replaced all instances of groveemg with emg * Added C source for emg sensor * Updated all cmake files * Added C example for emg sensor Signed-off-by: Noel Eck --- docs/images/{groveemg.jpg => emg.jpg} | Bin examples/c++/CMakeLists.txt | 2 +- examples/c++/{groveemg.cxx => emg.cxx} | 8 +- examples/c/CMakeLists.txt | 1 + examples/c/emg.c | 86 +++++++++++ examples/java/CMakeLists.txt | 2 +- examples/java/{GroveEmg.java => Emg.java} | 6 +- examples/javascript/{groveemg.js => emg.js} | 18 +-- examples/python/{groveemg.py => emg.py} | 8 +- src/emg/CMakeLists.txt | 8 ++ src/emg/emg.c | 127 +++++++++++++++++ src/{groveemg/groveemg.cxx => emg/emg.cxx} | 10 +- src/emg/emg.h | 133 ++++++++++++++++++ src/{groveemg/groveemg.hpp => emg/emg.hpp} | 18 +-- src/emg/emg_fti.c | 119 ++++++++++++++++ .../javaupm_groveemg.i => emg/javaupm_emg.i} | 8 +- src/emg/jsupm_emg.i | 8 ++ .../pyupm_groveemg.i => emg/pyupm_emg.i} | 6 +- src/groveemg/CMakeLists.txt | 5 - src/groveemg/jsupm_groveemg.i | 8 -- 20 files changed, 525 insertions(+), 56 deletions(-) rename docs/images/{groveemg.jpg => emg.jpg} (100%) rename examples/c++/{groveemg.cxx => emg.cxx} (89%) create mode 100644 examples/c/emg.c rename examples/java/{GroveEmg.java => Emg.java} (95%) rename examples/javascript/{groveemg.js => emg.js} (80%) rename examples/python/{groveemg.py => emg.py} (90%) create mode 100644 src/emg/CMakeLists.txt create mode 100644 src/emg/emg.c rename src/{groveemg/groveemg.cxx => emg/emg.cxx} (93%) create mode 100644 src/emg/emg.h rename src/{groveemg/groveemg.hpp => emg/emg.hpp} (89%) create mode 100644 src/emg/emg_fti.c rename src/{groveemg/javaupm_groveemg.i => emg/javaupm_emg.i} (66%) create mode 100644 src/emg/jsupm_emg.i rename src/{groveemg/pyupm_groveemg.i => emg/pyupm_emg.i} (62%) delete mode 100644 src/groveemg/CMakeLists.txt delete mode 100644 src/groveemg/jsupm_groveemg.i diff --git a/docs/images/groveemg.jpg b/docs/images/emg.jpg similarity index 100% rename from docs/images/groveemg.jpg rename to docs/images/emg.jpg diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index bcb1d648..23a87e24 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -169,7 +169,7 @@ add_example (nunchuck) add_example (otp538u) add_example (grovecollision) add_example (groveelectromagnet) -add_example (groveemg) +add_example (emg) add_example (o2) add_example (grovegsr) add_example (ina132) diff --git a/examples/c++/groveemg.cxx b/examples/c++/emg.cxx similarity index 89% rename from examples/c++/groveemg.cxx rename to examples/c++/emg.cxx index 3a049dd3..7cf2df8d 100644 --- a/examples/c++/groveemg.cxx +++ b/examples/c++/emg.cxx @@ -24,7 +24,7 @@ #include #include #include -#include "groveemg.hpp" +#include "emg.hpp" using namespace std; @@ -41,9 +41,9 @@ int main(int argc, char **argv) signal(SIGINT, sig_handler); //! [Interesting] - // The was tested with the GroveEMG Muscle Signal Reader Sensor Module - // Instantiate a GroveEMG on analog pin A0 - upm::GroveEMG *emg = new upm::GroveEMG(0); + // The was tested with the EMG Muscle Signal Reader Sensor Module + // Instantiate a EMG on analog pin A0 + upm::EMG *emg = new upm::EMG(0); cout << "Calibrating...." << endl; emg->calibrate(); diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index 30b8a425..ed66f496 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -97,6 +97,7 @@ add_example (dfrorp) add_example (vdiv) add_example (mqx) add_example (o2) +add_example (emg) # Custom examples add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps) diff --git a/examples/c/emg.c b/examples/c/emg.c new file mode 100644 index 00000000..1837d74a --- /dev/null +++ b/examples/c/emg.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 "emg.h" + +bool shouldRun = true; + +void sig_handler(int signo) +{ + if (signo == SIGINT) + shouldRun = false; +} + +int main() +{ + signal(SIGINT, sig_handler); + + //! [Interesting] + + // Instantiate a emg sensor on analog pin A0 + emg_context sensor = emg_init(0); + + if (!sensor) + { + printf("emg_init() failed.\n"); + return -1; + } + + // Set the aref, scale, and offset + emg_set_aref(sensor, 5.0); + emg_set_scale(sensor, 1.0); + emg_set_offset(sensor, -.1); + printf("aRef: %0.03f scale: %0.03f offset: %0.03f\n\n", + emg_get_aref(sensor), + emg_get_scale(sensor), + emg_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; + + emg_get_normalized(sensor, &normalized); + emg_get_raw_volts(sensor, &raw_volts); + emg_get_volts(sensor, &volts); + + printf("Normalized output: %0.03f, raw emg sensor output: %0.03f v " + "adjusted output: %0.03f v\n", normalized, raw_volts, volts); + + usleep(500000); + } + + //! [Interesting] + + printf("Exiting\n"); + + emg_close(sensor); + + return 0; +} diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index 3331f828..4fa33ea0 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -34,7 +34,7 @@ add_example(GroveButtonSample grove) add_example(GroveButton_intrSample grove) add_example(GroveCollision grovecollision) add_example(GroveEHRSample groveehr) -add_example(GroveEmg groveemg) +add_example(Emg emg) add_example(GroveGsr grovegsr) add_example(GroveLed_multiSample grove) add_example(GroveLEDSample grove) diff --git a/examples/java/GroveEmg.java b/examples/java/Emg.java similarity index 95% rename from examples/java/GroveEmg.java rename to examples/java/Emg.java index 98277011..30f46dc0 100644 --- a/examples/java/GroveEmg.java +++ b/examples/java/Emg.java @@ -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. */ -import upm_groveemg.GroveEMG; +import upm_emg.EMG; -public class GroveEmg { +public class Emg { public static void main(String[] args) { // TODO Auto-generated method stub //! [Interesting] // Instantiating the Grove EMG sensor on Analog pin 0 - GroveEMG emg = new GroveEMG(0); + EMG emg = new EMG(0); System.out.println("Calibrating ... "); emg.calibrate(); diff --git a/examples/javascript/groveemg.js b/examples/javascript/emg.js similarity index 80% rename from examples/javascript/groveemg.js rename to examples/javascript/emg.js index 4ddcb6e6..ec4be8e7 100644 --- a/examples/javascript/groveemg.js +++ b/examples/javascript/emg.js @@ -21,26 +21,26 @@ * 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 groveemg_lib = require("jsupm_groveemg"); +var emg_lib = require("jsupm_emg"); -// The was tested with the GroveEMG Muscle Signal Reader Sensor Module -// Instantiate a GroveEMG on analog pin A0 -var groveemg_obj = new groveemg_lib.GroveEMG(0); +// The was tested with the EMG Muscle Signal Reader Sensor Module +// Instantiate a EMG on analog pin A0 +var emg_obj = new emg_lib.EMG(0); console.log("Calibrating...."); -groveemg_obj.calibrate(); +emg_obj.calibrate(); var myInterval = setInterval(function() { - console.log(groveemg_obj.value()); + console.log(emg_obj.value()); }, 100); // When exiting: clear interval, and print message process.on('SIGINT', function() { clearInterval(myInterval); - groveemg_obj = null; - groveemg_lib.cleanUp(); - groveemg_lib = null; + emg_obj = null; + emg_lib.cleanUp(); + emg_lib = null; console.log("Exiting..."); process.exit(0); }); diff --git a/examples/python/groveemg.py b/examples/python/emg.py similarity index 90% rename from examples/python/groveemg.py rename to examples/python/emg.py index 898db266..d2446647 100644 --- a/examples/python/groveemg.py +++ b/examples/python/emg.py @@ -22,11 +22,11 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import time, sys, signal, atexit -import pyupm_groveemg as upmGroveemg +import pyupm_emg as upmEmg -# Tested with the GroveEMG Muscle Signal Reader Sensor Module -# Instantiate a GroveEMG on analog pin A0 -myEMG = upmGroveemg.GroveEMG(0) +# Tested with the EMG Muscle Signal Reader Sensor Module +# Instantiate a EMG on analog pin A0 +myEMG = upmEmg.EMG(0) ## Exit handlers ## diff --git a/src/emg/CMakeLists.txt b/src/emg/CMakeLists.txt new file mode 100644 index 00000000..fcb030f7 --- /dev/null +++ b/src/emg/CMakeLists.txt @@ -0,0 +1,8 @@ +upm_mixed_module_init (NAME emg + DESCRIPTION "upm emg muscle signal reader sensor module" + C_HDR emg.h + C_SRC emg.c + CPP_HDR emg.hpp + CPP_SRC emg.cxx + FTI_SRC emg_fti.c + REQUIRES mraa) diff --git a/src/emg/emg.c b/src/emg/emg.c new file mode 100644 index 00000000..30730f58 --- /dev/null +++ b/src/emg/emg.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 "emg.h" + +emg_context emg_init(int16_t pin) +{ + emg_context dev = (emg_context) malloc(sizeof(struct _emg_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 emg_close(emg_context dev) +{ + mraa_aio_close(dev->aio); + free(dev); +} + +upm_result_t emg_set_aref(const emg_context dev, float aref) +{ + dev->m_aRef = aref; + return UPM_SUCCESS; +} + +upm_result_t emg_set_scale(const emg_context dev, float scale) +{ + dev->m_scale = scale; + return UPM_SUCCESS; +} + +upm_result_t emg_set_offset(const emg_context dev, float offset) +{ + dev->m_offset = offset; + return UPM_SUCCESS; +} + +float emg_get_aref(const emg_context dev) +{ + return dev->m_aRef; +} + +float emg_get_scale(const emg_context dev) +{ + return dev->m_scale; +} + +float emg_get_offset(const emg_context dev) +{ + return dev->m_offset; +} + +upm_result_t emg_get_normalized(const emg_context dev, float *value) +{ + *value = mraa_aio_read_float(dev->aio); + if (*value < 0) + return UPM_ERROR_OPERATION_FAILED; +} + +upm_result_t emg_get_raw_volts(const emg_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 emg_get_volts(const emg_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/groveemg/groveemg.cxx b/src/emg/emg.cxx similarity index 93% rename from src/groveemg/groveemg.cxx rename to src/emg/emg.cxx index 538c6b50..d33f56f3 100644 --- a/src/groveemg/groveemg.cxx +++ b/src/emg/emg.cxx @@ -26,12 +26,12 @@ #include #include -#include "groveemg.hpp" +#include "emg.hpp" using namespace upm; using namespace std; -GroveEMG::GroveEMG(int pin) +EMG::EMG(int pin) { if ( !(m_aio = mraa_aio_init(pin)) ) { @@ -41,12 +41,12 @@ GroveEMG::GroveEMG(int pin) } } -GroveEMG::~GroveEMG() +EMG::~EMG() { mraa_aio_close(m_aio); } -void GroveEMG::calibrate() +void EMG::calibrate() { int val, sum = 0; @@ -62,7 +62,7 @@ void GroveEMG::calibrate() cout << "Static analog data = " << sum << endl; } -int GroveEMG::value() +int EMG::value() { int val = mraa_aio_read(m_aio); return val; diff --git a/src/emg/emg.h b/src/emg/emg.h new file mode 100644 index 00000000..21f4a51d --- /dev/null +++ b/src/emg/emg.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 _emg_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; +} *emg_context; + +/** + * Initialize analog sensor + * @param pin Analog pin + * @return sensor context + */ +emg_context emg_init(int16_t pin); + +/** + * Analog sensor destructor + * @param sensor context pointer + */ +void emg_close(emg_context dev); + +/** + * Set ADC reference voltage + * @param dev sensor context pointer + * @param aref ADC reference voltage + * @return Function result code + */ +upm_result_t emg_set_aref(const emg_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 emg_set_scale(const emg_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 emg_set_offset(const emg_context dev, float offset); + +/** + * Get sensor aref + * @param dev sensor context pointer + * @return Sensor ADC reference voltage + */ +float emg_get_aref(const emg_context dev); + +/** + * Get sensor scale + * @param dev sensor context pointer + * @return Sensor scale + */ +float emg_get_scale(const emg_context dev); + +/** + * Get sensor offset + * @param dev sensor context pointer + * @return Sensor offset + */ +float emg_get_offset(const emg_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 emg_get_normalized(const emg_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 emg_get_raw_volts(const emg_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 emg_get_volts(const emg_context dev, float *value); +#ifdef __cplusplus +} +#endif diff --git a/src/groveemg/groveemg.hpp b/src/emg/emg.hpp similarity index 89% rename from src/groveemg/groveemg.hpp rename to src/emg/emg.hpp index eef5fa34..9a9121e3 100644 --- a/src/groveemg/groveemg.hpp +++ b/src/emg/emg.hpp @@ -29,13 +29,13 @@ namespace upm { /** * @brief Grove EMG Muscle Signal Reader library - * @defgroup groveemg libupm-groveemg + * @defgroup emg libupm-emg * @ingroup seeed analog electric */ /** - * @library groveemg - * @sensor groveemg + * @library emg + * @sensor emg * @comname Grove EMG Sensor * @type electric * @man seeed @@ -46,21 +46,21 @@ namespace upm { * Grove EMG muscle signal reader gathers small muscle signals, * then processes them, and returns the result * - * @image html groveemg.jpg - * @snippet groveemg.cxx Interesting + * @image html emg.jpg + * @snippet emg.cxx Interesting */ - class GroveEMG { + class EMG { public: /** * Grove EMG reader constructor * * @param pin Analog pin to use */ - GroveEMG(int pin); + EMG(int pin); /** - * GroveEMG destructor + * EMG destructor */ - ~GroveEMG(); + ~EMG(); /** * Calibrates the Grove EMG reader diff --git a/src/emg/emg_fti.c b/src/emg/emg_fti.c new file mode 100644 index 00000000..c618f606 --- /dev/null +++ b/src/emg/emg_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 "emg.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_emg_name[] = "EMG"; +const char upm_emg_description[] = "Analog emg sensor"; +const upm_protocol_t upm_emg_protocol[] = {UPM_ANALOG}; +const upm_sensor_t upm_emg_category[] = {UPM_RAW}; + +// forward declarations +const void* upm_emg_get_ft(upm_sensor_t sensor_type); +void* upm_emg_init_str(const char* protocol, const char* params); +void upm_emg_close(void* dev); +const upm_sensor_descriptor_t upm_emg_get_descriptor(); +upm_result_t upm_emg_set_offset(const void* dev, float offset); +upm_result_t upm_emg_set_scale(const void* dev, float scale); +upm_result_t upm_emg_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_emg_init_str, + .upm_sensor_close = &upm_emg_close, + .upm_sensor_get_descriptor = &upm_emg_get_descriptor +}; + +/* 2. RAW function table */ +static const upm_raw_ft ft_raw = +{ + .upm_raw_set_offset = &upm_emg_set_offset, + .upm_raw_set_scale = &upm_emg_set_scale, + .upm_raw_get_value = &upm_emg_get_value +}; + +const void* upm_emg_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_emg_init_str(const char* protocol, const char* params) +{ + fprintf(stderr, "String initialization - not implemented, using ain0: %s\n", __FILENAME__); + return emg_init(0); +} + +void upm_emg_close(void* dev) +{ + emg_close((emg_context)dev); +} + +const upm_sensor_descriptor_t upm_emg_get_descriptor() +{ + /* Fill in the descriptor */ + upm_sensor_descriptor_t usd; + usd.name = upm_emg_name; + usd.description = upm_emg_description; + usd.protocol_size = 1; + usd.protocol = upm_emg_protocol; + usd.category_size = 1; + usd.category = upm_emg_category; + + return usd; +} + +upm_result_t upm_emg_set_offset(const void* dev, float offset) +{ + return emg_set_offset((emg_context)dev, offset); +} + +upm_result_t upm_emg_set_scale(const void* dev, float scale) +{ + return emg_set_scale((emg_context)dev, scale); +} + +upm_result_t upm_emg_get_value(const void* dev, float *value) +{ + return emg_get_volts((emg_context)dev, value); +} diff --git a/src/groveemg/javaupm_groveemg.i b/src/emg/javaupm_emg.i similarity index 66% rename from src/groveemg/javaupm_groveemg.i rename to src/emg/javaupm_emg.i index 9c66328b..da6f4e50 100644 --- a/src/groveemg/javaupm_groveemg.i +++ b/src/emg/javaupm_emg.i @@ -1,16 +1,16 @@ -%module javaupm_groveemg +%module javaupm_emg %include "../upm.i" %{ - #include "groveemg.hpp" + #include "emg.hpp" %} -%include "groveemg.hpp" +%include "emg.hpp" %pragma(java) jniclasscode=%{ static { try { - System.loadLibrary("javaupm_groveemg"); + System.loadLibrary("javaupm_emg"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load. \n" + e); System.exit(1); diff --git a/src/emg/jsupm_emg.i b/src/emg/jsupm_emg.i new file mode 100644 index 00000000..37ed79be --- /dev/null +++ b/src/emg/jsupm_emg.i @@ -0,0 +1,8 @@ +%module jsupm_emg +%include "../upm.i" + +%{ + #include "emg.hpp" +%} + +%include "emg.hpp" diff --git a/src/groveemg/pyupm_groveemg.i b/src/emg/pyupm_emg.i similarity index 62% rename from src/groveemg/pyupm_groveemg.i rename to src/emg/pyupm_emg.i index 09ce0c92..5c8f85a3 100644 --- a/src/groveemg/pyupm_groveemg.i +++ b/src/emg/pyupm_emg.i @@ -1,11 +1,11 @@ // Include doxygen-generated documentation %include "pyupm_doxy2swig.i" -%module pyupm_groveemg +%module pyupm_emg %include "../upm.i" %feature("autodoc", "3"); -%include "groveemg.hpp" +%include "emg.hpp" %{ - #include "groveemg.hpp" + #include "emg.hpp" %} diff --git a/src/groveemg/CMakeLists.txt b/src/groveemg/CMakeLists.txt deleted file mode 100644 index a65dec3d..00000000 --- a/src/groveemg/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -set (libname "groveemg") -set (libdescription "upm groveemg muscle signal reader sensor module") -set (module_src ${libname}.cxx) -set (module_hpp ${libname}.hpp) -upm_module_init() diff --git a/src/groveemg/jsupm_groveemg.i b/src/groveemg/jsupm_groveemg.i deleted file mode 100644 index 99041721..00000000 --- a/src/groveemg/jsupm_groveemg.i +++ /dev/null @@ -1,8 +0,0 @@ -%module jsupm_groveemg -%include "../upm.i" - -%{ - #include "groveemg.hpp" -%} - -%include "groveemg.hpp"