From 7afd1f3fc18496dd77b3bc412ff51c83c98c7e56 Mon Sep 17 00:00:00 2001 From: Petre Eftime Date: Tue, 1 Sep 2015 18:56:04 +0300 Subject: [PATCH] java: fix return types and arrays for mpu60x0 and mpu9150 Signed-off-by: Petre Eftime Signed-off-by: Mihai Tudor Panu --- src/mpu9150/javaupm_mpu9150.i | 43 ++++++++++++++++++++++++++++------- src/mpu9150/mpu60x0.h | 17 ++++++++++++++ src/mpu9150/mpu9150.cxx | 9 ++++++++ src/mpu9150/mpu9150.h | 11 +++++++++ 4 files changed, 72 insertions(+), 8 deletions(-) diff --git a/src/mpu9150/javaupm_mpu9150.i b/src/mpu9150/javaupm_mpu9150.i index 1e9cb910..8fd838b4 100644 --- a/src/mpu9150/javaupm_mpu9150.i +++ b/src/mpu9150/javaupm_mpu9150.i @@ -9,18 +9,45 @@ %include "../IsrCallback.h" %apply int {mraa::Edge}; -%apply float *INOUT { float *x, float *y, float *z }; -%apply signed char[] {uint8_t *}; %{ #include "mpu60x0.h" -%} - -%include "mpu60x0.h" - - -%{ #include "mpu9150.h" %} + +%typemap(jni) float * "jfloatArray" +%typemap(jstype) float * "float[]" +%typemap(jtype) float * "float[]" + +%typemap(javaout) float * { + return $jnicall; +} + +%typemap(out) float * { + $result = JCALL1(NewFloatArray, jenv, 3); + JCALL4(SetFloatArrayRegion, jenv, $result, 0, 3, $1); + delete [] $1; +} + +%ignore getAccelerometer(float *, float *, float *); +%ignore getGyroscope(float *, float *, float *); +%ignore getMagnetometer(float *, float *, float *); + +%typemap(jni) (uint8_t *buf, int len) "jbyteArray"; +%typemap(jtype) (uint8_t *buf, int len) "byte[]"; +%typemap(jstype) (uint8_t *buf, int len) "byte[]"; + +%typemap(javain) (uint8_t *buf, int len) "$javainput"; + +%typemap(in) (uint8_t *buf, int len) { + $1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL); + $2 = JCALL1(GetArrayLength, jenv, $input); +} + +%typemap(freearg) (uint8_t *buf, int len) { + JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); +} + +%include "mpu60x0.h" %include "mpu9150.h" diff --git a/src/mpu9150/mpu60x0.h b/src/mpu9150/mpu60x0.h index 693de505..fd433a40 100644 --- a/src/mpu9150/mpu60x0.h +++ b/src/mpu9150/mpu60x0.h @@ -808,6 +808,23 @@ namespace upm { */ void getGyroscope(float *x, float *y, float *z); +#ifdef SWIGJAVA + /** + * get the accelerometer values + * + * @return Array containing X, Y, Z accelerometer values + */ + float *getAccelerometer(); + + /** + * get the gyroscope values + * + * @return Array containing X, Y, Z gyroscope values + */ + float *getGyroscope(); +#endif + + /** * get the temperature value * diff --git a/src/mpu9150/mpu9150.cxx b/src/mpu9150/mpu9150.cxx index 2023963a..e8961655 100644 --- a/src/mpu9150/mpu9150.cxx +++ b/src/mpu9150/mpu9150.cxx @@ -100,3 +100,12 @@ void MPU9150::getMagnetometer(float *x, float *y, float *z) if (z) *z = mz; } + +#ifdef SWIGJAVA +float *MPU9150::getMagnetometer() +{ + float *v = new float[3]; + getMagnetometer(&v[0], &v[1], &v[2]); + return v; +} +#endif diff --git a/src/mpu9150/mpu9150.h b/src/mpu9150/mpu9150.h index a9d1a1c4..6f341fb0 100644 --- a/src/mpu9150/mpu9150.h +++ b/src/mpu9150/mpu9150.h @@ -106,6 +106,17 @@ namespace upm { */ void getMagnetometer(float *x, float *y, float *z); +#ifdef SWIGJAVA + /** + * Return the compensated values for the x, y, and z axes. The + * unit of measurement is in micro-teslas (uT). + * + * @return Array containing X, Y, Z magnetometer values + */ + float *getMagnetometer(); +#endif + + protected: // magnetometer instance