diff --git a/src/mma7660/javaupm_mma7660.i b/src/mma7660/javaupm_mma7660.i index 5a7779a9..a20902df 100644 --- a/src/mma7660/javaupm_mma7660.i +++ b/src/mma7660/javaupm_mma7660.i @@ -15,4 +15,34 @@ #include "mma7660.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); +} + + +%typemap(jni) int* "jintArray" +%typemap(jstype) int* "int[]" +%typemap(jtype) int* "int[]" + +%typemap(javaout) int* { + return $jnicall; +} + +%typemap(out) int *getRawValues { + $result = JCALL1(NewIntArray, jenv, 3); + JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const signed int*)$1); +} + +%ignore getRawValues(int *, int *, int *); +%ignore getAcceleration(float *, float *, float *); + %include "mma7660.h" diff --git a/src/mma7660/mma7660.cxx b/src/mma7660/mma7660.cxx index 45aa0248..cf7801a3 100644 --- a/src/mma7660/mma7660.cxx +++ b/src/mma7660/mma7660.cxx @@ -88,6 +88,15 @@ void MMA7660::getRawValues(int *x, int *y, int *z) *z = getVerifiedAxis(REG_ZOUT); } +#ifdef SWIGJAVA +int *MMA7660::getRawValues() +{ + int *values = new int[3]; + getRawValues(&values[0], &values[1], &values[2]); + return values; +} +#endif + void MMA7660::setModeActive() { uint8_t modeReg = readByte(REG_MODE); @@ -254,3 +263,12 @@ void MMA7660::getAcceleration(float *ax, float *ay, float *az) *az = z/21.33; } +#ifdef SWIGJAVA +float *MMA7660::getAcceleration() +{ + float *values = new float[3]; + getAcceleration(&values[0], &values[1], &values[2]); + return values; +} +#endif + diff --git a/src/mma7660/mma7660.h b/src/mma7660/mma7660.h index c9ec4683..1ca4e4e2 100644 --- a/src/mma7660/mma7660.h +++ b/src/mma7660/mma7660.h @@ -169,6 +169,15 @@ namespace upm { */ void getRawValues(int *x, int *y, int *z); +#ifdef SWIGJAVA + /** + * Reads the current value of conversion + * + * @return Array containing x, y, z. Free using delete. + */ + int *getRawValues(); +#endif + /** * Gets the computed acceleration * @@ -178,6 +187,15 @@ namespace upm { */ void getAcceleration(float *ax, float *ay, float *az); +#ifdef SWIGJAVA + /** + * Gets the computed acceleration + * + * @return Array containing x, y, z. Free using delete. + */ + float *getAcceleration(); +#endif + /** * Reads an axis, verifying its validity. The value passed must * be one of REG_XOUT, REG_YOUT, or REG_ZOUT.