diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eb6f6a6b..00fd93c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -437,16 +437,10 @@ function(upm_swig_java) set_source_files_properties (javaupm_${libname}.i PROPERTIES CPLUSPLUS ON) set_source_files_properties (javaupm_${libname}.i PROPERTIES SWIG_FLAGS ";-package;upm_${libname};-I${CMAKE_BINARY_DIR}/src") - # NOTE, ${module_src} is ONLY needed when swig'ing to JAVA. This is - # because *some* upm libraries have ifdef's for JAVA and SWIG in their - # source (cxx) which builds in different functionality. Because of this, - # the source must be added when building the JAVA wrapper. - # See issue #518 - # TODO: Fix this somehow if (CMAKE_VERSION VERSION_LESS "3.8") - swig_add_module (javaupm_${libname} java javaupm_${libname}.i ${module_src}) + swig_add_module (javaupm_${libname} java javaupm_${libname}.i) else () - swig_add_library (javaupm_${libname} LANGUAGE java SOURCES javaupm_${libname}.i ${module_src}) + swig_add_library (javaupm_${libname} LANGUAGE java SOURCES javaupm_${libname}.i) endif () # If the C++ target depends on C++ interfaces, make the JAVA target diff --git a/src/_upm.i b/src/_upm.i new file mode 100644 index 00000000..7686e018 --- /dev/null +++ b/src/_upm.i @@ -0,0 +1,77 @@ +/* Macro for adding JAVA run + usage: JAVA_ADD_INSTALLISR(javaupm_a110x) +*/ +%define JAVA_ADD_INSTALLISR(UPM_Classname) +%extend UPM_Classname { + void installISR(jobject runnable) + { + $self->installISR(mraa_java_isr_callback, runnable); + } +} +%enddef + +/* Define GETTER in the appropiate .i file with the getter function name +*/ +%define JAVA_ADD_INSTALLISR_GPIO(UPM_Classname) +%extend UPM_Classname { + void installISR(int gpio, mraa::Edge level, jobject runnable) + { + // delete any existing ISR and GPIO context + $self->uninstallISR(); + + // create gpio context + mraa::Gpio* swg_gpioIntr = $self->GETTER; + + swg_gpioIntr->dir(mraa::DIR_IN); + swg_gpioIntr->isr(level, runnable); + + } +} +%enddef + +/* Define INTERRUPT in the appropiate .i file with the interrupt type +*/ +%define JAVA_ADD_INSTALLISR_INTERRUPT(UPM_Classname) +%extend UPM_Classname { + void installISR(INTERRUPT intr, int gpio, + mraa::Edge level, jobject runnable) + { + $self->installISR(intr, gpio, level, mraa_java_isr_callback, runnable); + } +} +%enddef + +%define JAVA_ADD_INSTALLISR_EDGE(UPM_Classname) +%extend UPM_Classname { + void installISR(mraa::Edge level, jobject runnable) + { + $self->installISR(level, mraa_java_isr_callback, runnable); + } +} +%enddef + +%define JAVA_ADD_INSTALLISR_PIN(UPM_Classname) +%extend UPM_Classname { + void installISR(int pin, jobject runnable) + { + $self->installISR(pin, mraa_java_isr_callback, runnable); + } + +} +%enddef + +/* Macro for adding JNI loadLibrary dependency + usage: JAVA_JNI_LOADLIBRARY(javaupm_rhusb) +*/ +%define JAVA_JNI_LOADLIBRARY(MyModuleName) +%pragma(java) jniclasscode=%{ +static { + try { + System.loadLibrary("MyModuleName"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library (MyModuleName) failed to load. \n" + e); + System.exit(1); + } +} +%} +%enddef diff --git a/src/a110x/a110x.cxx b/src/a110x/a110x.cxx index f6058654..b0b063f5 100644 --- a/src/a110x/a110x.cxx +++ b/src/a110x/a110x.cxx @@ -57,13 +57,6 @@ bool A110X::magnetDetected() return (!mraa_gpio_read(m_gpio) ? true : false); } -#ifdef JAVACALLBACK -void A110X::installISR(jobject runnable) -{ -installISR(mraa_java_isr_callback, runnable); -} -#endif - void A110X::installISR(void (*isr)(void *), void *arg) { if (m_isrInstalled) diff --git a/src/a110x/a110x.hpp b/src/a110x/a110x.hpp index de2147dd..fb5ca86a 100644 --- a/src/a110x/a110x.hpp +++ b/src/a110x/a110x.hpp @@ -85,11 +85,8 @@ namespace upm { * @param arg Pointer to an object to be supplied as an * argument to the ISR. */ -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(jobject runnable); -#else void installISR(void (*isr)(void *), void *arg); -#endif + /** * Uninstalls the previously installed ISR * @@ -97,9 +94,6 @@ namespace upm { void uninstallISR(); private: -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(void (*isr)(void *), void *arg); -#endif bool m_isrInstalled; mraa_gpio_context m_gpio; diff --git a/src/a110x/common.i b/src/a110x/common.i new file mode 100644 index 00000000..0c8257a3 --- /dev/null +++ b/src/a110x/common.i @@ -0,0 +1,6 @@ +%include "../upm.i" + +%{ +#include "a110x.hpp" +%} +%include "a110x.hpp" diff --git a/src/a110x/javaupm_a110x.i b/src/a110x/javaupm_a110x.i index 4e558725..7443506e 100644 --- a/src/a110x/javaupm_a110x.i +++ b/src/a110x/javaupm_a110x.i @@ -1,20 +1,11 @@ %module javaupm_a110x -%include "../upm.i" %include "stdint.i" %include "typemaps.i" -%{ - #include "a110x.hpp" -%} -%include "a110x.hpp" +%include "common.i" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_a110x"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +/* Macro for loading javaupm_a110x */ +JAVA_JNI_LOADLIBRARY(javaupm_a110x) + +/* Macro adding an installisr call w/JAVA runnable to A110X */ +JAVA_ADD_INSTALLISR(upm::A110X) diff --git a/src/a110x/jsupm_a110x.i b/src/a110x/jsupm_a110x.i index f6a53050..27befc34 100644 --- a/src/a110x/jsupm_a110x.i +++ b/src/a110x/jsupm_a110x.i @@ -1,8 +1,3 @@ %module jsupm_a110x -%include "../upm.i" -%{ - #include "a110x.hpp" -%} - -%include "a110x.hpp" +%include "common.i" diff --git a/src/a110x/pyupm_a110x.i b/src/a110x/pyupm_a110x.i index 19999662..c82bf319 100644 --- a/src/a110x/pyupm_a110x.i +++ b/src/a110x/pyupm_a110x.i @@ -1,9 +1,4 @@ -// Include doxygen-generated documentation %include "pyupm_doxy2swig.i" %module pyupm_a110x -%include "../upm.i" -%include "a110x.hpp" -%{ - #include "a110x.hpp" -%} +%include "common.i" diff --git a/src/abp/javaupm_abp.i b/src/abp/javaupm_abp.i index a32036ea..f69f4b00 100644 --- a/src/abp/javaupm_abp.i +++ b/src/abp/javaupm_abp.i @@ -8,13 +8,4 @@ %} %include "abp.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_abp"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_abp) diff --git a/src/ad8232/javaupm_ad8232.i b/src/ad8232/javaupm_ad8232.i index 5b90bbe5..31a21f47 100644 --- a/src/ad8232/javaupm_ad8232.i +++ b/src/ad8232/javaupm_ad8232.i @@ -7,13 +7,4 @@ %include "ad8232.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ad8232"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ad8232) \ No newline at end of file diff --git a/src/adafruitms1438/javaupm_adafruitms1438.i b/src/adafruitms1438/javaupm_adafruitms1438.i index b29b20ca..0633c7b9 100644 --- a/src/adafruitms1438/javaupm_adafruitms1438.i +++ b/src/adafruitms1438/javaupm_adafruitms1438.i @@ -7,13 +7,4 @@ %include "adafruitms1438.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_adafruitms1438"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_adafruitms1438) \ No newline at end of file diff --git a/src/adafruitss/javaupm_adafruitss.i b/src/adafruitss/javaupm_adafruitss.i index 1bbccd76..ad778277 100644 --- a/src/adafruitss/javaupm_adafruitss.i +++ b/src/adafruitss/javaupm_adafruitss.i @@ -6,13 +6,4 @@ #include "adafruitss.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_adafruitss"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_adafruitss) \ No newline at end of file diff --git a/src/adc121c021/javaupm_adc121c021.i b/src/adc121c021/javaupm_adc121c021.i index 45096009..5fa996e2 100644 --- a/src/adc121c021/javaupm_adc121c021.i +++ b/src/adc121c021/javaupm_adc121c021.i @@ -8,13 +8,4 @@ %include "adc121c021.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_adc121c021"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_adc121c021) \ No newline at end of file diff --git a/src/adis16448/javaupm_adis16448.i b/src/adis16448/javaupm_adis16448.i index 46dbd845..8fe04cc0 100644 --- a/src/adis16448/javaupm_adis16448.i +++ b/src/adis16448/javaupm_adis16448.i @@ -7,13 +7,4 @@ %include "adis16448.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_adis16448"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_adis16448) \ No newline at end of file diff --git a/src/ads1x15/javaupm_ads1x15.i b/src/ads1x15/javaupm_ads1x15.i index 3e83c564..78279501 100644 --- a/src/ads1x15/javaupm_ads1x15.i +++ b/src/ads1x15/javaupm_ads1x15.i @@ -18,13 +18,4 @@ import upm_interfaces.*; %include "ads1015.hpp" %include "ads1115.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ads1x15"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ads1x15) diff --git a/src/adxl335/javaupm_adxl335.i b/src/adxl335/javaupm_adxl335.i index 99e021e3..000745b5 100644 --- a/src/adxl335/javaupm_adxl335.i +++ b/src/adxl335/javaupm_adxl335.i @@ -42,13 +42,4 @@ %include "adxl335.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_adxl335"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_adxl335) \ No newline at end of file diff --git a/src/adxl345/javaupm_adxl345.i b/src/adxl345/javaupm_adxl345.i index 8087a365..bc4ce1e0 100644 --- a/src/adxl345/javaupm_adxl345.i +++ b/src/adxl345/javaupm_adxl345.i @@ -35,13 +35,4 @@ %include "adxl345.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_adxl345"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_adxl345) \ No newline at end of file diff --git a/src/adxrs610/javaupm_adxrs610.i b/src/adxrs610/javaupm_adxrs610.i index 32ca600a..6c0cdd87 100644 --- a/src/adxrs610/javaupm_adxrs610.i +++ b/src/adxrs610/javaupm_adxrs610.i @@ -7,13 +7,4 @@ %include "adxrs610.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_adxrs610"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_adxrs610) \ No newline at end of file diff --git a/src/am2315/javaupm_am2315.i b/src/am2315/javaupm_am2315.i index 8bdd047c..579324e6 100644 --- a/src/am2315/javaupm_am2315.i +++ b/src/am2315/javaupm_am2315.i @@ -7,13 +7,4 @@ %include "am2315.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_am2315"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_am2315) \ No newline at end of file diff --git a/src/apa102/javaupm_apa102.i b/src/apa102/javaupm_apa102.i index 372a228b..70ed738f 100644 --- a/src/apa102/javaupm_apa102.i +++ b/src/apa102/javaupm_apa102.i @@ -18,13 +18,4 @@ %include "apa102.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_apa102"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_apa102) diff --git a/src/apds9002/javaupm_apds9002.i b/src/apds9002/javaupm_apds9002.i index e994e0c1..0a4f381e 100644 --- a/src/apds9002/javaupm_apds9002.i +++ b/src/apds9002/javaupm_apds9002.i @@ -7,13 +7,4 @@ %include "apds9002.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_apds9002"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_apds9002) \ No newline at end of file diff --git a/src/apds9930/javaupm_apds9930.i b/src/apds9930/javaupm_apds9930.i index 2a7afb30..3059d356 100644 --- a/src/apds9930/javaupm_apds9930.i +++ b/src/apds9930/javaupm_apds9930.i @@ -6,13 +6,4 @@ %} %include "apds9930.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_apds9930"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_apds9930) diff --git a/src/at42qt1070/javaupm_at42qt1070.i b/src/at42qt1070/javaupm_at42qt1070.i index f387c4a6..233d44a8 100644 --- a/src/at42qt1070/javaupm_at42qt1070.i +++ b/src/at42qt1070/javaupm_at42qt1070.i @@ -7,13 +7,4 @@ %include "at42qt1070.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_at42qt1070"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_at42qt1070) \ No newline at end of file diff --git a/src/bacnetmstp/javaupm_bacnetmstp.i b/src/bacnetmstp/javaupm_bacnetmstp.i index 12dd8ed8..933734e9 100644 --- a/src/bacnetmstp/javaupm_bacnetmstp.i +++ b/src/bacnetmstp/javaupm_bacnetmstp.i @@ -11,13 +11,4 @@ %include "bacnetmstp.hpp" %include "bacnetutil.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bacnetmstp"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_bacnetmstp) diff --git a/src/bh1750/javaupm_bh1750.i b/src/bh1750/javaupm_bh1750.i index 7c1315c9..7630633a 100644 --- a/src/bh1750/javaupm_bh1750.i +++ b/src/bh1750/javaupm_bh1750.i @@ -10,13 +10,4 @@ %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bh1750"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_bh1750) diff --git a/src/biss0001/javaupm_biss0001.i b/src/biss0001/javaupm_biss0001.i index 0d7fae82..b4abf480 100644 --- a/src/biss0001/javaupm_biss0001.i +++ b/src/biss0001/javaupm_biss0001.i @@ -7,13 +7,4 @@ %include "biss0001.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_biss0001"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_biss0001) \ No newline at end of file diff --git a/src/bma220/bma220.cxx b/src/bma220/bma220.cxx index 4f540be8..86f1c35e 100644 --- a/src/bma220/bma220.cxx +++ b/src/bma220/bma220.cxx @@ -42,7 +42,7 @@ BMA220::BMA220(int bus, uint8_t addr) : m_accelX = 0.0; m_accelY = 0.0; m_accelZ = 0.0; - + m_accelScale = 0.0; mraa::Result rv; @@ -59,7 +59,7 @@ BMA220::BMA220(int bus, uint8_t addr) : // set scaling rate if (!setAccelerometerScale(FSL_RANGE_2G)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to set accel scale"); return; } @@ -107,8 +107,8 @@ bool BMA220::writeReg(uint8_t reg, uint8_t val) throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.writeReg() failed"); return false; - } - + } + return true; } @@ -126,11 +126,11 @@ bool BMA220::setAccelerometerScale(FSL_RANGE_T scale) } // store scaling factor - + switch (scale) { case FSL_RANGE_2G: - m_accelScale = 16.0; + m_accelScale = 16.0; break; case FSL_RANGE_4G: @@ -147,7 +147,7 @@ bool BMA220::setAccelerometerScale(FSL_RANGE_T scale) default: // should never occur, but... m_accelScale = 0.0; // set a safe, though incorrect value - throw std::logic_error(string(__FUNCTION__) + + throw std::logic_error(string(__FUNCTION__) + ": internal error, unsupported scale"); break; } @@ -193,7 +193,7 @@ bool BMA220::setFilterConfig(FILTER_CONFIG_T filter) reg &= ~(_FILTER_CONFIG_FILTER_MASK << _FILTER_CONFIG_FILTER_SHIFT); reg |= (filter << _FILTER_CONFIG_FILTER_SHIFT); - + return writeReg(REG_FILTER_CONFIG, reg); } @@ -205,7 +205,7 @@ bool BMA220::setSerialHighBW(bool high) reg |= FILTER_CONFIG_SERIAL_HIGH_BW; else reg &= ~FILTER_CONFIG_SERIAL_HIGH_BW; - + return writeReg(REG_FILTER_CONFIG, reg); } @@ -260,7 +260,7 @@ bool BMA220::setSleepDuration(SLEEP_DUR_T dur) reg &= ~(_ENABLE_CONFIG3_SLEEP_DUR_MASK << _ENABLE_CONFIG3_SLEEP_DUR_SHIFT); reg |= (dur << _ENABLE_CONFIG3_SLEEP_DUR_SHIFT); - + return writeReg(REG_ENABLE_CONFIG3, reg); } @@ -273,7 +273,7 @@ bool BMA220::setLowGThreshold(uint8_t thresh) reg &= ~(_THRESHOLD_LOW_MASK << _THRESHOLD_LOW_SHIFT); reg |= (thresh << _THRESHOLD_LOW_SHIFT); - + return writeReg(REG_THRESHOLD, reg); } @@ -286,7 +286,7 @@ bool BMA220::setHighGThreshold(uint8_t thresh) reg &= ~(_THRESHOLD_HIGH_MASK << _THRESHOLD_HIGH_SHIFT); reg |= (thresh << _THRESHOLD_HIGH_SHIFT); - + return writeReg(REG_THRESHOLD, reg); } @@ -299,7 +299,7 @@ bool BMA220::setLowGHysteresis(uint8_t hyst) reg &= ~(_L_HYST_DUR_LOW_HY_MASK << _L_HYST_DUR_LOW_HY_SHIFT); reg |= (hyst << _L_HYST_DUR_LOW_HY_SHIFT); - + return writeReg(REG_L_HYST_DUR, reg); } @@ -312,7 +312,7 @@ bool BMA220::setLowGDuration(uint8_t dur) reg &= ~(_L_HYST_DUR_LOW_DUR_MASK << _L_HYST_DUR_LOW_DUR_SHIFT); reg |= (dur << _L_HYST_DUR_LOW_DUR_SHIFT); - + return writeReg(REG_L_HYST_DUR, reg); } @@ -325,7 +325,7 @@ bool BMA220::setHighGHysteresis(uint8_t hyst) reg &= ~(_H_HYST_DUR_HIGH_HY_MASK << _H_HYST_DUR_HIGH_HY_SHIFT); reg |= (hyst << _H_HYST_DUR_HIGH_HY_SHIFT); - + return writeReg(REG_H_HYST_DUR, reg); } @@ -338,7 +338,7 @@ bool BMA220::setHighGDuration(uint8_t dur) reg &= ~(_H_HYST_DUR_HIGH_DUR_MASK << _H_HYST_DUR_HIGH_DUR_SHIFT); reg |= (dur << _H_HYST_DUR_HIGH_DUR_SHIFT); - + return writeReg(REG_H_HYST_DUR, reg); } @@ -351,7 +351,7 @@ bool BMA220::setTapDuration(uint8_t dur) reg &= ~(_TAP_CONFIG_DUR_MASK << _TAP_CONFIG_DUR_SHIFT); reg |= (dur << _TAP_CONFIG_DUR_SHIFT); - + return writeReg(REG_TAP_CONFIG, reg); } @@ -364,7 +364,7 @@ bool BMA220::setTapThreshold(uint8_t thresh) reg &= ~(_TAP_CONFIG_THRESH_MASK << _TAP_CONFIG_THRESH_SHIFT); reg |= (thresh << _TAP_CONFIG_THRESH_SHIFT); - + return writeReg(REG_TAP_CONFIG, reg); } @@ -389,7 +389,7 @@ bool BMA220::setSlopeDuration(uint8_t dur) reg &= ~(_SLOPE_CONFIG_DUR_MASK << _SLOPE_CONFIG_DUR_SHIFT); reg |= (dur << _SLOPE_CONFIG_DUR_SHIFT); - + return writeReg(REG_SLOPE_CONFIG, reg); } @@ -402,7 +402,7 @@ bool BMA220::setSlopeThreshold(uint8_t thresh) reg &= ~(_SLOPE_CONFIG_THRESH_MASK << _SLOPE_CONFIG_THRESH_SHIFT); reg |= (thresh << _SLOPE_CONFIG_THRESH_SHIFT); - + return writeReg(REG_SLOPE_CONFIG, reg); } @@ -474,7 +474,7 @@ bool BMA220::setInterruptLatch(CONFIG2_LAT_T lat) reg &= ~(_ENABLE_CONFIG2_LAT_INT_MASK << _ENABLE_CONFIG2_LAT_INT_SHIFT); reg |= (lat << _ENABLE_CONFIG2_LAT_INT_SHIFT); - + return writeReg(REG_ENABLE_CONFIG2, reg); } @@ -489,22 +489,8 @@ bool BMA220::resetInterrupts() return writeReg(REG_ENABLE_CONFIG2, reg); } -#if defined(SWIGJAVA) || (JAVACALLBACK) + void BMA220::installISR(int gpio, mraa::Edge level, - jobject runnable) -{ - // delete any existing ISR and GPIO context - uninstallISR(); - - // create gpio context - m_gpioIntr = new mraa::Gpio(gpio); - - m_gpioIntr->dir(mraa::DIR_IN); - m_gpioIntr->isr(level, runnable); - -} -#else -void BMA220::installISR(int gpio, mraa::Edge level, void (*isr)(void *), void *arg) { // delete any existing ISR and GPIO context @@ -516,7 +502,6 @@ void BMA220::installISR(int gpio, mraa::Edge level, m_gpioIntr->dir(mraa::DIR_IN); m_gpioIntr->isr(level, isr, arg); } -#endif void BMA220::uninstallISR() { @@ -524,8 +509,12 @@ void BMA220::uninstallISR() { m_gpioIntr->isrExit(); delete m_gpioIntr; - + m_gpioIntr = 0; } } +mraa::Gpio* BMA220::get_gpioIntr() +{ + return m_gpioIntr; +} diff --git a/src/bma220/bma220.hpp b/src/bma220/bma220.hpp index 8077ade4..3edddace 100644 --- a/src/bma220/bma220.hpp +++ b/src/bma220/bma220.hpp @@ -32,7 +32,7 @@ #define BMA220_DEFAULT_ADDR 0x0a namespace upm { - + /** * @brief BMA220 Accelerometer library * @defgroup bma220 libupm-bma220 @@ -115,7 +115,7 @@ namespace upm { REG_SUSPEND = 0x30, REG_SOFTRESET = 0x32 } REG_T; - + /** * REG_H_HYST_DUR bits @@ -271,7 +271,7 @@ namespace upm { INT_STATUS1_ORIENT_INT = 0x80 // orient intr was generated } INT_STATUS1_BITS_T; - + /** * INT_STATUS1_ORIENT values * @@ -485,7 +485,7 @@ namespace upm { * BMA220 Destructor */ ~BMA220(); - + /** * update the accelerometer values */ @@ -776,9 +776,7 @@ namespace upm { */ bool resetInterrupts(); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(int gpio, mraa::Edge level, jobject runnable); -#else + /** * install an interrupt handler. * @@ -789,16 +787,17 @@ namespace upm { * @param isr the interrupt handler, accepting a void * argument * @param arg the argument to pass the the interrupt handler */ - void installISR(int gpio, mraa::Edge level, + void installISR(int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif - + /** * uninstall a previously installed interrupt handler * */ void uninstallISR(); + mraa::Gpio* get_gpioIntr(); + protected: mraa::I2c m_i2c; mraa::Gpio *m_gpioIntr; @@ -821,13 +820,6 @@ namespace upm { * update the accelerometer values */ void updateAccelerometer(); - // Adding a private function definition for java bindings -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(int gpio, mraa::Edge level, - void (*isr)(void *), void *arg); -#endif }; } - - diff --git a/src/bma220/javaupm_bma220.i b/src/bma220/javaupm_bma220.i index c2363c06..24bcd47f 100644 --- a/src/bma220/javaupm_bma220.i +++ b/src/bma220/javaupm_bma220.i @@ -30,13 +30,10 @@ %include "bma220.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bma220"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +%define GETTER get_gpioIntr(); +%enddef +JAVA_ADD_INSTALLISR_GPIO(upm::BMA220) + +%ignore installISR(int, mraa::Edge, void *, void *); + +JAVA_JNI_LOADLIBRARY(javaupm_bma220) diff --git a/src/bma250e/bma250e.hpp b/src/bma250e/bma250e.hpp index 632d2563..9b199757 100644 --- a/src/bma250e/bma250e.hpp +++ b/src/bma250e/bma250e.hpp @@ -518,14 +518,7 @@ namespace upm { void setLowPowerMode2(); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(BMA250E_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, jobject runnable) - { - installISR(intr, gpio, level, mraa_java_isr_callback, runnable); - } -#else - /** + /** * install an interrupt handler. * * @param intr One of the BMA250E_INTERRUPT_PINS_T values @@ -541,7 +534,6 @@ namespace upm { void installISR(BMA250E_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif /** * uninstall a previously installed interrupt handler @@ -585,12 +577,6 @@ namespace upm { /* Disable implicit copy and assignment operators */ BMA250E(const BMA250E&) = delete; BMA250E &operator=(const BMA250E&) = delete; - - // Adding a private function definition for java bindings -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(BMA250E_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, - void (*isr)(void *), void *arg); -#endif + }; } diff --git a/src/bma250e/javaupm_bma250e.i b/src/bma250e/javaupm_bma250e.i index 1435bfee..d31bc803 100644 --- a/src/bma250e/javaupm_bma250e.i +++ b/src/bma250e/javaupm_bma250e.i @@ -20,19 +20,19 @@ import java.lang.Float; %template(floatVector) std::vector; -%include "bma250e_defs.h" -%include "bma250e.hpp" %{ #include "bma250e.hpp" + #include "bma250e_defs.h" %} +%include "bma250e_defs.h" +%include "bma250e.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bma250e"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} + +%ignore installISR (BMA250E_INTERRUPT_PINS_T, int, mraa::Edge , void *, void *); + +%define INTERRUPT BMA250E_INTERRUPT_PINS_T +%enddef +JAVA_ADD_INSTALLISR_INTERRUPT(upm::BMA250E) + + +JAVA_JNI_LOADLIBRARY(javaupm_bma250e) diff --git a/src/bmg160/bmg160.hpp b/src/bmg160/bmg160.hpp index b663c32c..46559f3a 100644 --- a/src/bmg160/bmg160.hpp +++ b/src/bmg160/bmg160.hpp @@ -415,13 +415,6 @@ namespace upm { */ void enableOutputFiltering(bool filter); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(BMG160_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, jobject runnable) - { - installISR(intr, gpio, level, mraa_java_isr_callback, runnable); - } -#else /** * install an interrupt handler. * @@ -439,7 +432,6 @@ namespace upm { void installISR(BMG160_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif /** * uninstall a previously installed interrupt handler @@ -484,11 +476,5 @@ namespace upm { BMG160(const BMG160&) = delete; BMG160 &operator=(const BMG160&) = delete; - // needs to be private for SWIG Java builds -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(BMG160_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, - void (*isr)(void *), void *arg); -#endif }; } diff --git a/src/bmg160/javaupm_bmg160.i b/src/bmg160/javaupm_bmg160.i index ef394217..f1d49274 100644 --- a/src/bmg160/javaupm_bmg160.i +++ b/src/bmg160/javaupm_bmg160.i @@ -20,19 +20,18 @@ import java.lang.Float; %template(floatVector) std::vector; -%include "bmg160_defs.h" -%include "bmg160.hpp" %{ #include "bmg160.hpp" + #include "bmg160_defs.h" %} +%include "bmg160_defs.h" +%include "bmg160.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bmg160"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} + +%ignore installISR (BMG160_INTERRUPT_PINS_T , int mraa::Edge , void *, void *); + +%define INTERRUPT BMG160_INTERRUPT_PINS_T +%enddef +JAVA_ADD_INSTALLISR_INTERRUPT(upm::BMG160) + +JAVA_JNI_LOADLIBRARY(javaupm_bmg160) diff --git a/src/bmi160/javaupm_bmi160.i b/src/bmi160/javaupm_bmi160.i index 57603b42..02914254 100644 --- a/src/bmi160/javaupm_bmi160.i +++ b/src/bmi160/javaupm_bmi160.i @@ -30,13 +30,4 @@ %include "bmi160.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bmi160"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_bmi160) diff --git a/src/bmm150/bmm150.hpp b/src/bmm150/bmm150.hpp index fecc6a76..b7aad494 100644 --- a/src/bmm150/bmm150.hpp +++ b/src/bmm150/bmm150.hpp @@ -281,14 +281,6 @@ namespace upm { */ void setRepetitionsZ(uint8_t reps); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(BMM150_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, - jobject runnable) - { - installISR(intr, gpio, level, mraa_java_isr_callback, runnable); - } -#else /** * Install an interrupt handler. * @@ -305,7 +297,6 @@ namespace upm { void installISR(BMM150_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif /** * Uninstall a previously installed interrupt handler. @@ -350,11 +341,5 @@ namespace upm { BMM150(const BMM150&) = delete; BMM150 &operator=(const BMM150&) = delete; - // Adding a private function definition for java bindings -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(BMM150_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, - void (*isr)(void *), void *arg); -#endif }; } diff --git a/src/bmm150/javaupm_bmm150.i b/src/bmm150/javaupm_bmm150.i index bf8a285a..14ec636a 100644 --- a/src/bmm150/javaupm_bmm150.i +++ b/src/bmm150/javaupm_bmm150.i @@ -20,19 +20,17 @@ import java.lang.Float; %template(floatVector) std::vector; -%include "bmm150_defs.h" -%include "bmm150.hpp" %{ #include "bmm150.hpp" + #include "bmm150_defs.h" %} +%include "bmm150_defs.h" +%include "bmm150.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bmm150"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +%ignore installISR (BMM150_INTERRUPT_PINS_T , int , mraa::Edge , void *, void *); + +%define INTERRUPT BMM150_INTERRUPT_PINS_T +%enddef +JAVA_ADD_INSTALLISR_INTERRUPT(upm::BMM150) + +JAVA_JNI_LOADLIBRARY(javaupm_bmm150) diff --git a/src/bmp280/javaupm_bmp280.i b/src/bmp280/javaupm_bmp280.i index a4fb6dce..90cedea2 100644 --- a/src/bmp280/javaupm_bmp280.i +++ b/src/bmp280/javaupm_bmp280.i @@ -26,13 +26,4 @@ #include "bme280.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bmp280"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_bmp280) diff --git a/src/bmpx8x/javaupm_bmpx8x.i b/src/bmpx8x/javaupm_bmpx8x.i index d17819f2..6f511c42 100644 --- a/src/bmpx8x/javaupm_bmpx8x.i +++ b/src/bmpx8x/javaupm_bmpx8x.i @@ -15,13 +15,4 @@ import upm_interfaces.*; %include "bmpx8x_defs.h" %include "bmpx8x.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bmpx8x"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_bmpx8x) diff --git a/src/bmx055/javaupm_bmx055.i b/src/bmx055/javaupm_bmx055.i index 17ec87f1..194617e8 100644 --- a/src/bmx055/javaupm_bmx055.i +++ b/src/bmx055/javaupm_bmx055.i @@ -44,13 +44,4 @@ import java.lang.Float; #include "bmi055.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bmx055"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_bmx055) diff --git a/src/bno055/bno055.hpp b/src/bno055/bno055.hpp index 73ce7af2..ba25468a 100644 --- a/src/bno055/bno055.hpp +++ b/src/bno055/bno055.hpp @@ -622,12 +622,6 @@ namespace upm { BNO055_SYS_ERR_T getSystemError(); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(int gpio, mraa_gpio_edge_t level, jobject runnable) - { - installISR(gpio, level, mraa_java_isr_callback, runnable); - } -#else /** * install an interrupt handler. * @@ -641,7 +635,6 @@ namespace upm { */ void installISR(int gpio, mraa_gpio_edge_t level, void (*isr)(void *), void *arg); -#endif /** * uninstall a previously installed interrupt handler @@ -707,10 +700,5 @@ namespace upm { BNO055(const BNO055&) = delete; BNO055 &operator=(const BNO055&) = delete; - // Adding a private function definition for java bindings -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(int gpio, mraa_gpio_edge_t level, - void (*isr)(void *), void *arg); -#endif }; } diff --git a/src/bno055/javaupm_bno055.i b/src/bno055/javaupm_bno055.i index 4dba63ec..76d985e9 100644 --- a/src/bno055/javaupm_bno055.i +++ b/src/bno055/javaupm_bno055.i @@ -18,19 +18,20 @@ %template(byteVector) std::vector; %template(intVector) std::vector; -%include "bno055_regs.h" -%include "bno055.hpp" %{ #include "bno055.hpp" + #include "bno055_regs.h" %} +%include "bno055_regs.h" +%include "bno055.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_bno055"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } +%ignore installISR(int , mraa::Edge , void *, void *); + +%extend upm::BNO055 { + void installISR(int gpio, mraa_gpio_edge_t level, jobject runnable) + { + $self->installISR(gpio, level, mraa_java_isr_callback, runnable); } -%} +} + +JAVA_JNI_LOADLIBRARY(javaupm_bno055) diff --git a/src/button/button.cxx b/src/button/button.cxx index 0b902a0a..51a51b97 100644 --- a/src/button/button.cxx +++ b/src/button/button.cxx @@ -59,12 +59,12 @@ int Button::value() return mraa_gpio_read(m_gpio); } -#ifdef JAVACALLBACK +/*#ifdef JAVACALLBACK void Button::installISR(mraa::Edge level, jobject runnable) { installISR(level, mraa_java_isr_callback, runnable); } -#endif +#endif*/ void Button::installISR(mraa::Edge level, void (*isr)(void *), void *arg) { diff --git a/src/button/button.hpp b/src/button/button.hpp index 6e604580..8696226f 100644 --- a/src/button/button.hpp +++ b/src/button/button.hpp @@ -87,11 +87,11 @@ class Button{ * @param arg Pointer to an object to be supplied as an * argument to the ISR. */ -#if defined(SWIGJAVA) || defined(JAVACALLBACK) +/*#if defined(SWIGJAVA) || defined(JAVACALLBACK) void installISR(mraa::Edge level, jobject runnable); -#else +#else*/ void installISR(mraa::Edge level, void (*isr)(void *), void *arg); -#endif +//#endif /** * Uninstalls the previously installed ISR * @@ -99,9 +99,6 @@ class Button{ void uninstallISR(); private: -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(mraa::Edge level, void (*isr)(void *), void *arg); -#endif bool m_isrInstalled; std::string m_name; mraa_gpio_context m_gpio; diff --git a/src/button/javaupm_button.i b/src/button/javaupm_button.i index 8e8f30d2..1812e2cf 100644 --- a/src/button/javaupm_button.i +++ b/src/button/javaupm_button.i @@ -9,13 +9,8 @@ %include "button.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_button"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +#%ignore + +JAVA_ADD_INSTALLISR_EDGE(upm::Button) + +JAVA_JNI_LOADLIBRARY(javaupm_button) diff --git a/src/buzzer/javaupm_buzzer.i b/src/buzzer/javaupm_buzzer.i index b7041134..ec515f81 100644 --- a/src/buzzer/javaupm_buzzer.i +++ b/src/buzzer/javaupm_buzzer.i @@ -8,13 +8,4 @@ #include "buzzer.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_buzzer"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_buzzer) diff --git a/src/cjq4435/javaupm_cjq4435.i b/src/cjq4435/javaupm_cjq4435.i index 414863d4..b0b206db 100644 --- a/src/cjq4435/javaupm_cjq4435.i +++ b/src/cjq4435/javaupm_cjq4435.i @@ -7,13 +7,4 @@ %include "cjq4435.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_cjq4435"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_cjq4435) \ No newline at end of file diff --git a/src/collision/javaupm_collision.i b/src/collision/javaupm_collision.i index c4f74673..c61cd48c 100644 --- a/src/collision/javaupm_collision.i +++ b/src/collision/javaupm_collision.i @@ -7,13 +7,4 @@ %include "collision.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_collision"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_collision) \ No newline at end of file diff --git a/src/curieimu/javaupm_curieimu.i b/src/curieimu/javaupm_curieimu.i index 726f8c2b..24ebc1d1 100644 --- a/src/curieimu/javaupm_curieimu.i +++ b/src/curieimu/javaupm_curieimu.i @@ -30,13 +30,4 @@ %include "curieimu.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_curieimu"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_curieimu) diff --git a/src/cwlsxxa/javaupm_cwlsxxa.i b/src/cwlsxxa/javaupm_cwlsxxa.i index 8a25f336..54e1b250 100644 --- a/src/cwlsxxa/javaupm_cwlsxxa.i +++ b/src/cwlsxxa/javaupm_cwlsxxa.i @@ -7,13 +7,4 @@ #include "cwlsxxa.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_cwlsxxa"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_cwlsxxa) diff --git a/src/dfrec/javaupm_dfrec.i b/src/dfrec/javaupm_dfrec.i index 6efab860..868860d9 100644 --- a/src/dfrec/javaupm_dfrec.i +++ b/src/dfrec/javaupm_dfrec.i @@ -9,13 +9,4 @@ #include "dfrec.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_dfrec"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_dfrec) diff --git a/src/dfrorp/javaupm_dfrorp.i b/src/dfrorp/javaupm_dfrorp.i index 6215fc3a..da465c48 100644 --- a/src/dfrorp/javaupm_dfrorp.i +++ b/src/dfrorp/javaupm_dfrorp.i @@ -9,13 +9,4 @@ #include "dfrorp.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_dfrorp"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_dfrorp) diff --git a/src/dfrph/javaupm_dfrph.i b/src/dfrph/javaupm_dfrph.i index 975520bc..83570bb3 100644 --- a/src/dfrph/javaupm_dfrph.i +++ b/src/dfrph/javaupm_dfrph.i @@ -7,13 +7,4 @@ %include "dfrph.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_dfrph"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_dfrph) \ No newline at end of file diff --git a/src/ds1307/javaupm_ds1307.i b/src/ds1307/javaupm_ds1307.i index 6bb3b71b..1ef78215 100644 --- a/src/ds1307/javaupm_ds1307.i +++ b/src/ds1307/javaupm_ds1307.i @@ -9,13 +9,4 @@ %include "ds1307.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ds1307"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ds1307) \ No newline at end of file diff --git a/src/ds1808lc/javaupm_ds1808lc.i b/src/ds1808lc/javaupm_ds1808lc.i index c0a0ca79..f8e8f3d4 100644 --- a/src/ds1808lc/javaupm_ds1808lc.i +++ b/src/ds1808lc/javaupm_ds1808lc.i @@ -18,13 +18,4 @@ import upm_interfaces.*; %include "ds1808lc.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ds1808lc"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ds1808lc) diff --git a/src/ds18b20/javaupm_ds18b20.i b/src/ds18b20/javaupm_ds18b20.i index 170bc2c2..b46df9cb 100644 --- a/src/ds18b20/javaupm_ds18b20.i +++ b/src/ds18b20/javaupm_ds18b20.i @@ -11,13 +11,4 @@ %array_class(char, charArray); -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ds18b20"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ds18b20) diff --git a/src/ds2413/javaupm_ds2413.i b/src/ds2413/javaupm_ds2413.i index c8469508..51118778 100644 --- a/src/ds2413/javaupm_ds2413.i +++ b/src/ds2413/javaupm_ds2413.i @@ -10,13 +10,4 @@ %include "ds2413.hpp" %array_class(char, charArray); -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ds2413"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ds2413) diff --git a/src/e50hx/javaupm_e50hx.i b/src/e50hx/javaupm_e50hx.i index 19b7b0fa..e2cc8441 100644 --- a/src/e50hx/javaupm_e50hx.i +++ b/src/e50hx/javaupm_e50hx.i @@ -22,13 +22,4 @@ %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_e50hx"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_e50hx) diff --git a/src/ecezo/javaupm_ecezo.i b/src/ecezo/javaupm_ecezo.i index ea18ce84..64d34e99 100644 --- a/src/ecezo/javaupm_ecezo.i +++ b/src/ecezo/javaupm_ecezo.i @@ -10,13 +10,4 @@ #include "ecezo.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ecezo"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ecezo) diff --git a/src/ecs1030/javaupm_ecs1030.i b/src/ecs1030/javaupm_ecs1030.i index 54ac2bb5..44153781 100644 --- a/src/ecs1030/javaupm_ecs1030.i +++ b/src/ecs1030/javaupm_ecs1030.i @@ -7,13 +7,4 @@ %include "ecs1030.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ecs1030"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ecs1030) \ No newline at end of file diff --git a/src/ehr/javaupm_ehr.i b/src/ehr/javaupm_ehr.i index 6cce692d..829e50f7 100644 --- a/src/ehr/javaupm_ehr.i +++ b/src/ehr/javaupm_ehr.i @@ -9,13 +9,4 @@ %include "ehr.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ehr"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ehr) \ No newline at end of file diff --git a/src/eldriver/javaupm_eldriver.i b/src/eldriver/javaupm_eldriver.i index 1a2abc0d..bef554ae 100644 --- a/src/eldriver/javaupm_eldriver.i +++ b/src/eldriver/javaupm_eldriver.i @@ -7,13 +7,4 @@ %include "eldriver.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_eldriver"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_eldriver) \ No newline at end of file diff --git a/src/electromagnet/javaupm_electromagnet.i b/src/electromagnet/javaupm_electromagnet.i index 96f0c246..99403700 100644 --- a/src/electromagnet/javaupm_electromagnet.i +++ b/src/electromagnet/javaupm_electromagnet.i @@ -7,13 +7,4 @@ %include "electromagnet.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_electromagnet"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_electromagnet) \ No newline at end of file diff --git a/src/emg/javaupm_emg.i b/src/emg/javaupm_emg.i index da6f4e50..6f911c38 100644 --- a/src/emg/javaupm_emg.i +++ b/src/emg/javaupm_emg.i @@ -7,13 +7,4 @@ %include "emg.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_emg"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_emg) \ No newline at end of file diff --git a/src/enc03r/javaupm_enc03r.i b/src/enc03r/javaupm_enc03r.i index 5f901ebd..e5e9f3e2 100644 --- a/src/enc03r/javaupm_enc03r.i +++ b/src/enc03r/javaupm_enc03r.i @@ -7,13 +7,4 @@ %include "enc03r.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_enc03r"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_enc03r) \ No newline at end of file diff --git a/src/flex/javaupm_flex.i b/src/flex/javaupm_flex.i index b4017c5b..14a07ed7 100644 --- a/src/flex/javaupm_flex.i +++ b/src/flex/javaupm_flex.i @@ -7,13 +7,4 @@ %include "flex.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_flex"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_flex) \ No newline at end of file diff --git a/src/gas/javaupm_gas.i b/src/gas/javaupm_gas.i index 6e87530c..9a259973 100644 --- a/src/gas/javaupm_gas.i +++ b/src/gas/javaupm_gas.i @@ -56,13 +56,4 @@ %include "mq9.hpp" %include "tp401.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_gas"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_gas) \ No newline at end of file diff --git a/src/gp2y0a/javaupm_gp2y0a.i b/src/gp2y0a/javaupm_gp2y0a.i index 7edfcea5..3ea06750 100644 --- a/src/gp2y0a/javaupm_gp2y0a.i +++ b/src/gp2y0a/javaupm_gp2y0a.i @@ -7,13 +7,4 @@ %include "gp2y0a.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_gp2y0a"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_gp2y0a) \ No newline at end of file diff --git a/src/gprs/javaupm_gprs.i b/src/gprs/javaupm_gprs.i index fd79f474..61a59cfc 100644 --- a/src/gprs/javaupm_gprs.i +++ b/src/gprs/javaupm_gprs.i @@ -10,13 +10,4 @@ %include "gprs.hpp" %array_class(char, charArray); -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_gprs"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_gprs) \ No newline at end of file diff --git a/src/grove/grovebutton.cxx b/src/grove/grovebutton.cxx index a4926285..5c77b960 100644 --- a/src/grove/grovebutton.cxx +++ b/src/grove/grovebutton.cxx @@ -58,12 +58,12 @@ int GroveButton::value() return mraa_gpio_read(m_gpio); } -#ifdef JAVACALLBACK +/*#ifdef JAVACALLBACK void GroveButton::installISR(mraa::Edge level, jobject runnable) { installISR(level, mraa_java_isr_callback, runnable); } -#endif +#endif*/ void GroveButton::installISR(mraa::Edge level, void (*isr)(void *), void *arg) { diff --git a/src/grove/grovebutton.hpp b/src/grove/grovebutton.hpp index a99092bf..00761332 100644 --- a/src/grove/grovebutton.hpp +++ b/src/grove/grovebutton.hpp @@ -84,11 +84,11 @@ class GroveButton: public Grove { * @param arg Pointer to an object to be supplied as an * argument to the ISR. */ -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(mraa::Edge level, jobject runnable); -#else +//#if defined(SWIGJAVA) || defined(JAVACALLBACK) + // void installISR(mraa::Edge level, jobject runnable); +//#else void installISR(mraa::Edge level, void (*isr)(void *), void *arg); -#endif +//#endif /** * Uninstalls the previously installed ISR * @@ -96,9 +96,6 @@ class GroveButton: public Grove { void uninstallISR(); private: -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(mraa::Edge level, void (*isr)(void *), void *arg); -#endif bool m_isrInstalled; std::string m_name; mraa_gpio_context m_gpio; diff --git a/src/grove/javaupm_grove.i b/src/grove/javaupm_grove.i index a70cdea1..724ccdb1 100644 --- a/src/grove/javaupm_grove.i +++ b/src/grove/javaupm_grove.i @@ -49,13 +49,8 @@ #include "grovetemp.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grove"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_ADD_INSTALLISR_EDGE(upm::GroveButton) + + + +JAVA_JNI_LOADLIBRARY(javaupm_grove) diff --git a/src/grovecollision/javaupm_grovecollision.i b/src/grovecollision/javaupm_grovecollision.i index 39b50252..2697c0e2 100644 --- a/src/grovecollision/javaupm_grovecollision.i +++ b/src/grovecollision/javaupm_grovecollision.i @@ -7,13 +7,4 @@ %include "grovecollision.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovecollision"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovecollision) \ No newline at end of file diff --git a/src/groveehr/javaupm_groveehr.i b/src/groveehr/javaupm_groveehr.i index 2ac1d9c4..55d0b6b6 100644 --- a/src/groveehr/javaupm_groveehr.i +++ b/src/groveehr/javaupm_groveehr.i @@ -9,13 +9,4 @@ %include "groveehr.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_groveehr"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_groveehr) \ No newline at end of file diff --git a/src/groveeldriver/javaupm_groveeldriver.i b/src/groveeldriver/javaupm_groveeldriver.i index f6e67877..9647d777 100644 --- a/src/groveeldriver/javaupm_groveeldriver.i +++ b/src/groveeldriver/javaupm_groveeldriver.i @@ -7,13 +7,4 @@ %include "groveeldriver.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_groveeldriver"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_groveeldriver) \ No newline at end of file diff --git a/src/groveelectromagnet/javaupm_groveelectromagnet.i b/src/groveelectromagnet/javaupm_groveelectromagnet.i index ecfffde1..b3c80972 100644 --- a/src/groveelectromagnet/javaupm_groveelectromagnet.i +++ b/src/groveelectromagnet/javaupm_groveelectromagnet.i @@ -7,13 +7,4 @@ %include "groveelectromagnet.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_groveelectromagnet"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_groveelectromagnet) \ No newline at end of file diff --git a/src/groveemg/javaupm_groveemg.i b/src/groveemg/javaupm_groveemg.i index 9c66328b..a8224642 100644 --- a/src/groveemg/javaupm_groveemg.i +++ b/src/groveemg/javaupm_groveemg.i @@ -7,13 +7,4 @@ %include "groveemg.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_groveemg"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_groveemg) \ No newline at end of file diff --git a/src/grovegprs/javaupm_grovegprs.i b/src/grovegprs/javaupm_grovegprs.i index 29972361..3671fda5 100644 --- a/src/grovegprs/javaupm_grovegprs.i +++ b/src/grovegprs/javaupm_grovegprs.i @@ -10,13 +10,4 @@ %include "grovegprs.hpp" %array_class(char, charArray); -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovegprs"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovegprs) \ No newline at end of file diff --git a/src/grovegsr/javaupm_grovegsr.i b/src/grovegsr/javaupm_grovegsr.i index 22e27b0c..20ca2eda 100644 --- a/src/grovegsr/javaupm_grovegsr.i +++ b/src/grovegsr/javaupm_grovegsr.i @@ -7,13 +7,4 @@ %include "grovegsr.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovegsr"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovegsr) \ No newline at end of file diff --git a/src/grovelinefinder/javaupm_grovelinefinder.i b/src/grovelinefinder/javaupm_grovelinefinder.i index ebad50a8..8c38f43f 100644 --- a/src/grovelinefinder/javaupm_grovelinefinder.i +++ b/src/grovelinefinder/javaupm_grovelinefinder.i @@ -7,13 +7,4 @@ %include "grovelinefinder.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovelinefinder"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovelinefinder) \ No newline at end of file diff --git a/src/grovemd/javaupm_grovemd.i b/src/grovemd/javaupm_grovemd.i index 4fa1da78..b1ef7661 100644 --- a/src/grovemd/javaupm_grovemd.i +++ b/src/grovemd/javaupm_grovemd.i @@ -7,13 +7,4 @@ %include "grovemd.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovemd"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovemd) \ No newline at end of file diff --git a/src/grovemoisture/javaupm_grovemoisture.i b/src/grovemoisture/javaupm_grovemoisture.i index 1cf217c7..2ed6005a 100644 --- a/src/grovemoisture/javaupm_grovemoisture.i +++ b/src/grovemoisture/javaupm_grovemoisture.i @@ -7,13 +7,4 @@ %include "grovemoisture.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovemoisture"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovemoisture) \ No newline at end of file diff --git a/src/groveo2/javaupm_groveo2.i b/src/groveo2/javaupm_groveo2.i index a7611088..dc408563 100644 --- a/src/groveo2/javaupm_groveo2.i +++ b/src/groveo2/javaupm_groveo2.i @@ -7,13 +7,4 @@ %include "groveo2.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_groveo2"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_groveo2) \ No newline at end of file diff --git a/src/grovescam/javaupm_grovescam.i b/src/grovescam/javaupm_grovescam.i index c22bf9c5..0b0966db 100644 --- a/src/grovescam/javaupm_grovescam.i +++ b/src/grovescam/javaupm_grovescam.i @@ -8,13 +8,4 @@ %include "grovescam.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovescam"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovescam) \ No newline at end of file diff --git a/src/grovespeaker/javaupm_grovespeaker.i b/src/grovespeaker/javaupm_grovespeaker.i index 4af4564a..65934a5e 100644 --- a/src/grovespeaker/javaupm_grovespeaker.i +++ b/src/grovespeaker/javaupm_grovespeaker.i @@ -7,13 +7,4 @@ %include "grovespeaker.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovespeaker"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovespeaker) \ No newline at end of file diff --git a/src/groveultrasonic/javaupm_groveultrasonic.i b/src/groveultrasonic/javaupm_groveultrasonic.i index f8907065..7d906b2d 100644 --- a/src/groveultrasonic/javaupm_groveultrasonic.i +++ b/src/groveultrasonic/javaupm_groveultrasonic.i @@ -9,13 +9,4 @@ %include "groveultrasonic.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_groveultrasonic"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_groveultrasonic) diff --git a/src/grovevdiv/javaupm_grovevdiv.i b/src/grovevdiv/javaupm_grovevdiv.i index b3c5e02f..5dc15ef0 100644 --- a/src/grovevdiv/javaupm_grovevdiv.i +++ b/src/grovevdiv/javaupm_grovevdiv.i @@ -7,13 +7,4 @@ %include "grovevdiv.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovevdiv"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovevdiv) \ No newline at end of file diff --git a/src/grovewater/javaupm_grovewater.i b/src/grovewater/javaupm_grovewater.i index 0c074171..3d2eeabb 100644 --- a/src/grovewater/javaupm_grovewater.i +++ b/src/grovewater/javaupm_grovewater.i @@ -7,13 +7,4 @@ %include "grovewater.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovewater"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovewater) \ No newline at end of file diff --git a/src/grovewfs/javaupm_grovewfs.i b/src/grovewfs/javaupm_grovewfs.i index f4e5f045..65cbf0f6 100644 --- a/src/grovewfs/javaupm_grovewfs.i +++ b/src/grovewfs/javaupm_grovewfs.i @@ -9,13 +9,4 @@ %include "grovewfs.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_grovewfs"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_grovewfs) \ No newline at end of file diff --git a/src/gsr/javaupm_gsr.i b/src/gsr/javaupm_gsr.i index 4d058129..de644725 100644 --- a/src/gsr/javaupm_gsr.i +++ b/src/gsr/javaupm_gsr.i @@ -7,13 +7,4 @@ %include "gsr.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_gsr"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_gsr) \ No newline at end of file diff --git a/src/guvas12d/javaupm_guvas12d.i b/src/guvas12d/javaupm_guvas12d.i index 0cf05992..3f0ab6ef 100644 --- a/src/guvas12d/javaupm_guvas12d.i +++ b/src/guvas12d/javaupm_guvas12d.i @@ -7,13 +7,4 @@ %include "guvas12d.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_guvas12d"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_guvas12d) \ No newline at end of file diff --git a/src/h3lis331dl/javaupm_h3lis331dl.i b/src/h3lis331dl/javaupm_h3lis331dl.i index 9a8d1e0e..c6c05cb4 100644 --- a/src/h3lis331dl/javaupm_h3lis331dl.i +++ b/src/h3lis331dl/javaupm_h3lis331dl.i @@ -50,13 +50,4 @@ %include "h3lis331dl.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_h3lis331dl"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_h3lis331dl) \ No newline at end of file diff --git a/src/h803x/javaupm_h803x.i b/src/h803x/javaupm_h803x.i index 7c98031f..691e127a 100644 --- a/src/h803x/javaupm_h803x.i +++ b/src/h803x/javaupm_h803x.i @@ -8,13 +8,4 @@ %include "h803x.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_h803x"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_h803x) diff --git a/src/hcsr04/javaupm_hcsr04.i b/src/hcsr04/javaupm_hcsr04.i index dd7d104d..4b5e8d9f 100644 --- a/src/hcsr04/javaupm_hcsr04.i +++ b/src/hcsr04/javaupm_hcsr04.i @@ -8,14 +8,5 @@ %include "hcsr04.h" %include "hcsr04.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hcsr04"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_hcsr04) diff --git a/src/hdc1000/javaupm_hdc1000.i b/src/hdc1000/javaupm_hdc1000.i index c6ec0197..c885e378 100644 --- a/src/hdc1000/javaupm_hdc1000.i +++ b/src/hdc1000/javaupm_hdc1000.i @@ -7,13 +7,4 @@ %include "hdc1000.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hdc1000"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_hdc1000) \ No newline at end of file diff --git a/src/hdxxvxta/javaupm_hdxxvxta.i b/src/hdxxvxta/javaupm_hdxxvxta.i index 3a0d6a23..558e33c6 100644 --- a/src/hdxxvxta/javaupm_hdxxvxta.i +++ b/src/hdxxvxta/javaupm_hdxxvxta.i @@ -9,13 +9,4 @@ %include "hdxxvxta.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hdxxvxta"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_hdxxvxta) diff --git a/src/hka5/javaupm_hka5.i b/src/hka5/javaupm_hka5.i index 98e9a573..2d88955c 100644 --- a/src/hka5/javaupm_hka5.i +++ b/src/hka5/javaupm_hka5.i @@ -9,13 +9,4 @@ #include "hka5.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hka5"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_hka5) diff --git a/src/hlg150h/javaupm_hlg150h.i b/src/hlg150h/javaupm_hlg150h.i index d0904464..26d62ccb 100644 --- a/src/hlg150h/javaupm_hlg150h.i +++ b/src/hlg150h/javaupm_hlg150h.i @@ -18,13 +18,4 @@ import upm_interfaces.*; %include "hlg150h.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hlg150h"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_hlg150h) diff --git a/src/hm11/javaupm_hm11.i b/src/hm11/javaupm_hm11.i index a5fee074..3248e2ed 100644 --- a/src/hm11/javaupm_hm11.i +++ b/src/hm11/javaupm_hm11.i @@ -12,13 +12,4 @@ speed_t int_B9600 = B9600; %array_class(char, charArray); -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hm11"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_hm11) \ No newline at end of file diff --git a/src/hmc5883l/javaupm_hmc5883l.i b/src/hmc5883l/javaupm_hmc5883l.i index db43d6d9..df5cc6ea 100644 --- a/src/hmc5883l/javaupm_hmc5883l.i +++ b/src/hmc5883l/javaupm_hmc5883l.i @@ -20,13 +20,4 @@ %include "hmc5883l.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hmc5883l"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_hmc5883l) \ No newline at end of file diff --git a/src/hmtrp/javaupm_hmtrp.i b/src/hmtrp/javaupm_hmtrp.i index 6d4c4ded..35333d26 100644 --- a/src/hmtrp/javaupm_hmtrp.i +++ b/src/hmtrp/javaupm_hmtrp.i @@ -25,13 +25,4 @@ READDATA_EXCEPTION(getModSignalStrength()) %include "hmtrp.hpp" speed_t int_B9600 = B9600; -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hmtrp"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_hmtrp) diff --git a/src/hp20x/javaupm_hp20x.i b/src/hp20x/javaupm_hp20x.i index 8602c46b..eb3a7061 100644 --- a/src/hp20x/javaupm_hp20x.i +++ b/src/hp20x/javaupm_hp20x.i @@ -7,13 +7,4 @@ %include "hp20x.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hp20x"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_hp20x) \ No newline at end of file diff --git a/src/ht9170/javaupm_ht9170.i b/src/ht9170/javaupm_ht9170.i index 25fd7135..518efc1b 100644 --- a/src/ht9170/javaupm_ht9170.i +++ b/src/ht9170/javaupm_ht9170.i @@ -7,13 +7,4 @@ %include "ht9170.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ht9170"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ht9170) \ No newline at end of file diff --git a/src/htu21d/javaupm_htu21d.i b/src/htu21d/javaupm_htu21d.i index b51e7fcf..36441026 100644 --- a/src/htu21d/javaupm_htu21d.i +++ b/src/htu21d/javaupm_htu21d.i @@ -9,13 +9,4 @@ %} %include "htu21d.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_htu21d"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_htu21d) diff --git a/src/hwxpxx/javaupm_hwxpxx.i b/src/hwxpxx/javaupm_hwxpxx.i index b4311371..5e4fe95f 100644 --- a/src/hwxpxx/javaupm_hwxpxx.i +++ b/src/hwxpxx/javaupm_hwxpxx.i @@ -8,13 +8,4 @@ %include "hwxpxx.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hwxpxx"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_hwxpxx) diff --git a/src/hx711/javaupm_hx711.i b/src/hx711/javaupm_hx711.i index 1d3e9efa..38082e7f 100644 --- a/src/hx711/javaupm_hx711.i +++ b/src/hx711/javaupm_hx711.i @@ -7,13 +7,4 @@ %include "hx711.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_hx711"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_hx711) \ No newline at end of file diff --git a/src/ili9341/javaupm_ili9341.i b/src/ili9341/javaupm_ili9341.i index 6a7071b8..e628c1d3 100644 --- a/src/ili9341/javaupm_ili9341.i +++ b/src/ili9341/javaupm_ili9341.i @@ -16,13 +16,4 @@ %include "ili9341.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ili9341"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ili9341) \ No newline at end of file diff --git a/src/ims/javaupm_ims.i b/src/ims/javaupm_ims.i index 95d4df9f..6bff5154 100644 --- a/src/ims/javaupm_ims.i +++ b/src/ims/javaupm_ims.i @@ -8,13 +8,4 @@ %include "ims_defs.h" %include "ims.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ims"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ims) diff --git a/src/ina132/javaupm_ina132.i b/src/ina132/javaupm_ina132.i index affc72f5..cf4d0c5e 100644 --- a/src/ina132/javaupm_ina132.i +++ b/src/ina132/javaupm_ina132.i @@ -7,13 +7,4 @@ %include "ina132.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ina132"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ina132) \ No newline at end of file diff --git a/src/interfaces/javaupm_interfaces.i b/src/interfaces/javaupm_interfaces.i index cd582af7..3aab09ab 100644 --- a/src/interfaces/javaupm_interfaces.i +++ b/src/interfaces/javaupm_interfaces.i @@ -9,14 +9,5 @@ %include javaupm_iPressureSensor.i %include javaupm_iTemperatureSensor.i - -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_interfaces"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +%include _upm.i +JAVA_JNI_LOADLIBRARY(javaupm_interfaces) diff --git a/src/isd1820/javaupm_isd1820.i b/src/isd1820/javaupm_isd1820.i index 235c9d99..492b80f9 100644 --- a/src/isd1820/javaupm_isd1820.i +++ b/src/isd1820/javaupm_isd1820.i @@ -8,13 +8,4 @@ %include "isd1820.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_isd1820"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_isd1820) \ No newline at end of file diff --git a/src/itg3200/javaupm_itg3200.i b/src/itg3200/javaupm_itg3200.i index b11cce90..d60f8c6b 100644 --- a/src/itg3200/javaupm_itg3200.i +++ b/src/itg3200/javaupm_itg3200.i @@ -34,13 +34,4 @@ %include "itg3200.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_itg3200"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_itg3200) \ No newline at end of file diff --git a/src/jhd1313m1/javaupm_jhd1313m1.i b/src/jhd1313m1/javaupm_jhd1313m1.i index b4cc23bc..175e9947 100644 --- a/src/jhd1313m1/javaupm_jhd1313m1.i +++ b/src/jhd1313m1/javaupm_jhd1313m1.i @@ -11,13 +11,4 @@ #include "jhd1313m1.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_jhd1313m1"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_jhd1313m1) diff --git a/src/joystick12/javaupm_joystick12.i b/src/joystick12/javaupm_joystick12.i index c4ecf63b..b75cf1fc 100644 --- a/src/joystick12/javaupm_joystick12.i +++ b/src/joystick12/javaupm_joystick12.i @@ -7,13 +7,4 @@ %include "joystick12.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_joystick12"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_joystick12) \ No newline at end of file diff --git a/src/l298/javaupm_l298.i b/src/l298/javaupm_l298.i index af7fc452..94911073 100644 --- a/src/l298/javaupm_l298.i +++ b/src/l298/javaupm_l298.i @@ -7,13 +7,4 @@ %include "l298.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_l298"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_l298) \ No newline at end of file diff --git a/src/lcd/javaupm_i2clcd.i b/src/lcd/javaupm_i2clcd.i index 7c630256..3afd276f 100644 --- a/src/lcd/javaupm_i2clcd.i +++ b/src/lcd/javaupm_i2clcd.i @@ -38,13 +38,4 @@ %include "ssd1306.hpp" %include "eboled.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_i2clcd"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_i2clcd) diff --git a/src/lcdks/javaupm_lcdks.i b/src/lcdks/javaupm_lcdks.i index d560eb1d..dcc9a9eb 100644 --- a/src/lcdks/javaupm_lcdks.i +++ b/src/lcdks/javaupm_lcdks.i @@ -11,13 +11,4 @@ #include "lcdks.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lcdks"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_lcdks) diff --git a/src/lcm1602/javaupm_lcm1602.i b/src/lcm1602/javaupm_lcm1602.i index 648d2dd4..6e599fad 100644 --- a/src/lcm1602/javaupm_lcm1602.i +++ b/src/lcm1602/javaupm_lcm1602.i @@ -11,13 +11,4 @@ #include "lcm1602.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lcm1602"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_lcm1602) diff --git a/src/ldt0028/javaupm_ldt0028.i b/src/ldt0028/javaupm_ldt0028.i index c8a132a9..47244737 100644 --- a/src/ldt0028/javaupm_ldt0028.i +++ b/src/ldt0028/javaupm_ldt0028.i @@ -7,13 +7,4 @@ %include "ldt0028.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ldt0028"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ldt0028) \ No newline at end of file diff --git a/src/led/javaupm_led.i b/src/led/javaupm_led.i index 2d31bd3f..2be8ff7b 100644 --- a/src/led/javaupm_led.i +++ b/src/led/javaupm_led.i @@ -8,13 +8,4 @@ #include "led.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_led"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_led) diff --git a/src/lidarlitev3/javaupm_lidarlitev3.i b/src/lidarlitev3/javaupm_lidarlitev3.i index 15157d8f..3609d297 100644 --- a/src/lidarlitev3/javaupm_lidarlitev3.i +++ b/src/lidarlitev3/javaupm_lidarlitev3.i @@ -7,13 +7,4 @@ %include "lidarlitev3.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lidarlitev3"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_lidarlitev3) diff --git a/src/light/javaupm_light.i b/src/light/javaupm_light.i index 3a41414f..a93fb664 100644 --- a/src/light/javaupm_light.i +++ b/src/light/javaupm_light.i @@ -7,13 +7,4 @@ %include "light.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_light"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_light) \ No newline at end of file diff --git a/src/linefinder/javaupm_linefinder.i b/src/linefinder/javaupm_linefinder.i index 3851eced..957dcd9b 100644 --- a/src/linefinder/javaupm_linefinder.i +++ b/src/linefinder/javaupm_linefinder.i @@ -7,13 +7,4 @@ %include "linefinder.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_linefinder"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_linefinder) \ No newline at end of file diff --git a/src/lis2ds12/javaupm_lis2ds12.i b/src/lis2ds12/javaupm_lis2ds12.i index ed6ee92b..be636f0e 100644 --- a/src/lis2ds12/javaupm_lis2ds12.i +++ b/src/lis2ds12/javaupm_lis2ds12.i @@ -5,19 +5,18 @@ %ignore getAccelerometer(float *, float *, float *); -%include "lis2ds12_defs.h" -%include "lis2ds12.hpp" %{ #include "lis2ds12.hpp" + #include "lis2ds12_defs.h" %} +%include "lis2ds12_defs.h" +%include "lis2ds12.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lis2ds12"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} + +#%ignore installISR(LIS2DS12_INTERRUPT_PINS_T , int , mraa::Edge, void *, void *); + +%define INTERRUPT LIS2DS12_INTERRUPT_PINS_T +%enddef +JAVA_ADD_INSTALLISR_INTERRUPT(upm::LIS2DS12) + +JAVA_JNI_LOADLIBRARY(javaupm_lis2ds12) diff --git a/src/lis2ds12/lis2ds12.hpp b/src/lis2ds12/lis2ds12.hpp index e2da9ba8..fcc9b8cf 100644 --- a/src/lis2ds12/lis2ds12.hpp +++ b/src/lis2ds12/lis2ds12.hpp @@ -247,14 +247,6 @@ namespace upm { */ uint8_t getStatus(); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(LIS2DS12_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, jobject runnable) - { - installISR(intr, gpio, level, mraa_java_isr_callback, - runnable); - } -#else /** * install an interrupt handler * @@ -271,7 +263,6 @@ namespace upm { void installISR(LIS2DS12_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif /** * uninstall a previously installed interrupt handler @@ -316,12 +307,6 @@ namespace upm { /* Disable implicit copy and assignment operators */ LIS2DS12(const LIS2DS12&) = delete; LIS2DS12 &operator=(const LIS2DS12&) = delete; - - // Adding a private function definition for java bindings -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(LIS2DS12_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, - void (*isr)(void *), void *arg); -#endif + }; } diff --git a/src/lis3dh/javaupm_lis3dh.i b/src/lis3dh/javaupm_lis3dh.i index 1fe3f5dc..e40987ab 100644 --- a/src/lis3dh/javaupm_lis3dh.i +++ b/src/lis3dh/javaupm_lis3dh.i @@ -5,19 +5,18 @@ %ignore getAccelerometer(float *, float *, float *); -%include "lis3dh_defs.h" -%include "lis3dh.hpp" %{ #include "lis3dh.hpp" + #include "lis3dh_defs.h" %} +%include "lis3dh_defs.h" +%include "lis3dh.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lis3dh"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} + +%ignore installISR(LIS3DH_INTERRUPT_PINS_T , int , mraa::Edge , void *, void* ); + +%define INTERRUPT LIS3DH_INTERRUPT_PINS_T +%enddef +JAVA_ADD_INSTALLISR_INTERRUPT(upm::LIS3DH) + +JAVA_JNI_LOADLIBRARY(javaupm_lis3dh) diff --git a/src/lis3dh/lis3dh.hpp b/src/lis3dh/lis3dh.hpp index 50dd6dce..a6827db6 100644 --- a/src/lis3dh/lis3dh.hpp +++ b/src/lis3dh/lis3dh.hpp @@ -329,13 +329,6 @@ class LIS3DH */ uint8_t getStatusAux(); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void - installISR(LIS3DH_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, jobject runnable) - { - installISR(intr, gpio, level, mraa_java_isr_callback, runnable); - } -#else /** * Install an interrupt handler * @@ -354,7 +347,6 @@ class LIS3DH mraa::Edge level, void (*isr)(void*), void* arg); -#endif /** * Uninstall a previously installed interrupt handler @@ -372,13 +364,5 @@ class LIS3DH LIS3DH(const LIS3DH&) = delete; LIS3DH& operator=(const LIS3DH&) = delete; -// Adding a private function definition for Java bindings -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(LIS3DH_INTERRUPT_PINS_T intr, - int gpio, - mraa::Edge level, - void (*isr)(void*), - void* arg); -#endif }; } diff --git a/src/lm35/javaupm_lm35.i b/src/lm35/javaupm_lm35.i index 4274ed29..7f85e8c8 100644 --- a/src/lm35/javaupm_lm35.i +++ b/src/lm35/javaupm_lm35.i @@ -7,13 +7,4 @@ %include "lm35.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lm35"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_lm35) \ No newline at end of file diff --git a/src/lol/javaupm_lol.i b/src/lol/javaupm_lol.i index 2947ae7a..6ac316be 100644 --- a/src/lol/javaupm_lol.i +++ b/src/lol/javaupm_lol.i @@ -24,13 +24,4 @@ %include "lol.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lol"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_lol) \ No newline at end of file diff --git a/src/loudness/javaupm_loudness.i b/src/loudness/javaupm_loudness.i index 91e949c0..d053e626 100644 --- a/src/loudness/javaupm_loudness.i +++ b/src/loudness/javaupm_loudness.i @@ -7,13 +7,4 @@ %include "loudness.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_loudness"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_loudness) \ No newline at end of file diff --git a/src/lp8860/javaupm_lp8860.i b/src/lp8860/javaupm_lp8860.i index 7e21393a..a324a5a6 100644 --- a/src/lp8860/javaupm_lp8860.i +++ b/src/lp8860/javaupm_lp8860.i @@ -14,13 +14,4 @@ import upm_interfaces.*; %include "lp8860.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lp8860"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_lp8860) diff --git a/src/lpd8806/javaupm_lpd8806.i b/src/lpd8806/javaupm_lpd8806.i index 0faac254..dd47e540 100644 --- a/src/lpd8806/javaupm_lpd8806.i +++ b/src/lpd8806/javaupm_lpd8806.i @@ -7,13 +7,4 @@ %include "lpd8806.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lpd8806"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_lpd8806) \ No newline at end of file diff --git a/src/lsm303agr/javaupm_lsm303agr.i b/src/lsm303agr/javaupm_lsm303agr.i index f0c218b0..ad8962d0 100644 --- a/src/lsm303agr/javaupm_lsm303agr.i +++ b/src/lsm303agr/javaupm_lsm303agr.i @@ -21,19 +21,18 @@ import java.lang.Float; %template(floatVector) std::vector; -%include "lsm303agr_defs.h" -%include "lsm303agr.hpp" %{ #include "lsm303agr.hpp" + #include "lsm303agr_defs.h" %} +%include "lsm303agr_defs.h" +%include "lsm303agr.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lsm303agr"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} + +%ignore installISR(LSM303AGR_INTERRUPT_PINS_T , int , mraa::Edge , void *, void *); + +%define INTERRUPT LSM303AGR_INTERRUPT_PINS_T +%enddef +JAVA_ADD_INSTALLISR_INTERRUPT(upm::LSM303AGR) + +JAVA_JNI_LOADLIBRARY(javaupm_lsm303agr) diff --git a/src/lsm303agr/lsm303agr.hpp b/src/lsm303agr/lsm303agr.hpp index aa41a5a2..72542d07 100644 --- a/src/lsm303agr/lsm303agr.hpp +++ b/src/lsm303agr/lsm303agr.hpp @@ -303,14 +303,6 @@ namespace upm { */ uint8_t getMagnetometerIntSrc(); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(LSM303AGR_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, - jobject runnable) - { - installISR(intr, gpio, level, mraa_java_isr_callback, runnable); - } -#else /** * Install an interrupt handler * @@ -327,7 +319,6 @@ namespace upm { void installISR(LSM303AGR_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif /** * Uninstall a previously installed interrupt handler @@ -373,11 +364,5 @@ namespace upm { LSM303AGR(const LSM303AGR&) = delete; LSM303AGR &operator=(const LSM303AGR&) = delete; - // Adding a private function definition for java bindings -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(LSM303AGR_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, - void (*isr)(void *), void *arg); -#endif }; } diff --git a/src/lsm303d/javaupm_lsm303d.i b/src/lsm303d/javaupm_lsm303d.i index 399d11bc..8592d615 100644 --- a/src/lsm303d/javaupm_lsm303d.i +++ b/src/lsm303d/javaupm_lsm303d.i @@ -27,13 +27,4 @@ import java.lang.Float; #include "lsm303d.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lsm303d"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_lsm303d) diff --git a/src/lsm303dlh/javaupm_lsm303dlh.i b/src/lsm303dlh/javaupm_lsm303dlh.i index f11af5ee..a7f8066d 100644 --- a/src/lsm303dlh/javaupm_lsm303dlh.i +++ b/src/lsm303dlh/javaupm_lsm303dlh.i @@ -20,13 +20,4 @@ %include "lsm303dlh.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lsm303dlh"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_lsm303dlh) diff --git a/src/lsm6ds3h/javaupm_lsm6ds3h.i b/src/lsm6ds3h/javaupm_lsm6ds3h.i index 50f07359..f3c7e617 100644 --- a/src/lsm6ds3h/javaupm_lsm6ds3h.i +++ b/src/lsm6ds3h/javaupm_lsm6ds3h.i @@ -6,19 +6,17 @@ %ignore getAccelerometer(float *, float *, float *); %ignore getGyroscope(float *, float *, float *); -%include "lsm6ds3h_defs.h" -%include "lsm6ds3h.hpp" %{ #include "lsm6ds3h.hpp" + #include "lsm6ds3h_defs.h" %} +%include "lsm6ds3h_defs.h" +%include "lsm6ds3h.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lsm6ds3h"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +%ignore installISR(LSM6DS3H_INTERRUPT_PINS_T , int , mraa::Edge , void *, void *); + +%define INTERRUPT LSM6DS3H_INTERRUPT_PINS_T +%enddef +JAVA_ADD_INSTALLISR_INTERRUPT(upm::LSM6DS3H) + +JAVA_JNI_LOADLIBRARY(javaupm_lsm6ds3h) diff --git a/src/lsm6ds3h/lsm6ds3h.hpp b/src/lsm6ds3h/lsm6ds3h.hpp index 558c06eb..4eff1594 100644 --- a/src/lsm6ds3h/lsm6ds3h.hpp +++ b/src/lsm6ds3h/lsm6ds3h.hpp @@ -261,14 +261,6 @@ namespace upm { */ uint8_t getStatus(); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(LSM6DS3H_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, jobject runnable) - { - installISR(intr, gpio, level, mraa_java_isr_callback, - runnable); - } -#else /** * install an interrupt handler * @@ -285,7 +277,6 @@ namespace upm { void installISR(LSM6DS3H_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif /** * uninstall a previously installed interrupt handler @@ -330,11 +321,5 @@ namespace upm { LSM6DS3H(const LSM6DS3H&) = delete; LSM6DS3H &operator=(const LSM6DS3H&) = delete; - // Adding a private function definition for java bindings -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(LSM6DS3H_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, - void (*isr)(void *), void *arg); -#endif }; } diff --git a/src/lsm6dsl/javaupm_lsm6dsl.i b/src/lsm6dsl/javaupm_lsm6dsl.i index e951bd84..98d96115 100644 --- a/src/lsm6dsl/javaupm_lsm6dsl.i +++ b/src/lsm6dsl/javaupm_lsm6dsl.i @@ -6,19 +6,17 @@ %ignore getAccelerometer(float *, float *, float *); %ignore getGyroscope(float *, float *, float *); -%include "lsm6dsl_defs.h" -%include "lsm6dsl.hpp" %{ #include "lsm6dsl.hpp" + #include "lsm6dsl_defs.h" %} +%include "lsm6dsl_defs.h" +%include "lsm6dsl.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lsm6dsl"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} + +%ignore installISR(LSM6DSL_INTERRUPT_PINS_T , int , mraa::Edge , void *, void *); + +%define INTERRUPT LSM6DSL_INTERRUPT_PINS_T +%enddef +JAVA_ADD_INSTALLISR_INTERRUPT(upm::LSM6DSL) +JAVA_JNI_LOADLIBRARY(javaupm_lsm6dsl) diff --git a/src/lsm6dsl/lsm6dsl.hpp b/src/lsm6dsl/lsm6dsl.hpp index 95e6aff8..77031a0e 100644 --- a/src/lsm6dsl/lsm6dsl.hpp +++ b/src/lsm6dsl/lsm6dsl.hpp @@ -277,15 +277,6 @@ namespace upm { */ void setAccelerometerOffsets(int x, int y, int z, bool weight); - -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, jobject runnable) - { - installISR(intr, gpio, level, mraa_java_isr_callback, - runnable); - } -#else /** * install an interrupt handler * @@ -302,7 +293,6 @@ namespace upm { void installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif /** * uninstall a previously installed interrupt handler @@ -347,11 +337,5 @@ namespace upm { LSM6DSL(const LSM6DSL&) = delete; LSM6DSL &operator=(const LSM6DSL&) = delete; - // Adding a private function definition for java bindings -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio, - mraa::Edge level, - void (*isr)(void *), void *arg); -#endif }; } diff --git a/src/lsm9ds0/javaupm_lsm9ds0.i b/src/lsm9ds0/javaupm_lsm9ds0.i index a91723f4..4e2c584e 100644 --- a/src/lsm9ds0/javaupm_lsm9ds0.i +++ b/src/lsm9ds0/javaupm_lsm9ds0.i @@ -42,15 +42,24 @@ #include "lsm9ds0.hpp" %} +%ignore installISR(LSM6DSL_INTERRUPT_PINS_T , int , mraa::Edge , void *, void *); + +%extend upm::LSM9DS0 { + installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, + jobject runnable) + { + // delete any existing ISR and GPIO context + $self->uninstallISR(intr); + + // greate gpio context + getPin(intr) = new mraa::Gpio(gpio); + + getPin(intr)->dir(mraa::DIR_IN); + getPin(intr)->isr(level, runnable); + + } +} + %include "lsm9ds0.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_lsm9ds0"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_lsm9ds0) diff --git a/src/lsm9ds0/lsm9ds0.cxx b/src/lsm9ds0/lsm9ds0.cxx index b8e4f1ca..b4bfcf12 100644 --- a/src/lsm9ds0/lsm9ds0.cxx +++ b/src/lsm9ds0/lsm9ds0.cxx @@ -43,15 +43,15 @@ LSM9DS0::LSM9DS0(int bus, bool raw, uint8_t gAddress, uint8_t xmAddress) : m_accelX = 0.0; m_accelY = 0.0; m_accelZ = 0.0; - + m_gyroX = 0.0; m_gyroY = 0.0; m_gyroZ = 0.0; - + m_magX = 0.0; m_magY = 0.0; m_magZ = 0.0; - + m_temp = 0.0; m_accelScale = 0.0; @@ -68,7 +68,7 @@ LSM9DS0::LSM9DS0(int bus, bool raw, uint8_t gAddress, uint8_t xmAddress) : if ( (rv = m_i2cXM.address(m_xmAddr)) != mraa::SUCCESS) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Could not initialize XM i2c address"); return; } @@ -89,24 +89,24 @@ bool LSM9DS0::init() // power up if (!setGyroscopePowerDown(false)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to wake up gyro"); return false; } - + // enable all axes if (!setGyroscopeEnableAxes(CTRL_REG1_G_YEN |CTRL_REG1_G_XEN | CTRL_REG1_G_ZEN)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to enable gyro axes"); return false; } - + // set gyro ODR if (!setGyroscopeODR(G_ODR_95_25)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to set gyro ODR"); return false; } @@ -114,7 +114,7 @@ bool LSM9DS0::init() // set gyro scale if (!setGyroscopeScale(G_FS_245)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to set gyro scale"); return false; } @@ -124,7 +124,7 @@ bool LSM9DS0::init() // power up and set ODR if (!setAccelerometerODR(XM_AODR_100)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to set accel ODR"); return false; } @@ -133,35 +133,35 @@ bool LSM9DS0::init() if (!setAccelerometerEnableAxes(CTRL_REG1_XM_AXEN |CTRL_REG1_XM_AYEN | CTRL_REG1_XM_AZEN)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to enable accel axes"); return false; } - + // set scaling rate if (!setAccelerometerScale(XM_AFS_2)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to set accel scale"); return false; } - + // temperature sensor // enable the temperature sensor if (!enableTemperatureSensor(true)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to enable temp sensor"); return false; } // Init the magnetometer - + // set mode (this also powers it up if not XM_MD_POWERDOWN) if (!setMagnetometerMode(XM_MD_CONTINUOUS)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to set mag scale"); return false; } @@ -169,7 +169,7 @@ bool LSM9DS0::init() // turn LPM off if (!setMagnetometerLPM(false)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to disable mag LPM"); return false; } @@ -177,23 +177,23 @@ bool LSM9DS0::init() // set resolution if (!setMagnetometerResolution(XM_RES_LOW)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to set mag res"); return false; } - + // set ODR if (!setMagnetometerODR(XM_ODR_12_5)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to set mag ODR"); return false; } - + // set scale if (!setMagnetometerScale(XM_MFS_2)) { - throw std::runtime_error(string(__FUNCTION__) + + throw std::runtime_error(string(__FUNCTION__) + ": Unable to set mag scale"); return false; } @@ -293,7 +293,7 @@ uint8_t LSM9DS0::readReg(DEVICE_T dev, uint8_t reg) case DEV_GYRO: device = &m_i2cG; break; case DEV_XM: device = &m_i2cXM; break; default: - throw std::logic_error(string(__FUNCTION__) + + throw std::logic_error(string(__FUNCTION__) + ": Internal error, invalid device specified"); return 0; } @@ -310,7 +310,7 @@ void LSM9DS0::readRegs(DEVICE_T dev, uint8_t reg, uint8_t *buffer, int len) case DEV_GYRO: device = &m_i2cG; break; case DEV_XM: device = &m_i2cXM; break; default: - throw std::logic_error(string(__FUNCTION__) + + throw std::logic_error(string(__FUNCTION__) + ": Internal error, invalid device specified"); return; } @@ -329,7 +329,7 @@ bool LSM9DS0::writeReg(DEVICE_T dev, uint8_t reg, uint8_t val) case DEV_GYRO: device = &m_i2cG; break; case DEV_XM: device = &m_i2cXM; break; default: - throw std::logic_error(string(__FUNCTION__) + + throw std::logic_error(string(__FUNCTION__) + ": Internal error, invalid device specified"); return false; } @@ -340,8 +340,8 @@ bool LSM9DS0::writeReg(DEVICE_T dev, uint8_t reg, uint8_t val) throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.writeReg() failed"); return false; - } - + } + return true; } @@ -380,7 +380,7 @@ bool LSM9DS0::setGyroscopeODR(G_ODR_T odr) reg &= ~(_CTRL_REG1_G_ODR_MASK << _CTRL_REG1_G_ODR_SHIFT); reg |= (odr << _CTRL_REG1_G_ODR_SHIFT); - + return writeReg(DEV_GYRO, REG_CTRL_REG1_G, reg); } @@ -415,7 +415,7 @@ bool LSM9DS0::setGyroscopeScale(G_FS_T scale) default: // should never occur, but... m_gyroScale = 0.0; // set a safe, though incorrect value - throw std::logic_error(string(__FUNCTION__) + + throw std::logic_error(string(__FUNCTION__) + ": internal error, unsupported scale"); break; } @@ -446,7 +446,7 @@ bool LSM9DS0::setAccelerometerODR(XM_AODR_T odr) reg &= ~(_CTRL_REG1_XM_AODR_MASK << _CTRL_REG1_XM_AODR_SHIFT); reg |= (odr << _CTRL_REG1_XM_AODR_SHIFT); - + return writeReg(DEV_XM, REG_CTRL_REG1_XM, reg); } @@ -464,11 +464,11 @@ bool LSM9DS0::setAccelerometerScale(XM_AFS_T scale) } // store scaling factor - + switch (scale) { case XM_AFS_2: - m_accelScale = 0.061; + m_accelScale = 0.061; break; case XM_AFS_4: @@ -489,7 +489,7 @@ bool LSM9DS0::setAccelerometerScale(XM_AFS_T scale) default: // should never occur, but... m_accelScale = 0.0; // set a safe, though incorrect value - throw std::logic_error(string(__FUNCTION__) + + throw std::logic_error(string(__FUNCTION__) + ": internal error, unsupported scale"); break; } @@ -504,7 +504,7 @@ bool LSM9DS0::setMagnetometerResolution(XM_RES_T res) reg &= ~(_CTRL_REG5_XM_RES_MASK << _CTRL_REG5_XM_RES_SHIFT); reg |= (res << _CTRL_REG5_XM_RES_SHIFT); - + return writeReg(DEV_XM, REG_CTRL_REG5_XM, reg); } @@ -515,7 +515,7 @@ bool LSM9DS0::setMagnetometerODR(XM_ODR_T odr) reg &= ~(_CTRL_REG5_XM_ODR_MASK << _CTRL_REG5_XM_ODR_SHIFT); reg |= (odr << _CTRL_REG5_XM_ODR_SHIFT); - + return writeReg(DEV_XM, REG_CTRL_REG5_XM, reg); } @@ -526,7 +526,7 @@ bool LSM9DS0::setMagnetometerMode(XM_MD_T mode) reg &= ~(_CTRL_REG7_XM_MD_MASK << _CTRL_REG7_XM_MD_SHIFT); reg |= (mode << _CTRL_REG7_XM_MD_SHIFT); - + return writeReg(DEV_XM, REG_CTRL_REG7_XM, reg); } @@ -538,7 +538,7 @@ bool LSM9DS0::setMagnetometerLPM(bool enable) reg |= CTRL_REG7_XM_MLP; else reg &= ~CTRL_REG7_XM_MLP; - + return writeReg(DEV_XM, REG_CTRL_REG7_XM, reg); } @@ -556,7 +556,7 @@ bool LSM9DS0::setMagnetometerScale(XM_MFS_T scale) } // store scaling factor - + switch (scale) { case XM_MFS_2: @@ -577,7 +577,7 @@ bool LSM9DS0::setMagnetometerScale(XM_MFS_T scale) default: // should never occur, but... m_magScale = 0.0; // set a safe, though incorrect value - throw std::logic_error(string(__FUNCTION__) + + throw std::logic_error(string(__FUNCTION__) + ": internal error, unsupported scale"); break; } @@ -741,22 +741,8 @@ uint8_t LSM9DS0::getInterruptGen2Src() return readReg(DEV_XM, REG_INT_GEN_2_SRC); } -#if defined(SWIGJAVA) || defined (JAVACALLBACK) + void LSM9DS0::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, - jobject runnable) -{ - // delete any existing ISR and GPIO context - uninstallISR(intr); - - // greate gpio context - getPin(intr) = new mraa::Gpio(gpio); - - getPin(intr)->dir(mraa::DIR_IN); - getPin(intr)->isr(level, runnable); - -} -#else -void LSM9DS0::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void (*isr)(void *), void *arg) { // delete any existing ISR and GPIO context @@ -768,7 +754,7 @@ void LSM9DS0::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, getPin(intr)->dir(mraa::DIR_IN); getPin(intr)->isr(level, isr, arg); } -#endif + void LSM9DS0::uninstallISR(INTERRUPT_PINS_T intr) { @@ -776,7 +762,7 @@ void LSM9DS0::uninstallISR(INTERRUPT_PINS_T intr) { getPin(intr)->isrExit(); delete getPin(intr); - + getPin(intr) = 0; } } diff --git a/src/lsm9ds0/lsm9ds0.hpp b/src/lsm9ds0/lsm9ds0.hpp index 3d8169f0..bb49e4c3 100644 --- a/src/lsm9ds0/lsm9ds0.hpp +++ b/src/lsm9ds0/lsm9ds0.hpp @@ -34,7 +34,7 @@ #define LSM9DS0_DEFAULT_GYRO_ADDR 0x6b namespace upm { - + /** * @brief LSM9DS0 accelerometer library * @defgroup lsm9ds0 libupm-lsm9ds0 @@ -50,7 +50,7 @@ namespace upm { * @con i2c gpio * @web https://www.sparkfun.com/products/13033 * - * @brief API for the LSM9DS0 3-axis Gyroscope, Accelerometer, + * @brief API for the LSM9DS0 3-axis Gyroscope, Accelerometer, * and Magnetometer * * The LSM9DS0 is a system-in-package featuring a 3D digital linear @@ -109,13 +109,13 @@ namespace upm { REG_STATUS_REG_G = 0x27, - REG_OUT_X_L_G = 0x28, // gyro output, X axis, LSB - REG_OUT_X_H_G = 0x29, // gyro output, X axis, MSB + REG_OUT_X_L_G = 0x28, // gyro output, X axis, LSB + REG_OUT_X_H_G = 0x29, // gyro output, X axis, MSB REG_OUT_Y_L_G = 0x2a, REG_OUT_Y_H_G = 0x2b, REG_OUT_Z_L_G = 0x2c, REG_OUT_Z_H_G = 0x2d, - + REG_FIFO_CTRL_REG_G = 0x2e, REG_FIFO_SRC_REG_G = 0x2f, @@ -133,14 +133,14 @@ namespace upm { // on how to use this register REG_INT1_DURATION_G = 0x38 } REG_G_T; - + /** * Gyro CTRL_REG1_G bits */ typedef enum { CTRL_REG1_G_YEN = 0x01, // Y enable, odd ordering... - CTRL_REG1_G_XEN = 0x02, - CTRL_REG1_G_ZEN = 0x04, + CTRL_REG1_G_XEN = 0x02, + CTRL_REG1_G_ZEN = 0x04, CTRL_REG1_G_PD = 0x08, // power down (0) CTRL_REG1_G_BW0 = 0x10, // bandwidth @@ -328,7 +328,7 @@ namespace upm { CTRL_REG5_G_BOOT = 0x80 // reboot memory content } CTRL_REG5_G_BITS_T; - + /** * CRTL_REG5_G_OUTSEL and INT1SEL values. See Figure 18 in the * datasheet. @@ -366,7 +366,7 @@ namespace upm { FIFO_CTRL_REG_G_WTM4 = 0x10, _FIFO_CTRL_REG_G_WTM_MASK = 31, _FIFO_CTRL_REG_G_WTM_SHIFT = 0, - + FIFO_CTRL_REG_G_FM0 = 0x20, // FIFO mode config FIFO_CTRL_REG_G_FM1 = 0x40, FIFO_CTRL_REG_G_FM2 = 0x80, @@ -524,7 +524,7 @@ namespace upm { REG_TIME_LIMIT = 0x3b, REG_TIME_LATENCY = 0x3c, REG_TIME_WINDOW = 0x3d, - + REG_ACT_THS = 0x3e, REG_ACT_DUR = 0x3f } REG_XM_T; @@ -552,7 +552,7 @@ namespace upm { INT_CTRL_REG_M_4D = 0x02, INT_CTRL_REG_M_IEL = 0x04, // latch intr request INT_CTRL_REG_M_IEA = 0x08, - INT_CTRL_REG_M_PP_OD = 0x10, // push-pull/open drian + INT_CTRL_REG_M_PP_OD = 0x10, // push-pull/open drian INT_CTRL_REG_M_ZMIEN = 0x20, // Z mag axis interrupt recognition INT_CTRL_REG_M_YMIEN = 0x40, INT_CTRL_REG_M_XMIEN = 0x80 @@ -600,7 +600,7 @@ namespace upm { CTRL_REG1_XM_BDU = 0x04, // block data update CTRL_REG1_XM_AODR0 = 0x10, // accelerometer output data rate - CTRL_REG1_XM_AODR1 = 0x20, + CTRL_REG1_XM_AODR1 = 0x20, CTRL_REG1_XM_AODR2 = 0x40, CTRL_REG1_XM_AODR3 = 0x80, _CTRL_REG1_XM_AODR_MASK = 15, @@ -624,7 +624,7 @@ namespace upm { XM_AODR_1000 = 10 // 11-15 unused } XM_AODR_T; - + /** * CTRL_REG2_XM bits */ @@ -740,7 +740,7 @@ namespace upm { XM_ODR_25 = 3, XM_ODR_50 = 4, XM_ODR_100 = 5 - + // 6, 7 reserved } XM_ODR_T; @@ -749,9 +749,9 @@ namespace upm { */ typedef enum { XM_RES_LOW = 0, // low resolution - + // 1, 2 reserved - + XM_RES_HIGH = 3, } XM_RES_T; @@ -850,7 +850,7 @@ namespace upm { FIFO_CTRL_REG_FTH4 = 0x10, _FIFO_CTRL_REG_FTH_MASK = 31, _FIFO_CTRL_REG_FTH_SHIFT = 0, - + FIFO_CTRL_REG_FM0 = 0x20, // FIFO mode config FIFO_CTRL_REG_FM1 = 0x40, FIFO_CTRL_REG_FM2 = 0x80, @@ -970,7 +970,7 @@ namespace upm { CLICK_CONFIG_ZD = 0x20 // 0x40, 0x80 reserved } CLICK_CONFIG_BITS_T; - + /** * CLICK_SRC bits * @@ -1072,7 +1072,7 @@ namespace upm { * LSM9DS0 Destructor */ ~LSM9DS0(); - + /** * set up initial values and start operation * @@ -1416,10 +1416,7 @@ namespace upm { */ uint8_t getInterruptGen2Src(); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, - jobject runnable); -#else + /** * install an interrupt handler. * @@ -1432,9 +1429,9 @@ namespace upm { * @param isr the interrupt handler, accepting a void * argument * @param arg the argument to pass the the interrupt handler */ - void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, + void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif + /** * uninstall a previously installed interrupt handler * @@ -1486,5 +1483,3 @@ namespace upm { mraa::Gpio *m_gpioXM_GEN2; }; } - - diff --git a/src/m24lr64e/javaupm_m24lr64e.i b/src/m24lr64e/javaupm_m24lr64e.i index 048e1883..09fc1e7f 100644 --- a/src/m24lr64e/javaupm_m24lr64e.i +++ b/src/m24lr64e/javaupm_m24lr64e.i @@ -25,13 +25,4 @@ %include "m24lr64e.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_m24lr64e"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_m24lr64e) \ No newline at end of file diff --git a/src/mag3110/javaupm_mag3110.i b/src/mag3110/javaupm_mag3110.i index 109de91f..cdc25c23 100644 --- a/src/mag3110/javaupm_mag3110.i +++ b/src/mag3110/javaupm_mag3110.i @@ -7,13 +7,4 @@ %include "mag3110.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mag3110"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mag3110) \ No newline at end of file diff --git a/src/max30100/javaupm_max30100.i b/src/max30100/javaupm_max30100.i index 362c3f4e..ecf83532 100644 --- a/src/max30100/javaupm_max30100.i +++ b/src/max30100/javaupm_max30100.i @@ -17,13 +17,4 @@ %include "max30100_regs.h" %include "max30100.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_max30100"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_max30100) diff --git a/src/max31723/javaupm_max31723.i b/src/max31723/javaupm_max31723.i index c4a6a0b2..57d23547 100644 --- a/src/max31723/javaupm_max31723.i +++ b/src/max31723/javaupm_max31723.i @@ -7,13 +7,4 @@ %include "max31723.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_max31723"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_max31723) \ No newline at end of file diff --git a/src/max31855/javaupm_max31855.i b/src/max31855/javaupm_max31855.i index 17bbdc50..8561629d 100644 --- a/src/max31855/javaupm_max31855.i +++ b/src/max31855/javaupm_max31855.i @@ -9,13 +9,4 @@ %include "max31855.hpp" //! [Interesting] -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_max31855"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_max31855) \ No newline at end of file diff --git a/src/max44000/javaupm_max44000.i b/src/max44000/javaupm_max44000.i index b4080d6e..afe29a11 100644 --- a/src/max44000/javaupm_max44000.i +++ b/src/max44000/javaupm_max44000.i @@ -7,13 +7,4 @@ %include "max44000.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_max44000"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_max44000) \ No newline at end of file diff --git a/src/max44009/javaupm_max44009.i b/src/max44009/javaupm_max44009.i index cc788a96..ffa43057 100644 --- a/src/max44009/javaupm_max44009.i +++ b/src/max44009/javaupm_max44009.i @@ -18,13 +18,4 @@ import upm_interfaces.*; %include "max44009.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_max44009"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_max44009) diff --git a/src/max5487/javaupm_max5487.i b/src/max5487/javaupm_max5487.i index e5873b44..0b76385f 100644 --- a/src/max5487/javaupm_max5487.i +++ b/src/max5487/javaupm_max5487.i @@ -7,13 +7,4 @@ %include "max5487.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_max5487"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_max5487) \ No newline at end of file diff --git a/src/maxds3231m/javaupm_maxds3231m.i b/src/maxds3231m/javaupm_maxds3231m.i index a7a6801c..7177e14d 100644 --- a/src/maxds3231m/javaupm_maxds3231m.i +++ b/src/maxds3231m/javaupm_maxds3231m.i @@ -7,13 +7,4 @@ %include "maxds3231m.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_maxds3231m"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_maxds3231m) \ No newline at end of file diff --git a/src/maxsonarez/javaupm_maxsonarez.i b/src/maxsonarez/javaupm_maxsonarez.i index 6c56b8b7..b9e84b7d 100644 --- a/src/maxsonarez/javaupm_maxsonarez.i +++ b/src/maxsonarez/javaupm_maxsonarez.i @@ -7,13 +7,4 @@ %include "maxsonarez.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_maxsonarez"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_maxsonarez) \ No newline at end of file diff --git a/src/mb704x/javaupm_mb704x.i b/src/mb704x/javaupm_mb704x.i index 0c80da73..81b01068 100644 --- a/src/mb704x/javaupm_mb704x.i +++ b/src/mb704x/javaupm_mb704x.i @@ -9,13 +9,4 @@ #include "mb704x.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mb704x"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_mb704x) diff --git a/src/mcp2515/javaupm_mcp2515.i b/src/mcp2515/javaupm_mcp2515.i index c6fe1d64..3a696446 100644 --- a/src/mcp2515/javaupm_mcp2515.i +++ b/src/mcp2515/javaupm_mcp2515.i @@ -5,20 +5,14 @@ %include "../java_buffer.i" %include "std_string.i" -%include "mcp2515_regs.h" -%include "mcp2515.hpp" %{ #include "mcp2515.hpp" + #include "mcp2515_regs.h" %} +%include "mcp2515_regs.h" +%include "mcp2515.hpp" +%ignore installISR(int pin, void *, void *); -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mcp2515"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_ADD_INSTALLISR_PIN(upm::MCP2515) +JAVA_JNI_LOADLIBRARY(javaupm_mcp2515) diff --git a/src/mcp2515/mcp2515.hpp b/src/mcp2515/mcp2515.hpp index e465f205..ce6ce5f6 100644 --- a/src/mcp2515/mcp2515.hpp +++ b/src/mcp2515/mcp2515.hpp @@ -324,12 +324,7 @@ namespace upm { return std::string((char *)m_message.pkt.data, m_message.len); } -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(int pin, jobject runnable) - { - installISR(pin, mraa_java_isr_callback, runnable); - } -#else + /** * Installs an interrupt service routine (ISR) to be called when * an interrupt occurs. @@ -340,7 +335,7 @@ namespace upm { * argument to the ISR. */ void installISR(int pin, void (*isr)(void *), void *arg); -#endif + /** * Uninstalls the previously installed ISR @@ -518,9 +513,5 @@ namespace upm { /* Disable implicit copy and assignment operators */ MCP2515(const MCP2515&) = delete; MCP2515 &operator=(const MCP2515&) = delete; - -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(int pin, void (*isr)(void *), void *arg); -#endif }; } diff --git a/src/mcp9808/javaupm_mcp9808.i b/src/mcp9808/javaupm_mcp9808.i index 1e5e5c88..bbad4576 100644 --- a/src/mcp9808/javaupm_mcp9808.i +++ b/src/mcp9808/javaupm_mcp9808.i @@ -7,13 +7,4 @@ %include "mcp9808.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mcp9808"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mcp9808) \ No newline at end of file diff --git a/src/md/javaupm_md.i b/src/md/javaupm_md.i index 2aea9854..9d048039 100644 --- a/src/md/javaupm_md.i +++ b/src/md/javaupm_md.i @@ -8,13 +8,4 @@ %include "md_defs.h" %include "md.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_md"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_md) diff --git a/src/mg811/javaupm_mg811.i b/src/mg811/javaupm_mg811.i index 574fa795..7a1cda24 100644 --- a/src/mg811/javaupm_mg811.i +++ b/src/mg811/javaupm_mg811.i @@ -7,13 +7,4 @@ %include "mg811.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mg811"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mg811) \ No newline at end of file diff --git a/src/mhz16/javaupm_mhz16.i b/src/mhz16/javaupm_mhz16.i index 3be6f6c8..cc5da80d 100644 --- a/src/mhz16/javaupm_mhz16.i +++ b/src/mhz16/javaupm_mhz16.i @@ -15,13 +15,4 @@ %include "mhz16.hpp" speed_t int_B9600 = B9600; -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mhz16"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mhz16) \ No newline at end of file diff --git a/src/mic/javaupm_mic.i b/src/mic/javaupm_mic.i index fb7965d9..294a8e9b 100644 --- a/src/mic/javaupm_mic.i +++ b/src/mic/javaupm_mic.i @@ -39,13 +39,4 @@ %include "mic.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mic"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mic) \ No newline at end of file diff --git a/src/micsv89/javaupm_micsv89.i b/src/micsv89/javaupm_micsv89.i index e904570d..6e3f96eb 100644 --- a/src/micsv89/javaupm_micsv89.i +++ b/src/micsv89/javaupm_micsv89.i @@ -7,13 +7,4 @@ %include "micsv89.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_micsv89"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_micsv89) \ No newline at end of file diff --git a/src/mlx90614/javaupm_mlx90614.i b/src/mlx90614/javaupm_mlx90614.i index dddd6998..24dbb20e 100644 --- a/src/mlx90614/javaupm_mlx90614.i +++ b/src/mlx90614/javaupm_mlx90614.i @@ -7,13 +7,4 @@ %include "mlx90614.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mlx90614"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mlx90614) \ No newline at end of file diff --git a/src/mma7361/javaupm_mma7361.i b/src/mma7361/javaupm_mma7361.i index 5c165723..5d617d7d 100644 --- a/src/mma7361/javaupm_mma7361.i +++ b/src/mma7361/javaupm_mma7361.i @@ -41,13 +41,4 @@ #include "mma7361.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mma7361"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_mma7361) diff --git a/src/mma7455/javaupm_mma7455.i b/src/mma7455/javaupm_mma7455.i index 44b50f93..e1c97004 100644 --- a/src/mma7455/javaupm_mma7455.i +++ b/src/mma7455/javaupm_mma7455.i @@ -28,13 +28,4 @@ %include "mma7455.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mma7455"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mma7455) \ No newline at end of file diff --git a/src/mma7660/javaupm_mma7660.i b/src/mma7660/javaupm_mma7660.i index 4c43256d..c64cdc44 100644 --- a/src/mma7660/javaupm_mma7660.i +++ b/src/mma7660/javaupm_mma7660.i @@ -35,22 +35,18 @@ JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const signed int*)$1); } + %ignore getRawValues(int *, int *, int *); %ignore getAcceleration(float *, float *, float *); -%include "mma7660_regs.h" -%include "mma7660.hpp" %{ #include "mma7660.hpp" + #include "mma7660_regs.h" %} +%include "mma7660_regs.h" +%include "mma7660.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mma7660"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +%ignore installISR(int , void *, void *); + +JAVA_ADD_INSTALLISR_PIN(upm::MMA7660) +JAVA_JNI_LOADLIBRARY(javaupm_mma7660) diff --git a/src/mma7660/mma7660.hpp b/src/mma7660/mma7660.hpp index 7fd16225..65cee185 100644 --- a/src/mma7660/mma7660.hpp +++ b/src/mma7660/mma7660.hpp @@ -225,12 +225,7 @@ namespace upm { getRawValues(&values[0], &values[1], &values[2]); return values; } - - void installISR(int pin, jobject runnable) - { - installISR(pin, mraa_java_isr_callback, runnable); - } -#else +#endif /** * Installs an interrupt service routine (ISR) to be called when * an interrupt occurs @@ -241,7 +236,6 @@ namespace upm { * argument to the ISR. */ void installISR(int pin, void (*isr)(void *), void *arg); -#endif // defined(SWIGJAVA) || defined(JAVACALLBACK) protected: mma7660_context m_mma7660; @@ -251,9 +245,5 @@ namespace upm { MMA7660(const MMA7660&) = delete; MMA7660 &operator=(const MMA7660&) = delete; -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(int pin, void (*isr)(void *), void *arg); -#endif - }; } diff --git a/src/mma8x5x/javaupm_mma8x5x.i b/src/mma8x5x/javaupm_mma8x5x.i index 15597374..5dffbf6d 100644 --- a/src/mma8x5x/javaupm_mma8x5x.i +++ b/src/mma8x5x/javaupm_mma8x5x.i @@ -7,13 +7,4 @@ %include "mma8x5x.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mma8x5x"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mma8x5x) \ No newline at end of file diff --git a/src/moisture/javaupm_moisture.i b/src/moisture/javaupm_moisture.i index c5a4f1f2..750063c5 100644 --- a/src/moisture/javaupm_moisture.i +++ b/src/moisture/javaupm_moisture.i @@ -7,13 +7,4 @@ %include "moisture.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_moisture"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_moisture) \ No newline at end of file diff --git a/src/mpl3115a2/javaupm_mpl3115a2.i b/src/mpl3115a2/javaupm_mpl3115a2.i index 5c1f3d39..02950ee5 100644 --- a/src/mpl3115a2/javaupm_mpl3115a2.i +++ b/src/mpl3115a2/javaupm_mpl3115a2.i @@ -7,13 +7,4 @@ %include "mpl3115a2.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mpl3115a2"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mpl3115a2) \ No newline at end of file diff --git a/src/mpr121/javaupm_mpr121.i b/src/mpr121/javaupm_mpr121.i index 7e2a7ee9..5dd0f36e 100644 --- a/src/mpr121/javaupm_mpr121.i +++ b/src/mpr121/javaupm_mpr121.i @@ -9,13 +9,4 @@ %include "mpr121.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mpr121"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mpr121) \ No newline at end of file diff --git a/src/mpu9150/javaupm_mpu9150.i b/src/mpu9150/javaupm_mpu9150.i index 012afab4..35174f5e 100644 --- a/src/mpu9150/javaupm_mpu9150.i +++ b/src/mpu9150/javaupm_mpu9150.i @@ -33,13 +33,10 @@ %include "mpu60x0.hpp" %include "mpu9150.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mpu9150"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +%ignore installISR(int , mraa::Edge , void *, void *); + +%define GETTER get_gpioIRQ() +%enddef +JAVA_ADD_INSTALLISR_GPIO(upm::MPU60X0) + +JAVA_JNI_LOADLIBRARY(javaupm_mpu9150) diff --git a/src/mpu9150/mpu60x0.cxx b/src/mpu9150/mpu60x0.cxx index 7962c380..9ccde924 100644 --- a/src/mpu9150/mpu60x0.cxx +++ b/src/mpu9150/mpu60x0.cxx @@ -40,11 +40,11 @@ MPU60X0::MPU60X0(int bus, uint8_t address) : m_accelX = 0.0; m_accelY = 0.0; m_accelZ = 0.0; - + m_gyroX = 0.0; m_gyroY = 0.0; m_gyroZ = 0.0; - + m_temp = 0.0; m_accelScale = 1.0; @@ -154,8 +154,8 @@ bool MPU60X0::writeReg(uint8_t reg, uint8_t val) throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.writeReg() failed"); return false; - } - + } + return true; } @@ -217,7 +217,7 @@ bool MPU60X0::setGyroscopeScale(FS_SEL_T scale) default: // should never occur, but... m_gyroScale = 1.0; // set a safe, though incorrect value - throw std::logic_error(string(__FUNCTION__) + + throw std::logic_error(string(__FUNCTION__) + ": internal error, unsupported scale"); break; } @@ -239,7 +239,7 @@ bool MPU60X0::setAccelerometerScale(AFS_SEL_T scale) } // store scaling factor - + switch (scale) { case AFS_2: @@ -260,7 +260,7 @@ bool MPU60X0::setAccelerometerScale(AFS_SEL_T scale) default: // should never occur, but... m_accelScale = 1.0; // set a safe, though incorrect value - throw std::logic_error(string(__FUNCTION__) + + throw std::logic_error(string(__FUNCTION__) + ": internal error, unsupported scale"); break; } @@ -384,21 +384,8 @@ uint8_t MPU60X0::getInterruptPinConfig() return readReg(REG_INT_PIN_CFG); } -#if defined(SWIGJAVA) || defined(JAVACALLBACK) + void MPU60X0::installISR(int gpio, mraa::Edge level, - jobject runnable) -{ - // delete any existing ISR and GPIO context - uninstallISR(); - - // greate gpio context - m_gpioIRQ = new mraa::Gpio(gpio); - - m_gpioIRQ->dir(mraa::DIR_IN); - m_gpioIRQ->isr(level, runnable); -} -#else -void MPU60X0::installISR(int gpio, mraa::Edge level, void (*isr)(void *), void *arg) { // delete any existing ISR and GPIO context @@ -410,7 +397,7 @@ void MPU60X0::installISR(int gpio, mraa::Edge level, m_gpioIRQ->dir(mraa::DIR_IN); m_gpioIRQ->isr(level, isr, arg); } -#endif + void MPU60X0::uninstallISR() { @@ -418,7 +405,12 @@ void MPU60X0::uninstallISR() { m_gpioIRQ->isrExit(); delete m_gpioIRQ; - + m_gpioIRQ = 0; } } + + mraa::Gpio* MPU60X0::get_gpioIRQ() + { + return m_gpioIRQ; + } diff --git a/src/mpu9150/mpu60x0.hpp b/src/mpu9150/mpu60x0.hpp index 4efe41d7..91d7aa03 100644 --- a/src/mpu9150/mpu60x0.hpp +++ b/src/mpu9150/mpu60x0.hpp @@ -901,11 +901,8 @@ namespace upm { * @param isr the interrupt handler, accepting a void * argument * @param arg the argument to pass the the interrupt handler */ -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(int gpio, mraa::Edge level, jobject runnable); -#else + void installISR(int gpio, mraa::Edge level, void (*isr)(void *), void *arg); -#endif /** * uninstall a previously installed interrupt handler @@ -913,6 +910,8 @@ namespace upm { */ void uninstallISR(); + mraa::Gpio* get_gpioIRQ(); + protected: // uncompensated accelerometer and gyroscope values float m_accelX; @@ -942,5 +941,3 @@ namespace upm { mraa::Gpio *m_gpioIRQ; }; } - - diff --git a/src/mq303a/javaupm_mq303a.i b/src/mq303a/javaupm_mq303a.i index d6aa0dc4..3ddf5a80 100644 --- a/src/mq303a/javaupm_mq303a.i +++ b/src/mq303a/javaupm_mq303a.i @@ -7,13 +7,4 @@ %include "mq303a.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_mq303a"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_mq303a) \ No newline at end of file diff --git a/src/ms5611/javaupm_ms5611.i b/src/ms5611/javaupm_ms5611.i index 3ef03e02..a177d41d 100644 --- a/src/ms5611/javaupm_ms5611.i +++ b/src/ms5611/javaupm_ms5611.i @@ -14,13 +14,4 @@ import upm_interfaces.*; %include "ms5611.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ms5611"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ms5611) diff --git a/src/ms5803/javaupm_ms5803.i b/src/ms5803/javaupm_ms5803.i index 1bc6aa73..8554e494 100644 --- a/src/ms5803/javaupm_ms5803.i +++ b/src/ms5803/javaupm_ms5803.i @@ -12,13 +12,4 @@ %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ms5803"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ms5803) diff --git a/src/my9221/javaupm_my9221.i b/src/my9221/javaupm_my9221.i index cb98ab26..8bda1c70 100644 --- a/src/my9221/javaupm_my9221.i +++ b/src/my9221/javaupm_my9221.i @@ -16,13 +16,4 @@ #include "grovecircularled.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_my9221"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_my9221) diff --git a/src/nlgpio16/javaupm_nlgpio16.i b/src/nlgpio16/javaupm_nlgpio16.i index f741c3ad..04f28031 100644 --- a/src/nlgpio16/javaupm_nlgpio16.i +++ b/src/nlgpio16/javaupm_nlgpio16.i @@ -10,13 +10,4 @@ %include "nlgpio16.hpp" %array_class(char, charArray); -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_nlgpio16"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_nlgpio16) diff --git a/src/nmea_gps/javaupm_nmea_gps.i b/src/nmea_gps/javaupm_nmea_gps.i index a80b311a..c2fea16d 100644 --- a/src/nmea_gps/javaupm_nmea_gps.i +++ b/src/nmea_gps/javaupm_nmea_gps.i @@ -9,13 +9,4 @@ #include "nmea_gps.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_nmea_gps"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_nmea_gps) diff --git a/src/nrf24l01/javaupm_nrf24l01.i b/src/nrf24l01/javaupm_nrf24l01.i index 92543d5c..a4fb2c9b 100644 --- a/src/nrf24l01/javaupm_nrf24l01.i +++ b/src/nrf24l01/javaupm_nrf24l01.i @@ -19,13 +19,4 @@ %include "nrf24l01.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_nrf24l01"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_nrf24l01) diff --git a/src/nunchuck/javaupm_nunchuck.i b/src/nunchuck/javaupm_nunchuck.i index 57b0d92b..7806787e 100644 --- a/src/nunchuck/javaupm_nunchuck.i +++ b/src/nunchuck/javaupm_nunchuck.i @@ -8,13 +8,4 @@ %include "nunchuck.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_nunchuck"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_nunchuck) \ No newline at end of file diff --git a/src/o2/javaupm_o2.i b/src/o2/javaupm_o2.i index d4c93fcb..7be25969 100644 --- a/src/o2/javaupm_o2.i +++ b/src/o2/javaupm_o2.i @@ -7,13 +7,4 @@ %include "o2.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_o2"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_o2) \ No newline at end of file diff --git a/src/otp538u/javaupm_otp538u.i b/src/otp538u/javaupm_otp538u.i index 455c6c5c..914c6120 100644 --- a/src/otp538u/javaupm_otp538u.i +++ b/src/otp538u/javaupm_otp538u.i @@ -7,13 +7,4 @@ %include "otp538u.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_otp538u"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_otp538u) \ No newline at end of file diff --git a/src/ozw/javaupm_ozw.i b/src/ozw/javaupm_ozw.i index c09c05a3..32d45821 100644 --- a/src/ozw/javaupm_ozw.i +++ b/src/ozw/javaupm_ozw.i @@ -47,13 +47,4 @@ #include "tzemt400.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ozw"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ozw) diff --git a/src/p9813/javaupm_p9813.i b/src/p9813/javaupm_p9813.i index 1d422c5c..a0f35742 100644 --- a/src/p9813/javaupm_p9813.i +++ b/src/p9813/javaupm_p9813.i @@ -8,13 +8,4 @@ %} %include "p9813.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_p9813"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_p9813) diff --git a/src/pca9685/javaupm_pca9685.i b/src/pca9685/javaupm_pca9685.i index ccca3fc8..e2468da1 100644 --- a/src/pca9685/javaupm_pca9685.i +++ b/src/pca9685/javaupm_pca9685.i @@ -8,13 +8,4 @@ %include "pca9685.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_pca9685"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_pca9685) \ No newline at end of file diff --git a/src/pn532/javaupm_pn532.i b/src/pn532/javaupm_pn532.i index a833817d..799cbb37 100644 --- a/src/pn532/javaupm_pn532.i +++ b/src/pn532/javaupm_pn532.i @@ -15,13 +15,4 @@ %include "pn532.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_pn532"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_pn532) \ No newline at end of file diff --git a/src/ppd42ns/javaupm_ppd42ns.i b/src/ppd42ns/javaupm_ppd42ns.i index 907ca299..168e702d 100644 --- a/src/ppd42ns/javaupm_ppd42ns.i +++ b/src/ppd42ns/javaupm_ppd42ns.i @@ -8,13 +8,4 @@ %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ppd42ns"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ppd42ns) diff --git a/src/pulsensor/javaupm_pulsensor.i b/src/pulsensor/javaupm_pulsensor.i index e69289f3..ca62cde4 100644 --- a/src/pulsensor/javaupm_pulsensor.i +++ b/src/pulsensor/javaupm_pulsensor.i @@ -24,13 +24,4 @@ %include "pulsensor.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_pulsensor"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_pulsensor) diff --git a/src/relay/javaupm_relay.i b/src/relay/javaupm_relay.i index 4b8e7e8f..a8e3b1d7 100644 --- a/src/relay/javaupm_relay.i +++ b/src/relay/javaupm_relay.i @@ -7,13 +7,4 @@ %include "relay.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_relay"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_relay) diff --git a/src/rf22/javaupm_rf22.i b/src/rf22/javaupm_rf22.i index f5abf195..d7d39a40 100644 --- a/src/rf22/javaupm_rf22.i +++ b/src/rf22/javaupm_rf22.i @@ -17,13 +17,4 @@ %include "rf22.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_rf22"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_rf22) diff --git a/src/rfr359f/javaupm_rfr359f.i b/src/rfr359f/javaupm_rfr359f.i index ce2e2eef..98a76f6f 100644 --- a/src/rfr359f/javaupm_rfr359f.i +++ b/src/rfr359f/javaupm_rfr359f.i @@ -7,13 +7,4 @@ %include "rfr359f.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_rfr359f"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_rfr359f) \ No newline at end of file diff --git a/src/rgbringcoder/javaupm_rgbringcoder.i b/src/rgbringcoder/javaupm_rgbringcoder.i index 42109154..6b7758d9 100644 --- a/src/rgbringcoder/javaupm_rgbringcoder.i +++ b/src/rgbringcoder/javaupm_rgbringcoder.i @@ -7,13 +7,4 @@ %include "rgbringcoder.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_rgbringcoder"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_rgbringcoder) \ No newline at end of file diff --git a/src/rhusb/javaupm_rhusb.i b/src/rhusb/javaupm_rhusb.i index c6a600cf..779b735e 100644 --- a/src/rhusb/javaupm_rhusb.i +++ b/src/rhusb/javaupm_rhusb.i @@ -11,13 +11,4 @@ %include "rhusb.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_rhusb"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_rhusb) diff --git a/src/rn2903/javaupm_rn2903.i b/src/rn2903/javaupm_rn2903.i index 104fe35a..afab2970 100644 --- a/src/rn2903/javaupm_rn2903.i +++ b/src/rn2903/javaupm_rn2903.i @@ -10,13 +10,4 @@ #include "rn2903.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_rn2903"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_rn2903) diff --git a/src/rotary/javaupm_rotary.i b/src/rotary/javaupm_rotary.i index c7c774e1..d78d7379 100644 --- a/src/rotary/javaupm_rotary.i +++ b/src/rotary/javaupm_rotary.i @@ -7,13 +7,4 @@ %include "rotary.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_rotary"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_rotary) diff --git a/src/rotaryencoder/javaupm_rotaryencoder.i b/src/rotaryencoder/javaupm_rotaryencoder.i index 404df455..29285736 100644 --- a/src/rotaryencoder/javaupm_rotaryencoder.i +++ b/src/rotaryencoder/javaupm_rotaryencoder.i @@ -9,13 +9,4 @@ %include "rotaryencoder.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_rotaryencoder"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_rotaryencoder) \ No newline at end of file diff --git a/src/rpr220/javaupm_rpr220.i b/src/rpr220/javaupm_rpr220.i index ec4b3003..7c5fb42b 100644 --- a/src/rpr220/javaupm_rpr220.i +++ b/src/rpr220/javaupm_rpr220.i @@ -7,13 +7,6 @@ %} %include "rpr220.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_rpr220"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_rpr220) + +JAVA_ADD_INSTALLISR(upm::RPR220) diff --git a/src/rpr220/rpr220.cxx b/src/rpr220/rpr220.cxx index 9f14257d..a8b503f7 100644 --- a/src/rpr220/rpr220.cxx +++ b/src/rpr220/rpr220.cxx @@ -49,12 +49,7 @@ bool RPR220::blackDetected() return rpr220_black_detected(m_rpr220); } -#ifdef JAVACALLBACK -void RPR220::installISR(jobject runnable) -{ - installISR(mraa_java_isr_callback, runnable); -} -#endif + void RPR220::installISR(void (*isr)(void *), void *arg) { @@ -65,4 +60,3 @@ void RPR220::uninstallISR() { rpr220_uninstall_isr(m_rpr220); } - diff --git a/src/rpr220/rpr220.hpp b/src/rpr220/rpr220.hpp index 0eaeb87b..29503bc4 100644 --- a/src/rpr220/rpr220.hpp +++ b/src/rpr220/rpr220.hpp @@ -83,9 +83,7 @@ namespace upm { */ bool blackDetected(); -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(jobject runnable); -#else + /** * Installs an ISR to be called when * black is detected @@ -95,7 +93,6 @@ namespace upm { * argument to the ISR. */ void installISR(void (*isr)(void *), void *arg); -#endif /** * Uninstalls the previously installed ISR @@ -110,10 +107,5 @@ namespace upm { rpr220_context m_rpr220; -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(void (*isr)(void *), void *arg); -#endif }; } - - diff --git a/src/rsc/javaupm_rsc.i b/src/rsc/javaupm_rsc.i index 83973d31..69ba5090 100644 --- a/src/rsc/javaupm_rsc.i +++ b/src/rsc/javaupm_rsc.i @@ -7,13 +7,4 @@ %include "rsc.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_rsc"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_rsc) diff --git a/src/scam/javaupm_scam.i b/src/scam/javaupm_scam.i index f061fddf..b74fcf90 100644 --- a/src/scam/javaupm_scam.i +++ b/src/scam/javaupm_scam.i @@ -8,13 +8,4 @@ %include "scam.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_scam"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_scam) diff --git a/src/sensortemplate/javaupm_sensortemplate.i b/src/sensortemplate/javaupm_sensortemplate.i index 8f23abf0..6759bfe3 100644 --- a/src/sensortemplate/javaupm_sensortemplate.i +++ b/src/sensortemplate/javaupm_sensortemplate.i @@ -5,13 +5,4 @@ %include "common.i" /* Add the JAVA code to load the module */ -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_sensortemplate"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_sensortemplate) diff --git a/src/servo/javaupm_servo.i b/src/servo/javaupm_servo.i index 1ab59ea7..28a631ab 100644 --- a/src/servo/javaupm_servo.i +++ b/src/servo/javaupm_servo.i @@ -16,13 +16,4 @@ #include "es9257.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_servo"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_servo) \ No newline at end of file diff --git a/src/sht1x/javaupm_sht1x.i b/src/sht1x/javaupm_sht1x.i index 908100ff..3c8d8f6a 100644 --- a/src/sht1x/javaupm_sht1x.i +++ b/src/sht1x/javaupm_sht1x.i @@ -10,13 +10,4 @@ #include "sht1x.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_sht1x"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_sht1x) diff --git a/src/si1132/javaupm_si1132.i b/src/si1132/javaupm_si1132.i index 8f5c41e5..d61335b4 100644 --- a/src/si1132/javaupm_si1132.i +++ b/src/si1132/javaupm_si1132.i @@ -12,16 +12,7 @@ import upm_interfaces.*; %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_si1132"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_si1132) %include "si1132.hpp" %{ diff --git a/src/si114x/javaupm_si114x.i b/src/si114x/javaupm_si114x.i index 1bb66120..f3a1efc8 100644 --- a/src/si114x/javaupm_si114x.i +++ b/src/si114x/javaupm_si114x.i @@ -8,13 +8,4 @@ %include "si114x.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_si114x"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_si114x) \ No newline at end of file diff --git a/src/si7005/javaupm_si7005.i b/src/si7005/javaupm_si7005.i index 88e40c27..a653c8f5 100644 --- a/src/si7005/javaupm_si7005.i +++ b/src/si7005/javaupm_si7005.i @@ -19,13 +19,4 @@ import upm_interfaces.*; %include "si7005.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_si7005"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_si7005) diff --git a/src/slide/javaupm_slide.i b/src/slide/javaupm_slide.i index 01626d59..d06f49de 100644 --- a/src/slide/javaupm_slide.i +++ b/src/slide/javaupm_slide.i @@ -7,13 +7,4 @@ %include "slide.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_slide"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_slide) diff --git a/src/sm130/javaupm_sm130.i b/src/sm130/javaupm_sm130.i index 648620e8..4bf92c6b 100644 --- a/src/sm130/javaupm_sm130.i +++ b/src/sm130/javaupm_sm130.i @@ -7,13 +7,4 @@ %include "sm130.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_sm130"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_sm130) \ No newline at end of file diff --git a/src/smartdrive/javaupm_smartdrive.i b/src/smartdrive/javaupm_smartdrive.i index b316075b..8d70f7bf 100644 --- a/src/smartdrive/javaupm_smartdrive.i +++ b/src/smartdrive/javaupm_smartdrive.i @@ -7,13 +7,4 @@ %include "smartdrive.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_smartdrive"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_smartdrive) diff --git a/src/speaker/javaupm_speaker.i b/src/speaker/javaupm_speaker.i index f6e5224b..43507f34 100644 --- a/src/speaker/javaupm_speaker.i +++ b/src/speaker/javaupm_speaker.i @@ -7,13 +7,4 @@ %include "speaker.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_speaker"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_speaker) \ No newline at end of file diff --git a/src/ssd1351/javaupm_ssd1351.i b/src/ssd1351/javaupm_ssd1351.i index 36ca1596..ca2c1442 100644 --- a/src/ssd1351/javaupm_ssd1351.i +++ b/src/ssd1351/javaupm_ssd1351.i @@ -16,13 +16,4 @@ #include "ssd1351.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ssd1351"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ssd1351) \ No newline at end of file diff --git a/src/st7735/javaupm_st7735.i b/src/st7735/javaupm_st7735.i index be91f460..b27d1140 100644 --- a/src/st7735/javaupm_st7735.i +++ b/src/st7735/javaupm_st7735.i @@ -45,13 +45,4 @@ #include "st7735.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_st7735"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_st7735) \ No newline at end of file diff --git a/src/stepmotor/javaupm_stepmotor.i b/src/stepmotor/javaupm_stepmotor.i index 90505c56..8e839e98 100644 --- a/src/stepmotor/javaupm_stepmotor.i +++ b/src/stepmotor/javaupm_stepmotor.i @@ -7,13 +7,4 @@ %include "stepmotor.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_stepmotor"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_stepmotor) \ No newline at end of file diff --git a/src/sx1276/javaupm_sx1276.i b/src/sx1276/javaupm_sx1276.i index 8b1dd8a7..70d79bfd 100644 --- a/src/sx1276/javaupm_sx1276.i +++ b/src/sx1276/javaupm_sx1276.i @@ -14,13 +14,4 @@ %include "sx1276.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_sx1276"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_sx1276) diff --git a/src/sx6119/javaupm_sx6119.i b/src/sx6119/javaupm_sx6119.i index 4bbf6b7b..89c08bdb 100644 --- a/src/sx6119/javaupm_sx6119.i +++ b/src/sx6119/javaupm_sx6119.i @@ -8,13 +8,4 @@ %include "sx6119.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_sx6119"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_sx6119) \ No newline at end of file diff --git a/src/t3311/javaupm_t3311.i b/src/t3311/javaupm_t3311.i index 611a347f..55f0bc45 100644 --- a/src/t3311/javaupm_t3311.i +++ b/src/t3311/javaupm_t3311.i @@ -11,13 +11,4 @@ %include "t3311.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_t3311"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_t3311) diff --git a/src/t6713/javaupm_t6713.i b/src/t6713/javaupm_t6713.i index 70c3a470..b813433f 100644 --- a/src/t6713/javaupm_t6713.i +++ b/src/t6713/javaupm_t6713.i @@ -18,13 +18,4 @@ import upm_interfaces.*; %include "t6713.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_t6713"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_t6713) diff --git a/src/t8100/javaupm_t8100.i b/src/t8100/javaupm_t8100.i index 20e9a927..5b5143d0 100644 --- a/src/t8100/javaupm_t8100.i +++ b/src/t8100/javaupm_t8100.i @@ -10,13 +10,4 @@ %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_t8100"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_t8100) diff --git a/src/ta12200/javaupm_ta12200.i b/src/ta12200/javaupm_ta12200.i index a3fae852..d1d73a24 100644 --- a/src/ta12200/javaupm_ta12200.i +++ b/src/ta12200/javaupm_ta12200.i @@ -7,13 +7,4 @@ %include "ta12200.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ta12200"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_ta12200) \ No newline at end of file diff --git a/src/tb7300/javaupm_tb7300.i b/src/tb7300/javaupm_tb7300.i index 7374878c..55586a7b 100644 --- a/src/tb7300/javaupm_tb7300.i +++ b/src/tb7300/javaupm_tb7300.i @@ -20,13 +20,4 @@ %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_tb7300"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_tb7300) diff --git a/src/tca9548a/javaupm_tca9548a.i b/src/tca9548a/javaupm_tca9548a.i index afe28f04..ff4c380a 100644 --- a/src/tca9548a/javaupm_tca9548a.i +++ b/src/tca9548a/javaupm_tca9548a.i @@ -7,13 +7,4 @@ %include "tca9548a.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_tca9548a"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_tca9548a) diff --git a/src/tcs3414cs/javaupm_tcs3414cs.i b/src/tcs3414cs/javaupm_tcs3414cs.i index 1389d3f5..e3251704 100644 --- a/src/tcs3414cs/javaupm_tcs3414cs.i +++ b/src/tcs3414cs/javaupm_tcs3414cs.i @@ -7,13 +7,4 @@ %include "tcs3414cs.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_tcs3414cs"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_tcs3414cs) \ No newline at end of file diff --git a/src/tcs37727/javaupm_tcs37727.i b/src/tcs37727/javaupm_tcs37727.i index ac6c4bcc..c93b48f9 100644 --- a/src/tcs37727/javaupm_tcs37727.i +++ b/src/tcs37727/javaupm_tcs37727.i @@ -7,13 +7,4 @@ %include "tcs37727.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_tcs37727"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_tcs37727) \ No newline at end of file diff --git a/src/teams/javaupm_teams.i b/src/teams/javaupm_teams.i index eb8c43c0..744a2d52 100644 --- a/src/teams/javaupm_teams.i +++ b/src/teams/javaupm_teams.i @@ -7,13 +7,4 @@ #include "teams.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_teams"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_teams) diff --git a/src/temperature/javaupm_temperature.i b/src/temperature/javaupm_temperature.i index 567b7f7b..150eb71a 100644 --- a/src/temperature/javaupm_temperature.i +++ b/src/temperature/javaupm_temperature.i @@ -7,13 +7,4 @@ #include "temperature.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_temperature"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_temperature) diff --git a/src/tex00/javaupm_tex00.i b/src/tex00/javaupm_tex00.i index f59ddd42..ba345860 100644 --- a/src/tex00/javaupm_tex00.i +++ b/src/tex00/javaupm_tex00.i @@ -7,13 +7,4 @@ #include "tex00.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_tex00"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_tex00) diff --git a/src/th02/javaupm_th02.i b/src/th02/javaupm_th02.i index d20e8993..f58bfb74 100644 --- a/src/th02/javaupm_th02.i +++ b/src/th02/javaupm_th02.i @@ -7,13 +7,4 @@ %include "th02.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_th02"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_th02) \ No newline at end of file diff --git a/src/tm1637/javaupm_tm1637.i b/src/tm1637/javaupm_tm1637.i index b6d283f8..bf56cfb3 100644 --- a/src/tm1637/javaupm_tm1637.i +++ b/src/tm1637/javaupm_tm1637.i @@ -17,13 +17,4 @@ %include "tm1637.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_tm1637"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_tm1637) \ No newline at end of file diff --git a/src/tmp006/javaupm_tmp006.i b/src/tmp006/javaupm_tmp006.i index a52d474c..75f6cc4c 100644 --- a/src/tmp006/javaupm_tmp006.i +++ b/src/tmp006/javaupm_tmp006.i @@ -7,13 +7,4 @@ %include "tmp006.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_tmp006"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_tmp006) \ No newline at end of file diff --git a/src/tsl2561/javaupm_tsl2561.i b/src/tsl2561/javaupm_tsl2561.i index 78606b5f..249d1fa5 100644 --- a/src/tsl2561/javaupm_tsl2561.i +++ b/src/tsl2561/javaupm_tsl2561.i @@ -7,13 +7,4 @@ %include "tsl2561.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_tsl2561"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_tsl2561) \ No newline at end of file diff --git a/src/ttp223/javaupm_ttp223.i b/src/ttp223/javaupm_ttp223.i index c3b5e29d..65043218 100644 --- a/src/ttp223/javaupm_ttp223.i +++ b/src/ttp223/javaupm_ttp223.i @@ -11,13 +11,8 @@ %include "ttp223.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ttp223"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +#%ignore installISR(mraa::Edge , void *, void *) + +JAVA_ADD_INSTALLISR_EDGE(upm::TTP223) + +JAVA_JNI_LOADLIBRARY(javaupm_ttp223) diff --git a/src/ttp223/ttp223.cxx b/src/ttp223/ttp223.cxx index 7e2775dc..94cef4e9 100644 --- a/src/ttp223/ttp223.cxx +++ b/src/ttp223/ttp223.cxx @@ -31,7 +31,7 @@ using namespace upm; TTP223::TTP223(unsigned int pin) { // initialize gpio input - if ( !(m_gpio = mraa_gpio_init(pin)) ) + if ( !(m_gpio = mraa_gpio_init(pin)) ) { throw std::invalid_argument(std::string(__FUNCTION__) + ": mraa_gpio_init() failed, invalid pin?"); @@ -59,12 +59,6 @@ bool TTP223::isPressed() { return this->value() == 1; } -#ifdef JAVACALLBACK -void TTP223::installISR(mraa::Edge level, jobject runnable) -{ - installISR(level, mraa_java_isr_callback, runnable); -} -#endif void TTP223::installISR(mraa::Edge level, void (*isr)(void *), void *arg) { diff --git a/src/ttp223/ttp223.hpp b/src/ttp223/ttp223.hpp index 3162b223..1fd16fda 100644 --- a/src/ttp223/ttp223.hpp +++ b/src/ttp223/ttp223.hpp @@ -43,10 +43,10 @@ namespace upm { * @con gpio * * @brief API for the TTP223 Touch Sensor - * + * * This touch sensor detects when a finger is near the metallic pad * by the change in capacitance. It can replace a more traditional push - * button. The touch sensor can still function when placed under a + * button. The touch sensor can still function when placed under a * non-metallic surface like glass or plastic. * * @image html ttp223.jpg @@ -95,11 +95,8 @@ class TTP223 { * @param arg Pointer to an object to be supplied as an * argument to the ISR. */ -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(mraa::Edge level, jobject runnable); -#else + void installISR(mraa::Edge level, void (*isr)(void *), void *arg); -#endif /** * Uninstalls the previously installed ISR * @@ -107,9 +104,6 @@ class TTP223 { void uninstallISR(); protected: -#if defined(SWIGJAVA) || defined(JAVACALLBACK) - void installISR(mraa::Edge level, void (*isr)(void *), void *arg); -#endif std::string m_name; //!< name of this sensor mraa_gpio_context m_gpio; //!< GPIO pin bool m_isrInstalled; diff --git a/src/uartat/javaupm_uartat.i b/src/uartat/javaupm_uartat.i index dd8de86b..5017220e 100644 --- a/src/uartat/javaupm_uartat.i +++ b/src/uartat/javaupm_uartat.i @@ -10,13 +10,4 @@ #include "uartat.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_uartat"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_uartat) diff --git a/src/uln200xa/javaupm_uln200xa.i b/src/uln200xa/javaupm_uln200xa.i index e41873e4..68b6f6f4 100644 --- a/src/uln200xa/javaupm_uln200xa.i +++ b/src/uln200xa/javaupm_uln200xa.i @@ -8,13 +8,4 @@ %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_uln200xa"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_uln200xa) diff --git a/src/ultrasonic/javaupm_ultrasonic.i b/src/ultrasonic/javaupm_ultrasonic.i index bece5af0..9adfa549 100644 --- a/src/ultrasonic/javaupm_ultrasonic.i +++ b/src/ultrasonic/javaupm_ultrasonic.i @@ -9,13 +9,4 @@ %include "ultrasonic.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_ultrasonic"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_ultrasonic) diff --git a/src/upm.i b/src/upm.i index eb1c5391..11aacd41 100644 --- a/src/upm.i +++ b/src/upm.i @@ -2,6 +2,8 @@ %include "stdint.i" %include "upm_exception.i" +%import _upm.i + %{ #include "version.hpp" %} diff --git a/src/urm37/javaupm_urm37.i b/src/urm37/javaupm_urm37.i index 7d169749..859da92c 100644 --- a/src/urm37/javaupm_urm37.i +++ b/src/urm37/javaupm_urm37.i @@ -9,13 +9,4 @@ %include "urm37.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_urm37"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_urm37) \ No newline at end of file diff --git a/src/vcap/javaupm_vcap.i b/src/vcap/javaupm_vcap.i index da116499..12c86f29 100644 --- a/src/vcap/javaupm_vcap.i +++ b/src/vcap/javaupm_vcap.i @@ -7,13 +7,4 @@ #include "vcap.hpp" %} -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_vcap"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_vcap) diff --git a/src/vdiv/javaupm_vdiv.i b/src/vdiv/javaupm_vdiv.i index bc615e62..49e416eb 100644 --- a/src/vdiv/javaupm_vdiv.i +++ b/src/vdiv/javaupm_vdiv.i @@ -7,13 +7,4 @@ %include "vdiv.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_vdiv"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_vdiv) \ No newline at end of file diff --git a/src/veml6070/javaupm_veml6070.i b/src/veml6070/javaupm_veml6070.i index 35467981..ddb9b8fa 100644 --- a/src/veml6070/javaupm_veml6070.i +++ b/src/veml6070/javaupm_veml6070.i @@ -8,13 +8,4 @@ %} %include "veml6070.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_veml6070"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_veml6070) diff --git a/src/water/javaupm_water.i b/src/water/javaupm_water.i index 2b89df58..79610e24 100644 --- a/src/water/javaupm_water.i +++ b/src/water/javaupm_water.i @@ -7,13 +7,4 @@ %include "water.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_water"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_water) \ No newline at end of file diff --git a/src/waterlevel/javaupm_waterlevel.i b/src/waterlevel/javaupm_waterlevel.i index b9e9f2d8..1e1358c2 100644 --- a/src/waterlevel/javaupm_waterlevel.i +++ b/src/waterlevel/javaupm_waterlevel.i @@ -7,13 +7,4 @@ %include "waterlevel.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_waterlevel"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_waterlevel) \ No newline at end of file diff --git a/src/wfs/javaupm_wfs.i b/src/wfs/javaupm_wfs.i index 35f7ee08..340388e4 100644 --- a/src/wfs/javaupm_wfs.i +++ b/src/wfs/javaupm_wfs.i @@ -9,13 +9,4 @@ %include "wfs.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_wfs"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} +JAVA_JNI_LOADLIBRARY(javaupm_wfs) diff --git a/src/wheelencoder/javaupm_wheelencoder.i b/src/wheelencoder/javaupm_wheelencoder.i index 7baff367..4877afaa 100644 --- a/src/wheelencoder/javaupm_wheelencoder.i +++ b/src/wheelencoder/javaupm_wheelencoder.i @@ -7,13 +7,4 @@ %include "wheelencoder.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_wheelencoder"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_wheelencoder) \ No newline at end of file diff --git a/src/wt5001/javaupm_wt5001.i b/src/wt5001/javaupm_wt5001.i index dd9c9dca..9c9c861e 100644 --- a/src/wt5001/javaupm_wt5001.i +++ b/src/wt5001/javaupm_wt5001.i @@ -33,13 +33,4 @@ READDATA_EXCEPTION(getCurrentFile()) %include "wt5001.hpp" speed_t int_B9600 = B9600; -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_wt5001"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_wt5001) \ No newline at end of file diff --git a/src/xbee/javaupm_xbee.i b/src/xbee/javaupm_xbee.i index 95d7cea0..c34fab4d 100644 --- a/src/xbee/javaupm_xbee.i +++ b/src/xbee/javaupm_xbee.i @@ -10,13 +10,4 @@ %include "xbee.hpp" %array_class(char, charArray); -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_xbee"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_xbee) \ No newline at end of file diff --git a/src/yg1006/javaupm_yg1006.i b/src/yg1006/javaupm_yg1006.i index a2c26506..30436197 100644 --- a/src/yg1006/javaupm_yg1006.i +++ b/src/yg1006/javaupm_yg1006.i @@ -7,13 +7,4 @@ %include "yg1006.hpp" -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_yg1006"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_yg1006) \ No newline at end of file diff --git a/src/zfm20/javaupm_zfm20.i b/src/zfm20/javaupm_zfm20.i index cbecc9e2..90638835 100644 --- a/src/zfm20/javaupm_zfm20.i +++ b/src/zfm20/javaupm_zfm20.i @@ -16,13 +16,4 @@ %include "zfm20.hpp" speed_t int_B57600 = B57600; -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("javaupm_zfm20"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - System.exit(1); - } - } -%} \ No newline at end of file +JAVA_JNI_LOADLIBRARY(javaupm_zfm20) \ No newline at end of file diff --git a/tests/check_autoloadlibrary.py b/tests/check_autoloadlibrary.py index e91e260c..f4519e71 100755 --- a/tests/check_autoloadlibrary.py +++ b/tests/check_autoloadlibrary.py @@ -36,7 +36,9 @@ class AutoLoadLibrary(u.TestCase): if not '%module' in data: print "%%module not found in %s, skipping" % fileName continue - if not snippet in data: + # Check for the autoload code or the autoload macro + if (not 'JAVA_JNI_LOADLIBRARY(javaupm_' in data) and \ + (not snippet in data): broken_modules.append('%s: %s' % \ (moduleName, os.path.join(subdir, fileName)))