mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 01:41:12 +03:00
a110x: Add interrupt support and a suitable example
Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: John Van Drasek <john.r.van.drasek@intel.com>
This commit is contained in:

committed by
John Van Drasek

parent
317ad35180
commit
4bb077e70b
@ -31,8 +31,6 @@ using namespace std;
|
||||
|
||||
A110X::A110X(int pin)
|
||||
{
|
||||
mraa_init();
|
||||
|
||||
if ( !(m_gpio = mraa_gpio_init(pin)) )
|
||||
{
|
||||
cerr << __FUNCTION__ << ": mraa_gpio_init() failed" << endl;
|
||||
@ -40,10 +38,14 @@ A110X::A110X(int pin)
|
||||
}
|
||||
|
||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
|
||||
m_isrInstalled = false;
|
||||
}
|
||||
|
||||
A110X::~A110X()
|
||||
{
|
||||
if (m_isrInstalled)
|
||||
uninstallISR();
|
||||
|
||||
mraa_gpio_close(m_gpio);
|
||||
}
|
||||
|
||||
@ -52,3 +54,19 @@ bool A110X::magnetDetected()
|
||||
return (!mraa_gpio_read(m_gpio) ? true : false);
|
||||
}
|
||||
|
||||
void A110X::installISR(void (*isr)(void *), void *arg)
|
||||
{
|
||||
if (m_isrInstalled)
|
||||
uninstallISR();
|
||||
|
||||
// install our interrupt handler
|
||||
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_FALLING,
|
||||
isr, arg);
|
||||
m_isrInstalled = true;
|
||||
}
|
||||
|
||||
void A110X::uninstallISR()
|
||||
{
|
||||
mraa_gpio_isr_exit(m_gpio);
|
||||
m_isrInstalled = false;
|
||||
}
|
||||
|
@ -50,7 +50,10 @@ namespace upm {
|
||||
* whether it is detecting a magnetic field with south polarity
|
||||
* perpendicular to the sensor element.
|
||||
*
|
||||
* An example showing a simple test for the presence of a field
|
||||
* @snippet a110x.cxx Interesting
|
||||
* An example demonstrating the use of an interrupt handler to count pulses
|
||||
* @snippet a110x-intr.cxx Interesting
|
||||
*/
|
||||
class A110X {
|
||||
public:
|
||||
@ -71,7 +74,24 @@ namespace upm {
|
||||
*/
|
||||
bool magnetDetected();
|
||||
|
||||
/**
|
||||
* Install an Interrupt Service Routine (ISR) to be called when
|
||||
* the appropriate magnetic field is detected.
|
||||
*
|
||||
* @param fptr function pointer to function to be called on interrupt
|
||||
* @param arg pointer to an object that will be supplied as an
|
||||
* arguement to the ISR.
|
||||
*/
|
||||
void installISR(void (*isr)(void *), void *arg);
|
||||
|
||||
/**
|
||||
* Uninstall the previously installed Interrupt Service Routine (ISR)
|
||||
*
|
||||
*/
|
||||
void uninstallISR();
|
||||
|
||||
private:
|
||||
bool m_isrInstalled;
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user