mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
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 <noel.eck@intel.com>
This commit is contained in:
parent
fe06de86b4
commit
a19678948b
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
@ -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)
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#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();
|
||||
|
@ -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)
|
||||
|
86
examples/c/emg.c
Normal file
86
examples/c/emg.c
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* 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 <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#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;
|
||||
}
|
@ -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)
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
});
|
@ -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 ##
|
8
src/emg/CMakeLists.txt
Normal file
8
src/emg/CMakeLists.txt
Normal file
@ -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)
|
127
src/emg/emg.c
Normal file
127
src/emg/emg.c
Normal file
@ -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 <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
@ -26,12 +26,12 @@
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#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;
|
133
src/emg/emg.h
Normal file
133
src/emg/emg.h
Normal file
@ -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
|
@ -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
|
119
src/emg/emg_fti.c
Normal file
119
src/emg/emg_fti.c
Normal file
@ -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 <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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);
|
||||
}
|
@ -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);
|
8
src/emg/jsupm_emg.i
Normal file
8
src/emg/jsupm_emg.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_emg
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "emg.hpp"
|
||||
%}
|
||||
|
||||
%include "emg.hpp"
|
@ -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"
|
||||
%}
|
@ -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()
|
@ -1,8 +0,0 @@
|
||||
%module jsupm_groveemg
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "groveemg.hpp"
|
||||
%}
|
||||
|
||||
%include "groveemg.hpp"
|
Loading…
x
Reference in New Issue
Block a user