diff --git a/src/lol/javaupm_lol.i b/src/lol/javaupm_lol.i index 2c95c17b..8764e6a7 100644 --- a/src/lol/javaupm_lol.i +++ b/src/lol/javaupm_lol.i @@ -1,5 +1,22 @@ %module javaupm_lol %include "../upm.i" +%include "stdint.i" +%include "arrays_java.i"; +%include "typemaps.i" + +%typemap(jni) unsigned char* "jbyteArray"; +%typemap(jtype) unsigned char* "byte[]"; +%typemap(jstype) unsigned char* "byte[]"; + +%typemap(javaout) unsigned char* { + return $jnicall; +} + +%typemap(out) unsigned char* { + $result = JCALL1(NewByteArray, jenv, LOL_X*LOL_Y); + JCALL4(SetByteArrayRegion, jenv, $result, 0, LOL_X*LOL_Y-1, reinterpret_cast($1)); + delete [] $1; +} %{ #include "lol.h" diff --git a/src/m24lr64e/javaupm_m24lr64e.i b/src/m24lr64e/javaupm_m24lr64e.i index 78142030..906c1abf 100644 --- a/src/m24lr64e/javaupm_m24lr64e.i +++ b/src/m24lr64e/javaupm_m24lr64e.i @@ -4,6 +4,21 @@ %include "arrays_java.i"; %include "../java_buffer.i" +%typemap(jni) uint8_t * "jbyteArray" +%typemap(jtype) uint8_t * "byte[]" +%typemap(jstype) uint8_t * "byte[]" + +%typemap(javaout) uint8_t * { + return $jnicall; +} + +%typemap(out) uint8_t *{ + int length = upm::M24LR64E::UID_LENGTH; + $result = JCALL1(NewByteArray, jenv, length); + JCALL4(SetByteArrayRegion, jenv, $result, 0, length, reinterpret_cast($1)); + delete [] $1; +} + %{ #include "m24lr64e.h" %} diff --git a/src/m24lr64e/m24lr64e.cxx b/src/m24lr64e/m24lr64e.cxx index 3fe9bcbd..d684aaaf 100644 --- a/src/m24lr64e/m24lr64e.cxx +++ b/src/m24lr64e/m24lr64e.cxx @@ -163,9 +163,12 @@ uint8_t M24LR64E::getAFI() return EEPROM_Read_Byte(AFI_ADDR); } -void M24LR64E::getUID(uint8_t* buffer) +uint8_t *M24LR64E::getUID() { + uint8_t* buffer = new uint8_t[UID_LENGTH]; EEPROM_Read_Bytes(UID_ADDR, buffer, UID_LENGTH); + + return buffer; } uint32_t M24LR64E::getMemorySize() diff --git a/src/m24lr64e/m24lr64e.h b/src/m24lr64e/m24lr64e.h index 053b6bff..ffdaf25b 100644 --- a/src/m24lr64e/m24lr64e.h +++ b/src/m24lr64e/m24lr64e.h @@ -215,10 +215,11 @@ namespace upm { /** * Returns a unique ID. * Must be in the root mode. + * Maintained to preserve compatibility with older code. * - * @param buf Buffer to hold the returned UID. Must be UID_LENGTH bytes. + * @result buf Buffer to hold the UID. Must be UID_LENGTH bytes. */ - void getUID(uint8_t* buffer); + uint8_t *getUID(); /** * Returns the memory size diff --git a/src/mma7455/mma7455.h b/src/mma7455/mma7455.h index e6982f38..e643decd 100644 --- a/src/mma7455/mma7455.h +++ b/src/mma7455/mma7455.h @@ -164,7 +164,7 @@ typedef union { * * @brief API for the MMA7455 Accelerometer * - * This file defines the MMA7455 interface for libmma7455 + * This module defines the MMA7455 interface for libmma7455 * * @image html mma7455.jpg * @snippet mma7455.cxx Interesting @@ -181,6 +181,8 @@ class MMA7455 { /** * Returns the name of the component + * + * @return Name of the component */ std::string name() { @@ -189,6 +191,8 @@ class MMA7455 { /** * Calibrates the sensor + * + * @return 0 (MRAA_SUCCESS) if successful; non-zero otherwise */ mraa::Result calibrate (); @@ -198,6 +202,8 @@ class MMA7455 { * @param ptrX X-axis * @param ptrY Y-axis * @param ptrZ Z-axis + * + * @return 0 (MRAA_SUCCESS) if successful; non-zero otherwise */ mraa::Result readData (short * ptrX, short * ptrY, short * ptrZ); @@ -209,28 +215,26 @@ class MMA7455 { */ short *readData (); #endif - /** - * + * Internal function for reading I2C data * * @param reg Register address * @param buffer Register data buffer - * @param size Buffer size + * @param len Buffer size */ int i2cReadReg (unsigned char reg, uint8_t *buffer, int len); /** - * + * Internal function for writing I2C data * * @param reg Register address * @param buffer Register data buffer - * @param size Buffer size + * @param len Buffer size */ mraa::Result i2cWriteReg (unsigned char reg, uint8_t *buffer, int len); private: std::string m_name; - int m_controlAddr; int m_bus; mraa::I2c m_i2ControlCtx; diff --git a/src/st7735/javaupm_st7735.i b/src/st7735/javaupm_st7735.i index 738a2a20..5dd5e4a9 100644 --- a/src/st7735/javaupm_st7735.i +++ b/src/st7735/javaupm_st7735.i @@ -1,5 +1,39 @@ %module javaupm_st7735 %include "../upm.i" +%include "arrays_java.i" +%include "typemaps.i" +%include "stdint.i" + +%ignore m_map; +%ignore Bcmd; +%ignore font; +%ignore Rcmd1; +%ignore Rcmd2green; +%ignore Rcmd2red; +%ignore Rcmd3; + + +/* +%typemap(jni) unsigned char[] "jbyteArray"; +%typemap(jtype) unsigned char[] "byte[]"; +%typemap(jstype) unsigned char[] "byte[]"; + +%typemap(out) unsigned char[] { + $result = SWIG_JavaArrayOutSchar(jenv, reinterpret_cast($1), sizeof($1)); +} +%typemap(freearg) unsigned char* { + JCALL3(ReleaseByteArrayElements, jenv, $input, reinterpret_cast($1), 0); +} +*/ +%typemap(jni) unsigned char* "jbyteArray"; +%typemap(jtype) unsigned char* "byte[]"; +%typemap(jstype) unsigned char* "byte[]"; + +%typemap(javain) unsigned char* "$javainput" + +%typemap(in) unsigned char* { + $1 = (unsigned char *)JCALL2(GetByteArrayElements, jenv, $input, NULL); +} %include "gfx.h" %{