Class GpioInterrupt
- java.lang.Object
-
- com.pi4j.wiringpi.GpioInterrupt
-
public class GpioInterrupt extends Object
This class provides static methods to configure the native Pi4J library to listen to GPIO interrupts and invoke callbacks into this class. Additionally, this class provides a listener registration allowing Java consumers to subscribe to GPIO pin state changes.
Before using the Pi4J library, you need to ensure that the Java VM in configured with access to the following system libraries:
- pi4j
- wiringPi
This library depends on the wiringPi native system library. (developed by Gordon Henderson @ http://wiringpi.com/)
- Author:
- Robert Savage (http://www.savagehomeautomation.com)
- See Also:
- https://pi4j.com/
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GpioInterrupt.GpioEvent
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addListener(GpioInterruptListener listener)
Java consumer code can call this method to register itself as a listener for pin state changes.static int
disablePinStateChangeCallback(int pin)
This method is used to instruct the native code to stop the monitoring thread monitoring interrupts on the selected GPIO pin.static int
enablePinStateChangeCallback(int pin)
This method is used to instruct the native code to setup a monitoring thread to monitor interrupts that represent changes to the selected GPIO pin.static boolean
hasListener(GpioInterruptListener listener)
Returns true if the listener is already registered for event callbacks.static void
removeListener(GpioInterruptListener listener)
Java consumer code can all this method to unregister itself as a listener for pin state changes.static void
shutdown()
-
-
-
Method Detail
-
enablePinStateChangeCallback
public static int enablePinStateChangeCallback(int pin)
This method is used to instruct the native code to setup a monitoring thread to monitor interrupts that represent changes to the selected GPIO pin.
The GPIO pin must first be exported before it can be monitored.
- Parameters:
pin
- GPIO pin number (not header pin number; not wiringPi pin number)- Returns:
- A return value of a negative number represents an error. A return value of '0' represents success and that the GPIO pin is already being monitored. A return value of '1' represents success and that a new monitoring thread was created to handle the requested GPIO pin number.
-
disablePinStateChangeCallback
public static int disablePinStateChangeCallback(int pin)
This method is used to instruct the native code to stop the monitoring thread monitoring interrupts on the selected GPIO pin.
- Parameters:
pin
- GPIO pin number (not header pin number; not wiringPi pin number)- Returns:
- A return value of a negative number represents an error. A return value of '0' represents success and that no existing monitor was previously running. A return value of '1' represents success and that an existing monitoring thread was stopped for the requested GPIO pin number.
-
addListener
public static void addListener(GpioInterruptListener listener)
Java consumer code can call this method to register itself as a listener for pin state changes.
- Parameters:
listener
- A class instance that implements the GpioInterruptListener interface.- See Also:
GpioInterruptListener
,GpioInterruptEvent
-
removeListener
public static void removeListener(GpioInterruptListener listener)
Java consumer code can all this method to unregister itself as a listener for pin state changes.
- Parameters:
listener
- A class instance that implements the GpioInterruptListener interface.- See Also:
GpioInterruptListener
,GpioInterruptEvent
-
hasListener
public static boolean hasListener(GpioInterruptListener listener)
Returns true if the listener is already registered for event callbacks.
- Parameters:
listener
- A class instance that implements the GpioInterruptListener interface.- See Also:
GpioInterruptListener
,GpioInterruptEvent
-
shutdown
public static void shutdown()
-
-