mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
gsr: Added gsr sensor C source
Added the C source for the gsr sensor with necessary changes to cmake, examples, docs. * Renamed all files with grovegsr to gsr * Replaced all instances of grovegsr with gsr * Added C source for gsr sensor * Updated all cmake files * Added C example for gsr sensor * Fixed C++ threshold method from throwing on a successfull aio read Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
parent
a19678948b
commit
0e52ea619b
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@ -171,7 +171,7 @@ add_example (grovecollision)
|
|||||||
add_example (groveelectromagnet)
|
add_example (groveelectromagnet)
|
||||||
add_example (emg)
|
add_example (emg)
|
||||||
add_example (o2)
|
add_example (o2)
|
||||||
add_example (grovegsr)
|
add_example (gsr)
|
||||||
add_example (ina132)
|
add_example (ina132)
|
||||||
add_example (l298)
|
add_example (l298)
|
||||||
add_example (l298-stepper)
|
add_example (l298-stepper)
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include "grovegsr.hpp"
|
#include "gsr.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -42,10 +42,10 @@ int main()
|
|||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [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
|
// Instantiate a GSR on analog pin A0
|
||||||
upm::GroveGSR *gsr = new upm::GroveGSR(0);
|
upm::GSR *gsr = new upm::GSR(0);
|
||||||
cout << "Calibrating...." << endl;
|
cout << "Calibrating...." << endl;
|
||||||
gsr->calibrate();
|
gsr->calibrate();
|
||||||
|
|
@ -98,6 +98,7 @@ add_example (vdiv)
|
|||||||
add_example (mqx)
|
add_example (mqx)
|
||||||
add_example (o2)
|
add_example (o2)
|
||||||
add_example (emg)
|
add_example (emg)
|
||||||
|
add_example (gsr)
|
||||||
|
|
||||||
# Custom examples
|
# Custom examples
|
||||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||||
|
86
examples/c/gsr.c
Normal file
86
examples/c/gsr.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 "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;
|
||||||
|
}
|
@ -35,7 +35,7 @@ add_example(GroveButton_intrSample grove)
|
|||||||
add_example(GroveCollision grovecollision)
|
add_example(GroveCollision grovecollision)
|
||||||
add_example(GroveEHRSample groveehr)
|
add_example(GroveEHRSample groveehr)
|
||||||
add_example(Emg emg)
|
add_example(Emg emg)
|
||||||
add_example(GroveGsr grovegsr)
|
add_example(Gsr gsr)
|
||||||
add_example(GroveLed_multiSample grove)
|
add_example(GroveLed_multiSample grove)
|
||||||
add_example(GroveLEDSample grove)
|
add_example(GroveLEDSample grove)
|
||||||
add_example(GroveLightSample grove)
|
add_example(GroveLightSample grove)
|
||||||
|
@ -22,16 +22,16 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* 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) {
|
public static void main(String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a Grove GSR sensor on analog pin A0
|
// Instantiate a Grove GSR sensor on analog pin A0
|
||||||
GroveGSR gsr = new GroveGSR(0);
|
GSR gsr = new GSR(0);
|
||||||
System.out.println("Calibrating...");
|
System.out.println("Calibrating...");
|
||||||
gsr.calibrate();
|
gsr.calibrate();
|
||||||
|
|
@ -22,18 +22,18 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* 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
|
// Instantiate a GSR on analog pin A0
|
||||||
var grovegsr_obj = new grovegsr_lib.GroveGSR(0);
|
var gsr_obj = new gsr_lib.GSR(0);
|
||||||
console.log("Calibrating....");
|
console.log("Calibrating....");
|
||||||
grovegsr_obj.calibrate();
|
gsr_obj.calibrate();
|
||||||
|
|
||||||
var myInterval = setInterval(function()
|
var myInterval = setInterval(function()
|
||||||
{
|
{
|
||||||
console.log(grovegsr_obj.value());
|
console.log(gsr_obj.value());
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
|
||||||
@ -41,9 +41,9 @@ var myInterval = setInterval(function()
|
|||||||
process.on('SIGINT', function()
|
process.on('SIGINT', function()
|
||||||
{
|
{
|
||||||
clearInterval(myInterval);
|
clearInterval(myInterval);
|
||||||
grovegsr_obj = null;
|
gsr_obj = null;
|
||||||
grovegsr_lib.cleanUp();
|
gsr_lib.cleanUp();
|
||||||
grovegsr_lib = null;
|
gsr_lib = null;
|
||||||
console.log("Exiting...");
|
console.log("Exiting...");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
@ -22,12 +22,12 @@
|
|||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
import time, sys, signal, atexit
|
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
|
# Instantiate a GSR on analog pin A0
|
||||||
myGSR = upmGrovegsr.GroveGSR(0)
|
myGSR = upmGsr.GSR(0)
|
||||||
|
|
||||||
|
|
||||||
## Exit handlers ##
|
## Exit handlers ##
|
@ -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()
|
|
@ -1,8 +0,0 @@
|
|||||||
%module jsupm_grovegsr
|
|
||||||
%include "../upm.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "grovegsr.hpp"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "grovegsr.hpp"
|
|
8
src/gsr/CMakeLists.txt
Normal file
8
src/gsr/CMakeLists.txt
Normal file
@ -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)
|
127
src/gsr/gsr.c
Normal file
127
src/gsr/gsr.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 "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;
|
||||||
|
}
|
@ -26,45 +26,42 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "grovegsr.hpp"
|
#include "gsr.hpp"
|
||||||
|
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
GroveGSR::GroveGSR(int pin)
|
GSR::GSR(int pin)
|
||||||
{
|
{
|
||||||
if ( !(m_aio = mraa_aio_init(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__) +
|
val = mraa_aio_read(m_aio);
|
||||||
": mraa_aio_init() failed, invalid pin?");
|
if (val < 0)
|
||||||
return;
|
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);
|
int val = mraa_aio_read(m_aio);
|
||||||
}
|
return val;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
133
src/gsr/gsr.h
Normal file
133
src/gsr/gsr.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 _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
|
@ -29,13 +29,13 @@
|
|||||||
namespace upm {
|
namespace upm {
|
||||||
/**
|
/**
|
||||||
* @brief Grove GSR Galvanic Skin Response Sensor library
|
* @brief Grove GSR Galvanic Skin Response Sensor library
|
||||||
* @defgroup grovegsr libupm-grovegsr
|
* @defgroup gsr libupm-gsr
|
||||||
* @ingroup seeed analog electric
|
* @ingroup seeed analog electric
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @library grovegsr
|
* @library gsr
|
||||||
* @sensor grovegsr
|
* @sensor gsr
|
||||||
* @comname Grove GSR Sensor
|
* @comname Grove GSR Sensor
|
||||||
* @type electric
|
* @type electric
|
||||||
* @man seeed
|
* @man seeed
|
||||||
@ -48,21 +48,21 @@ namespace upm {
|
|||||||
* In other words, it measures sweat on your fingers
|
* In other words, it measures sweat on your fingers
|
||||||
* as an indicator of strong emotional reactions.
|
* as an indicator of strong emotional reactions.
|
||||||
*
|
*
|
||||||
* @image html grovegsr.jpg
|
* @image html gsr.jpg
|
||||||
* @snippet grovegsr.cxx Interesting
|
* @snippet gsr.cxx Interesting
|
||||||
*/
|
*/
|
||||||
class GroveGSR {
|
class GSR {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Grove GSR sensor constructor
|
* Grove GSR sensor constructor
|
||||||
*
|
*
|
||||||
* @param pin Analog pin to use
|
* @param pin Analog pin to use
|
||||||
*/
|
*/
|
||||||
GroveGSR(int pin);
|
GSR(int pin);
|
||||||
/**
|
/**
|
||||||
* GroveGSR destructor
|
* GSR destructor
|
||||||
*/
|
*/
|
||||||
~GroveGSR();
|
~GSR();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calibrates the Grove GSR sensor
|
* Calibrates the Grove GSR sensor
|
119
src/gsr/gsr_fti.c
Normal file
119
src/gsr/gsr_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 "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);
|
||||||
|
}
|
@ -1,16 +1,16 @@
|
|||||||
%module javaupm_grovegsr
|
%module javaupm_gsr
|
||||||
%include "../upm.i"
|
%include "../upm.i"
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include "grovegsr.hpp"
|
#include "gsr.hpp"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%include "grovegsr.hpp"
|
%include "gsr.hpp"
|
||||||
|
|
||||||
%pragma(java) jniclasscode=%{
|
%pragma(java) jniclasscode=%{
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
System.loadLibrary("javaupm_grovegsr");
|
System.loadLibrary("javaupm_gsr");
|
||||||
} catch (UnsatisfiedLinkError e) {
|
} catch (UnsatisfiedLinkError e) {
|
||||||
System.err.println("Native code library failed to load. \n" + e);
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
System.exit(1);
|
System.exit(1);
|
8
src/gsr/jsupm_gsr.i
Normal file
8
src/gsr/jsupm_gsr.i
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
%module jsupm_gsr
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "gsr.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "gsr.hpp"
|
@ -1,11 +1,11 @@
|
|||||||
// Include doxygen-generated documentation
|
// Include doxygen-generated documentation
|
||||||
%include "pyupm_doxy2swig.i"
|
%include "pyupm_doxy2swig.i"
|
||||||
%module pyupm_grovegsr
|
%module pyupm_gsr
|
||||||
%include "../upm.i"
|
%include "../upm.i"
|
||||||
|
|
||||||
%feature("autodoc", "3");
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
%include "grovegsr.hpp"
|
%include "gsr.hpp"
|
||||||
%{
|
%{
|
||||||
#include "grovegsr.hpp"
|
#include "gsr.hpp"
|
||||||
%}
|
%}
|
Loading…
x
Reference in New Issue
Block a user