mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 09:51:14 +03:00
hcsr04: Made ISR be used internally and not be exposed to the user. Changed access modifier to private. Removed passing ISR to constructor.
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:

committed by
Mihai Tudor Panu

parent
e54f5e21c3
commit
1accafa145
@ -34,14 +34,7 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
#ifdef JAVACALLBACK
|
||||
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) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
m_name = "HCSR04";
|
||||
|
||||
@ -63,7 +56,7 @@ HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)) {
|
||||
}
|
||||
|
||||
mraa_gpio_dir(m_echoPinCtx, MRAA_GPIO_IN);
|
||||
mraa_gpio_isr(m_echoPinCtx, MRAA_GPIO_EDGE_BOTH, fptr, (void*)this);
|
||||
mraa_gpio_isr(m_echoPinCtx, MRAA_GPIO_EDGE_BOTH, &ackEdgeDetected, (void*)this);
|
||||
}
|
||||
|
||||
HCSR04::~HCSR04 () {
|
||||
@ -96,16 +89,17 @@ HCSR04::timing() {
|
||||
}
|
||||
|
||||
void
|
||||
HCSR04::ackEdgeDetected () {
|
||||
HCSR04::ackEdgeDetected (void *ctx) {
|
||||
upm::HCSR04 *This = (upm::HCSR04 *)ctx;
|
||||
struct timeval timer;
|
||||
gettimeofday(&timer, NULL);
|
||||
|
||||
++m_InterruptCounter;
|
||||
if (!(m_InterruptCounter % 2)) {
|
||||
m_FallingTimeStamp = 1000000 * timer.tv_sec + timer.tv_usec;
|
||||
m_doWork = 1;
|
||||
This->m_InterruptCounter++;
|
||||
if (!(This->m_InterruptCounter % 2)) {
|
||||
This->m_FallingTimeStamp = 1000000 * timer.tv_sec + timer.tv_usec;
|
||||
This->m_doWork = 1;
|
||||
} else {
|
||||
m_RisingTimeStamp = 1000000 * timer.tv_sec + timer.tv_usec;
|
||||
This->m_RisingTimeStamp = 1000000 * timer.tv_sec + timer.tv_usec;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,11 +68,7 @@ class HCSR04 {
|
||||
* @param fptr Function pointer to handle rising-edge and
|
||||
* falling-edge interrupts
|
||||
*/
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
HCSR04 (uint8_t triggerPin, uint8_t echoPin, IsrCallback *cb);
|
||||
#else
|
||||
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *));
|
||||
#endif
|
||||
HCSR04 (uint8_t triggerPin, uint8_t echoPin);
|
||||
/**
|
||||
* HCSR04 object destructor
|
||||
*/
|
||||
@ -83,12 +79,6 @@ class HCSR04 {
|
||||
*/
|
||||
double getDistance (int sys);
|
||||
|
||||
/**
|
||||
* On each interrupt, this function detects if the interrupt
|
||||
* was falling-edge or rising-edge.
|
||||
* Should be called from the interrupt handler.
|
||||
*/
|
||||
void ackEdgeDetected ();
|
||||
|
||||
uint8_t m_doWork; /**< Flag to control blocking function while waiting for a falling-edge interrupt */
|
||||
|
||||
@ -101,9 +91,12 @@ class HCSR04 {
|
||||
}
|
||||
|
||||
private:
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *));
|
||||
#endif
|
||||
/**
|
||||
* On each interrupt, this function detects if the interrupt
|
||||
* was falling-edge or rising-edge.
|
||||
*/
|
||||
static void ackEdgeDetected (void *ctx);
|
||||
|
||||
double timing();
|
||||
mraa_gpio_context m_triggerPinCtx;
|
||||
mraa_gpio_context m_echoPinCtx;
|
||||
|
@ -1,11 +1,6 @@
|
||||
%module(directors="1") javaupm_hcsr04
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("director") IsrCallback;
|
||||
|
||||
%ignore generic_callback_isr;
|
||||
%include "../IsrCallback.h"
|
||||
|
||||
%{
|
||||
#include "hcsr04.h"
|
||||
%}
|
||||
@ -21,4 +16,5 @@
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
%}
|
||||
%}
|
||||
|
||||
|
Reference in New Issue
Block a user