java: solved callbacks

Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Stefan Andritoiu 2015-08-19 19:27:16 +03:00 committed by Mihai Tudor Panu
parent 323905a215
commit 19bcbc7c42
13 changed files with 108 additions and 16 deletions

View File

@ -54,6 +54,13 @@ bool A110X::magnetDetected()
return (!mraa_gpio_read(m_gpio) ? true : false); return (!mraa_gpio_read(m_gpio) ? true : false);
} }
#ifdef SWIGJAVA
void A110X::installISR( IsrCallback *cb)
{
installISR(generic_callback_isr, cb);
}
#endif
void A110X::installISR(void (*isr)(void *), void *arg) void A110X::installISR(void (*isr)(void *), void *arg)
{ {
if (m_isrInstalled) if (m_isrInstalled)

View File

@ -26,6 +26,10 @@
#include <string> #include <string>
#include <mraa/gpio.h> #include <mraa/gpio.h>
#ifdef SWIGJAVA
#include "../IsrCallback.h"
#endif
namespace upm { namespace upm {
/** /**
* @brief A110X Hall Effect library * @brief A110X Hall Effect library
@ -85,8 +89,11 @@ namespace upm {
* @param arg Pointer to an object to be supplied as an * @param arg Pointer to an object to be supplied as an
* argument to the ISR. * argument to the ISR.
*/ */
#ifdef SWIGJAVA
void installISR(IsrCallback *cb);
#else
void installISR(void (*isr)(void *), void *arg); void installISR(void (*isr)(void *), void *arg);
#endif
/** /**
* Uninstalls the previously installed ISR * Uninstalls the previously installed ISR
* *
@ -94,6 +101,10 @@ namespace upm {
void uninstallISR(); void uninstallISR();
private: private:
#ifdef SWIGJAVA
void installISR(void (*isr)(void *), void *arg);
#endif
bool m_isrInstalled; bool m_isrInstalled;
mraa_gpio_context m_gpio; mraa_gpio_context m_gpio;
}; };

View File

@ -2,17 +2,12 @@
%include "../upm.i" %include "../upm.i"
%include "stdint.i" %include "stdint.i"
%include "typemaps.i" %include "typemaps.i"
/*
%feature("director") ISRHelper; %feature("director") IsrCallback;
%feature("nodirector") A110x;
*/ %ignore generic_callback_isr;
%apply jobject { void * }; %include "../IsrCallback.h"
/*
%{
#include "isrhelper.h"
%}
%include "isrhelper.h"
*/
%{ %{
#include "a110x.h" #include "a110x.h"
%} %}

View File

@ -31,6 +31,14 @@
using namespace upm; using namespace upm;
#ifdef SWIGJAVA
void
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, IsrCallback *cb);
{
HCSR04 (triggerPin, echoPin, generic_callback_isr);
}
#endif
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)) { HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)) {
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
m_name = "HCSR04"; m_name = "HCSR04";

View File

@ -29,6 +29,10 @@
#include <mraa/pwm.h> #include <mraa/pwm.h>
#include <sys/time.h> #include <sys/time.h>
#ifdef SWIGJAVA
#include "../IsrCallback.h"
#endif
#define HIGH 1 #define HIGH 1
#define LOW 0 #define LOW 0
@ -58,6 +62,9 @@ namespace upm {
*/ */
class HCSR04 { class HCSR04 {
public: public:
#ifdef SWIGJAVA
HCSR04 (uint8_t triggerPin, uint8_t echoPin, IsrCallback *cb);
#else
/** /**
* Instantiates an HCSR04 object * Instantiates an HCSR04 object
* *
@ -67,7 +74,7 @@ class HCSR04 {
* falling-edge interrupts * falling-edge interrupts
*/ */
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)); HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *));
#endif
/** /**
* HCSR04 object destructor * HCSR04 object destructor
*/ */
@ -96,6 +103,9 @@ class HCSR04 {
} }
private: private:
#ifdef SWIGJAVA
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *));
#endif
mraa_pwm_context m_pwmTriggerCtx; mraa_pwm_context m_pwmTriggerCtx;
mraa_gpio_context m_echoPinCtx; mraa_gpio_context m_echoPinCtx;

View File

@ -1,6 +1,11 @@
%module javaupm_hcsr04 %module javaupm_hcsr04
%include "../upm.i" %include "../upm.i"
%feature("director") IsrCallback;
%ignore generic_callback_isr;
%include "../IsrCallback.h"
%{ %{
#include "hcsr04.h" #include "hcsr04.h"
%} %}

View File

@ -707,7 +707,6 @@ void LSM9DS0::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
} }
#endif #endif
void LSM9DS0::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void LSM9DS0::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
void (*isr)(void *), void *arg) void (*isr)(void *), void *arg)
{ {

View File

@ -3,10 +3,14 @@
%include "cpointer.i" %include "cpointer.i"
%include "typemaps.i" %include "typemaps.i"
%feature("director") IsrCallback;
%ignore generic_callback_isr;
%include "../IsrCallback.h"
%apply int *OUTPUT { int *x, int *y, int *z }; %apply int *OUTPUT { int *x, int *y, int *z };
%apply float *OUTPUT { float *ax, float *ay, float *az }; %apply float *OUTPUT { float *ax, float *ay, float *az };
%{ %{
#include "mma7660.h" #include "mma7660.h"
%} %}

View File

@ -195,6 +195,13 @@ bool MMA7660::tiltShake()
return false; return false;
} }
#ifdef SWIGJAVA
void MMA7660::installISR(int pin, IsrCallback *cb)
{
installISR(pin, generic_callback_isr, cb);
}
#endif
void MMA7660::installISR(int pin, void (*isr)(void *), void *arg) void MMA7660::installISR(int pin, void (*isr)(void *), void *arg)
{ {
if (m_isrInstalled) if (m_isrInstalled)

View File

@ -27,6 +27,10 @@
#include <mraa/i2c.h> #include <mraa/i2c.h>
#include <mraa/gpio.h> #include <mraa/gpio.h>
#ifdef SWIGJAVA
#include "../IsrCallback.h"
#endif
#define MMA7660_I2C_BUS 0 #define MMA7660_I2C_BUS 0
#define MMA7660_DEFAULT_I2C_ADDR 0x4c #define MMA7660_DEFAULT_I2C_ADDR 0x4c
@ -248,8 +252,11 @@ namespace upm {
* @param arg Pointer to an object to be supplied as an * @param arg Pointer to an object to be supplied as an
* argument to the ISR. * argument to the ISR.
*/ */
#ifdef SWIGJAVA
void installISR(int pin, IsrCallback *cb);
#else
void installISR(int pin, void (*isr)(void *), void *arg); void installISR(int pin, void (*isr)(void *), void *arg);
#endif
/** /**
* Uninstalls the previously installed ISR * Uninstalls the previously installed ISR
* *
@ -276,6 +283,10 @@ namespace upm {
bool setSampleRate(MMA7660_AUTOSLEEP_T sr); bool setSampleRate(MMA7660_AUTOSLEEP_T sr);
private: private:
#ifdef SWIGJAVA
void installISR(int pin, void (*isr)(void *), void *arg);
#endif
bool m_isrInstalled; bool m_isrInstalled;
mraa_i2c_context m_i2c; mraa_i2c_context m_i2c;
mraa_gpio_context m_gpio; mraa_gpio_context m_gpio;

View File

@ -1,8 +1,23 @@
%module javaupm_mpu9150 %module javaupm_mpu9150
%include "../upm.i" %include "../upm.i"
%include "typemaps.i" %include "typemaps.i"
%include "arrays_java.i"
%feature("director") IsrCallback;
%ignore generic_callback_isr;
%include "../IsrCallback.h"
%apply int {mraa::Edge};
%apply float *INOUT { float *x, float *y, float *z }; %apply float *INOUT { float *x, float *y, float *z };
%apply unsigned char[] {uint8_t *};
%{
#include "mpu60x0.h"
%}
%include "mpu60x0.h"
%{ %{
#include "mpu9150.h" #include "mpu9150.h"

View File

@ -380,6 +380,14 @@ uint8_t MPU60X0::getInterruptPinConfig()
return readReg(REG_INT_PIN_CFG); return readReg(REG_INT_PIN_CFG);
} }
#ifdef SWIGJAVA
void MPU60X0::installISR(int gpio, mraa::Edge level,
IsrCallback *cb)
{
installISR(intr, gpio, level, generic_callback_isr, cb);
}
#endif
void MPU60X0::installISR(int gpio, mraa::Edge level, void MPU60X0::installISR(int gpio, mraa::Edge level,
void (*isr)(void *), void *arg) void (*isr)(void *), void *arg)
{ {

View File

@ -34,6 +34,10 @@
#include <mraa/gpio.hpp> #include <mraa/gpio.hpp>
#endif #endif
#ifdef SWIGJAVA
#include "../IsrCallback.h"
#endif
#define MPU60X0_I2C_BUS 0 #define MPU60X0_I2C_BUS 0
#define MPU60X0_DEFAULT_I2C_ADDR 0x68 #define MPU60X0_DEFAULT_I2C_ADDR 0x68
@ -904,7 +908,11 @@ namespace upm {
* @param isr the interrupt handler, accepting a void * argument * @param isr the interrupt handler, accepting a void * argument
* @param arg the argument to pass the the interrupt handler * @param arg the argument to pass the the interrupt handler
*/ */
#ifdef SWIGJAVA
void installISR(int gpio, mraa::Edge level, IsrCallback *cb);
#else
void installISR(int gpio, mraa::Edge level, void (*isr)(void *), void *arg); void installISR(int gpio, mraa::Edge level, void (*isr)(void *), void *arg);
#endif
/** /**
* uninstall a previously installed interrupt handler * uninstall a previously installed interrupt handler
@ -931,6 +939,10 @@ namespace upm {
float m_gyroScale; float m_gyroScale;
private: private:
#ifdef SWIGJAVA
void installISR(int gpio, mraa::Edge level, void (*isr)(void *), void *arg);
#endif
mraa::I2c m_i2c; mraa::I2c m_i2c;
uint8_t m_addr; uint8_t m_addr;