option (BUILDSWIG "Build swig modules." ON)
option (BUILDSWIGPYTHON "Build swig python modules." ON)
option (BUILDSWIGNODE "Build swig node modules." ON)
+option (BUILDSWIGJAVA "Build Java API." OFF)
option (IPK "Generate IPK using CPack" OFF)
option (BUILDPYTHON3 "Use python3 for building/installing" OFF)
option (INSTALLGPIOTOOL "Install gpio tool" OFF)
EDGE_FALLING = 3 /**< Interupt on falling only */
} Edge;
+#if defined(SWIGJAVA)
+
+class IsrCallback
+{
+ public:
+ virtual ~IsrCallback()
+ {
+ }
+ virtual void
+ run()
+ { /* empty, overloaded in Java*/
+ }
+
+ private:
+};
+
+void
+generic_isr_callback(void* data)
+{
+ IsrCallback* callback = (IsrCallback*) data;
+ callback->run();
+}
+#endif
+
/**
* @brief API to General Purpose IO
*
#endif
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, &uvwork, this);
}
+#elif defined(SWIGJAVA)
+ mraa_result_t
+ isr(Edge mode, IsrCallback* cb, void* args)
+ {
+ return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, generic_isr_callback, cb);
+ }
#else
/**
* Sets a callback to be called when pin value changes
cov-build --dir cov-int make
tar caf mraa.tar.bz2 cov-int
~~~~~~~~~~~~~
+
+## Building Java bindings
+Have JAVA_HOME set to JDK install directory. Then use the cmake configuration flag:
+ -DBUILDSWIGJAVA=ON
+To compile Example.java
+~~~~~~~~~~~~~{.sh}
+javac -cp $DIR_WHERE_YOU_INSTALLED_MRAA/mraa.jar:. Example.java
+~~~~~~~~~~~~~
+To run, make sure libmraajava.so is in LD_LIBRARY_PATH
+ ~~~~~~~~~~~~~{.sh}
+jave -cp $DIR_WHERE_YOU_INSTALLED_MRAA/mraa.jar:. Example
+~~~~~~~~~~~~~
--- /dev/null
+/*
+ * Author: Alexander Komarov <alexander.komarov@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+public class bmp85 {
+ static {
+ try {
+ System.loadLibrary("mraajava");
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println(
+ "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
+ e);
+ System.exit(1);
+ }
+ }
+ public static void main(String argv[]) {
+ mraa.mraa.init();
+ System.out.println(mraa.mraa.getVersion());
+
+ // helper function to go from hex val to dec
+ // function char(x) { return parseInt(x, 16); }
+
+ mraa.I2c i2c = new mraa.I2c(0);
+ i2c.address((byte)0x77);
+ i2c.writeByte((byte)0xd0);
+ /*
+ SWIGTYPE_p_unsigned_char data0 = new SWIGTYPE_p_unsigned_char();*/
+ byte[] data = new byte[1];
+ i2c.read(data);
+ System.out.println((new Integer(data[0])).toString());
+
+ i2c.writeReg((byte)0xf4, (byte)0x2e);
+ // initialise device
+ if (i2c.readReg((byte)0xd0) != 0x55) {
+ System.out.println("error");
+ }
+
+ // we want to read temperature so write 0x2e into control reg
+ i2c.writeReg((byte)0xf4, (byte)0x2e);
+
+ // read a 16bit reg, obviously it's uncalibrated so mostly a useless value
+ // :)
+ System.out.println(i2c.readWordReg((byte)0xf6));
+
+ byte[] buf = new byte[2];
+ buf[0] = (byte)0xf4;
+ buf[1] = (byte)0x2e;
+ i2c.write(buf);
+
+ i2c.writeByte((byte)0xf6);
+ int d = i2c.readReg((byte)2);
+ System.out.println((new Integer(d)).toString());
+ };
+}
+;
--- /dev/null
+/*
+ * Author: Alexander Komarov <alexander.komarov@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+public class Example {
+ static {
+ try {
+ System.loadLibrary("mraajava");
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println(
+ "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
+ e);
+ System.exit(1);
+ }
+ }
+ public static void main(String argv[]) {
+ mraa.mraa.init();
+ System.out.println(mraa.mraa.getVersion());
+ };
+}
+;
--- /dev/null
+/*
+ * Author: Alexander Komarov <alexander.komarov@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+public class Isr {
+ static {
+ try {
+ System.loadLibrary("mraajava");
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println(
+ "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
+ e);
+ System.exit(1);
+ }
+ }
+ public static void main(String argv[]) {
+ mraa.mraa.init();
+
+ mraa.Gpio gpio = new mraa.Gpio(7);
+
+ mraa.IsrCallback callback = new JavaCallback();
+
+ gpio.isr(mraa.Edge.EDGE_RISING, callback, null);
+ while (true)
+ ;
+ };
+}
+;
+
+class JavaCallback extends mraa.IsrCallback {
+ public JavaCallback() { super(); }
+
+ public void run() { System.out.println("JavaCallback.run()"); }
+}
if (BUILDSWIGPYTHON)
add_subdirectory (python)
endif ()
+ if (BUILDSWIGJAVA)
+ add_subdirectory (java)
+ endif ()
if (BUILDSWIGNODE)
if (SWIG_VERSION VERSION_GREATER 3.0.4)
add_subdirectory (javascript)
--- /dev/null
+FIND_PACKAGE (JNI REQUIRED)
+
+include_directories (
+ ${JAVA_INCLUDE_PATH}
+ ${JAVA_INCLUDE_PATH2}
+ ${CMAKE_CURRENT_SOURCE_DIR}/..
+)
+
+# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is required
+set_source_files_properties (mraajava.i PROPERTIES SWIG_FLAGS ";-package;mraa;-I${CMAKE_BINARY_DIR}/src")
+set_source_files_properties (mraajava.i PROPERTIES CPLUSPLUS ON)
+
+set (CMAKE_CXX_FLAGS "-fpermissive")
+
+set (JAVAC $ENV{JAVA_HOME}/bin/javac)
+set (JAR $ENV{JAVA_HOME}/bin/jar)
+
+swig_add_module (mraajava java mraajava.i ${mraa_LIB_SRCS})
+swig_link_libraries (mraajava ${JAVA_LIBRARIES})
+
+add_custom_command (TARGET mraajava
+ POST_BUILD
+ COMMAND cmake -E echo "Compiling java.."
+ COMMAND cmake -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/mraa
+ COMMAND ${JAVAC} *.java -d ${CMAKE_CURRENT_BINARY_DIR}
+ COMMAND cmake -E echo "Creating jar"
+ COMMAND ${JAR} cvf mraa.jar mraa
+)
+
+if (DOXYGEN_FOUND)
+ foreach (_file ${DOCFILES})
+ add_dependencies (${SWIG_MODULE_mraajava_REAL_NAME} ${_file}doc_i)
+ endforeach ()
+endif ()
+
+install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.jar
+ ${CMAKE_CURRENT_BINARY_DIR}/libmraajava.so
+ DESTINATION lib
+)
--- /dev/null
+%module (directors="1",docstring="Java interface to libmraa") mraa
+
+%feature("autodoc", "3");
+
+%typemap(jtype) (uint8_t *txBuf, int length) "byte[]"
+%typemap(jstype) (uint8_t *txBuf, int length) "byte[]"
+%typemap(jni) (uint8_t *txBuf, int length) "jbyteArray"
+%typemap(javain) (uint8_t *txBuf, int length) "$javainput"
+
+%typemap(in,numinputs=1) (uint8_t *txBuf, int length) {
+ $1 = JCALL2(GetByteArrayElements, jenv, $input, NULL);
+ $2 = JCALL1(GetArrayLength, jenv, $input);
+}
+
+%typemap(jtype) (uint8_t *data, int length) "byte[]"
+%typemap(jstype) (uint8_t *data, int length) "byte[]"
+%typemap(jni) (uint8_t *data, int length) "jbyteArray"
+%typemap(javain) (uint8_t *data, int length) "$javainput"
+
+%typemap(in,numinputs=1) (uint8_t *data, int length) {
+ $1 = JCALL2(GetByteArrayElements, jenv, $input, NULL);
+ $2 = JCALL1(GetArrayLength, jenv, $input);
+}
+
+%typemap(argout) (uint8_t *data, int length) {
+ JCALL3(ReleaseByteArrayElements, jenv, $input, $1, JNI_COMMIT);
+}
+
+%typemap(jtype) (const uint8_t *data, int length) "byte[]"
+%typemap(jstype) (const uint8_t *data, int length) "byte[]"
+%typemap(jni) (const uint8_t *data, int length) "jbyteArray"
+%typemap(javain) (const uint8_t *data, int length) "$javainput"
+%typemap(in) (const uint8_t *data, int length) {
+ $1 = JCALL2(GetByteArrayElements, jenv, $input, NULL);
+ $2 = JCALL1(GetArrayLength, jenv, $input);
+}
+
+%feature("director") IsrCallback;
+%include ../mraa.i
}
%include ../mraa.i
+
+%init %{
+ //Adding mraa_init() to the module initialisation process
+ mraa_init();
+%}
#include "uart.hpp"
%}
-%init %{
- //Adding mraa_init() to the module initialisation process
- mraa_init();
-%}
-
%exception {
try {
$action
%include ../mraa.i
+%init %{
+ //Adding mraa_init() to the module initialisation process
+ mraa_init();
+%}