From 42c59e98ab836c188c5a3f44c13bba8e0fe02557 Mon Sep 17 00:00:00 2001 From: Petre Eftime Date: Thu, 27 Aug 2015 13:11:22 +0300 Subject: [PATCH] java: fix Java return types in lsm9ds0 Signed-off-by: Petre Eftime Signed-off-by: Mihai Tudor Panu --- src/lsm9ds0/javaupm_lsm9ds0.i | 28 ++++++++++++++++++++++++++++ src/lsm9ds0/lsm9ds0.cxx | 23 +++++++++++++++++++++++ src/lsm9ds0/lsm9ds0.h | 23 +++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/src/lsm9ds0/javaupm_lsm9ds0.i b/src/lsm9ds0/javaupm_lsm9ds0.i index ff1312ff..67b65526 100644 --- a/src/lsm9ds0/javaupm_lsm9ds0.i +++ b/src/lsm9ds0/javaupm_lsm9ds0.i @@ -16,4 +16,32 @@ %{ #include "lsm9ds0.h" %} + +%typemap(jni) float* "jfloatArray" +%typemap(jstype) float* "float[]" +%typemap(jtype) float* "float[]" + +%typemap(javaout) float* { + return $jnicall; +} + +%typemap(out) float *getAccelerometer { + $result = JCALL1(NewFloatArray, jenv, 3); + JCALL4(SetFloatArrayRegion, jenv, $result, 0, 3, $1); +} + +%typemap(out) float *getGyroscope { + $result = JCALL1(NewFloatArray, jenv, 3); + JCALL4(SetFloatArrayRegion, jenv, $result, 0, 3, $1); +} + +%typemap(out) float *getMagnetometer { + $result = JCALL1(NewFloatArray, jenv, 3); + JCALL4(SetFloatArrayRegion, jenv, $result, 0, 3, $1); +} + +%ignore getAccelerometer(float *, float *, float *); +%ignore getGyroscope(float *, float *, float *); +%ignore getMagnetometer(float *, float *, float *); + %include "lsm9ds0.h" diff --git a/src/lsm9ds0/lsm9ds0.cxx b/src/lsm9ds0/lsm9ds0.cxx index 3a475715..b945e1eb 100644 --- a/src/lsm9ds0/lsm9ds0.cxx +++ b/src/lsm9ds0/lsm9ds0.cxx @@ -602,6 +602,29 @@ void LSM9DS0::getMagnetometer(float *x, float *y, float *z) *z = (m_magZ * m_magScale) / 1000.0; } +#ifdef SWIGJAVA +float *LSM9DS0::getAccelerometer() +{ + float *v = new float[3]; + getAccelerometer(&v[0], &v[1], &v[2]); + return v; +} + +float *LSM9DS0::getGyroscope() +{ + float *v = new float[3]; + getGyroscope(&v[0], &v[1], &v[2]); + return v; +} + +float *LSM9DS0::getMagnetometer() +{ + float *v = new float[3]; + getMagnetometer(&v[0], &v[1], &v[2]); + return v; +} +#endif + float LSM9DS0::getTemperature() { // This might be wrong... The datasheet does not provide enough info diff --git a/src/lsm9ds0/lsm9ds0.h b/src/lsm9ds0/lsm9ds0.h index bcbd6823..e9d96fb7 100644 --- a/src/lsm9ds0/lsm9ds0.h +++ b/src/lsm9ds0/lsm9ds0.h @@ -1267,6 +1267,29 @@ namespace upm { */ void getMagnetometer(float *x, float *y, float *z); +#ifdef SWIGJAVA + /** + * get the accelerometer values in gravities + * + * @return Array containing X, Y, Z acceleration values + */ + float *getAccelerometer(); + + /** + * get the gyroscope values in degrees per second + * + * @return Array containing X, Y, Z gyroscope values + */ + float *getGyroscope(); + + /** + * get the magnetometer values in gauss + * + * @return Array containing X, Y, Z magnetometer values + */ + float *getMagnetometer(); +#endif + /** * get the temperature value. Unfortunately the datasheet does * not provide a mechanism to convert the temperature value into