From 9cfd1a967948b006f13e62d7277c8f3072ac2162 Mon Sep 17 00:00:00 2001 From: Petre Eftime Date: Fri, 28 Aug 2015 18:12:02 +0300 Subject: [PATCH] java: fix Java return types in h3lis331dl Signed-off-by: Petre Eftime Signed-off-by: Mihai Tudor Panu --- src/h3lis331dl/h3lis331dl.cxx | 23 ++++++++++++++++++ src/h3lis331dl/h3lis331dl.h | 24 +++++++++++++++++++ src/h3lis331dl/javaupm_h3lis331dl.i | 36 +++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/src/h3lis331dl/h3lis331dl.cxx b/src/h3lis331dl/h3lis331dl.cxx index 457c5d56..d8f657f6 100644 --- a/src/h3lis331dl/h3lis331dl.cxx +++ b/src/h3lis331dl/h3lis331dl.cxx @@ -567,3 +567,26 @@ void H3LIS331DL::getXYZ(int *x, int *y, int*z) *y = (m_rawY - m_adjY); *z = (m_rawZ - m_adjZ); } + +#ifdef SWIGJAVA +float *H3LIS331DL::getAcceleration() +{ + float *v = new float[3]; + getAcceleration(&v[0], &v[1], &v[2]); + return v; +} + +int *H3LIS331DL::getRawXYZ() +{ + int *v = new int[3]; + getRawXYZ(&v[0], &v[1], &v[2]); + return v; +} + +int *H3LIS331DL::getXYZ() +{ + int *v = new int[3]; + getXYZ(&v[0], &v[1], &v[2]); + return v; +} +#endif diff --git a/src/h3lis331dl/h3lis331dl.h b/src/h3lis331dl/h3lis331dl.h index 0dcbb126..d52a57d6 100644 --- a/src/h3lis331dl/h3lis331dl.h +++ b/src/h3lis331dl/h3lis331dl.h @@ -593,6 +593,30 @@ namespace upm { */ void getXYZ(int *x, int *y, int *z); +#ifdef SWIGJAVA + /** + * Gets acceleration values for each of the axes + * + * @return Array containing X, Y, Z acceleration values + */ + float *getAcceleration(); + + /** + * Gets raw axis values + * + * @return Array containing X, Y, Z raw values + */ + int *getRawXYZ(); + + /** + * Gets adjusted axis values + * + * @return Array containing X, Y, Z adjusted axis values + */ + int *getXYZ(); +#endif + + /** * Provides public access to the MRAA I2C context of the class for * direct user access diff --git a/src/h3lis331dl/javaupm_h3lis331dl.i b/src/h3lis331dl/javaupm_h3lis331dl.i index cd766fab..7dfad790 100644 --- a/src/h3lis331dl/javaupm_h3lis331dl.i +++ b/src/h3lis331dl/javaupm_h3lis331dl.i @@ -12,4 +12,40 @@ #include "h3lis331dl.h" %} +%typemap(jni) float* "jfloatArray" +%typemap(jstype) float* "float[]" +%typemap(jtype) float* "float[]" + +%typemap(javaout) float* { + return $jnicall; +} + +%typemap(out) float *getAcceleration { + $result = JCALL1(NewFloatArray, jenv, 3); + JCALL4(SetFloatArrayRegion, jenv, $result, 0, 3, $1); + delete [] $1; +} + +%typemap(jni) int* "jintArray" +%typemap(jstype) int* "int[]" +%typemap(jtype) int* "int[]" + +%typemap(javaout) int* { + return $jnicall; +} + +%typemap(out) int *getRawXYZ { + $result = JCALL1(NewIntArray, jenv, 3); + JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const int*)$1); +} + +%typemap(out) int *getXYZ { + $result = JCALL1(NewIntArray, jenv, 3); + JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const int*)$1); +} + +%ignore getRawXYZ(int *, int *, int *); +%ignore getXYZ(int *, int *, int *); +%ignore getAcceleration(float *, float *, float *); + %include "h3lis331dl.h"