From a0518976c6b64414c203ecbbe0f6c34a90debb0a Mon Sep 17 00:00:00 2001 From: Petre Eftime Date: Thu, 17 Sep 2015 17:23:46 +0300 Subject: [PATCH] ttp223: add Java isr callbacks Signed-off-by: Petre Eftime Signed-off-by: Mihai Tudor Panu --- src/ttp223/javaupm_ttp223.i | 11 ++++++++++- src/ttp223/ttp223.cxx | 24 ++++++++++++++++++++++++ src/ttp223/ttp223.h | 29 ++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/ttp223/javaupm_ttp223.i b/src/ttp223/javaupm_ttp223.i index 625f5181..cf7dd90a 100644 --- a/src/ttp223/javaupm_ttp223.i +++ b/src/ttp223/javaupm_ttp223.i @@ -1,6 +1,15 @@ -%module javaupm_ttp223 +%module (directors=1, docstring="TTP223 Touch Sensor") javaupm_ttp223 + %include "../upm.i" +%feature("director") IsrCallback; + +%ignore generic_callback_isr; +%include "../IsrCallback.h" + +%apply int {mraa::Edge} + + %{ #include "ttp223.h" %} diff --git a/src/ttp223/ttp223.cxx b/src/ttp223/ttp223.cxx index 307f6d3a..4e37d141 100644 --- a/src/ttp223/ttp223.cxx +++ b/src/ttp223/ttp223.cxx @@ -39,6 +39,7 @@ TTP223::TTP223(unsigned int pin) { } mraa_gpio_dir(m_gpio, MRAA_GPIO_IN); m_name = "ttp223"; + m_isrInstalled = false; } TTP223::~TTP223() { @@ -57,3 +58,26 @@ int TTP223::value() { bool TTP223::isPressed() { return this->value() == 1; } + +#ifdef JAVACALLBACK +void TTP223::installISR(mraa::Edge level, IsrCallback *cb) +{ + installISR(level, generic_callback_isr, cb); +} +#endif + +void TTP223::installISR(mraa::Edge level, void (*isr)(void *), void *arg) +{ + if (m_isrInstalled) + uninstallISR(); + + // install our interrupt handler + mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) level, isr, arg); + m_isrInstalled = true; +} + +void TTP223::uninstallISR() +{ + mraa_gpio_isr_exit(m_gpio); + m_isrInstalled = false; +} diff --git a/src/ttp223/ttp223.h b/src/ttp223/ttp223.h index f3ec5c1d..82038958 100644 --- a/src/ttp223/ttp223.h +++ b/src/ttp223/ttp223.h @@ -24,7 +24,11 @@ #pragma once #include -#include +#include + +#if defined(SWIGJAVA) || defined(JAVACALLBACK) +#include "../IsrCallback.h" +#endif namespace upm { /** @@ -87,9 +91,32 @@ class TTP223 { */ bool isPressed(); + /** + * Installs an interrupt service routine (ISR) to be called when + * the button is activated or deactivated. + * + * @param fptr Pointer to a function to be called on interrupt + * @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, IsrCallback *cb); +#else + void installISR(mraa::Edge level, void (*isr)(void *), void *arg); +#endif + /** + * Uninstalls the previously installed ISR + * + */ + 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; }; }