public class GpioBridgeImpl extends Object implements GpioBridge
Main object to give access to GPIO ports on a Linux kernel
The GpioBridge is a singleton. Features include retrieving Pins, writing and reading values, as well as
registering observers for changes to input pins
Gpio objects are cached and their Signal is set by the GpioBridge accordingly
| Modifier and Type | Method and Description |
|---|---|
Gpio |
getGpio(Pin pin,
Direction direction)
|
static GpioBridge |
getInstance() |
Signal |
readValue(Gpio gpio)
|
void |
register(Gpio gpio,
GpioSignalListener listener)
|
void |
start()
Starts the
GpioBridge's signal observing Thread. |
void |
stop()
Stops observing any pins and stops the
Thread |
boolean |
unregister(GpioBridgeTest gpio,
GpioSignalListener listener)
Unregisters a
GpioSignalListener from changes to the given Gpio |
void |
writeValue(Gpio gpio,
Signal signal)
|
public static GpioBridge getInstance()
GpioBridgepublic void writeValue(Gpio gpio, Signal signal) throws GpioException
writeValue in interface GpioBridgegpio - the Gpio to which the Signal should be writtensignal - the Signal to write to the given GpioGpioException - if the direction of the Gpio is not Direction.OUT, or if something goes wrong while
writing to the filepublic Signal readValue(Gpio gpio) throws GpioException
readValue in interface GpioBridgegpio - the Gpio for which the Signal should be readGpio's current signalGpioException - if the direction of the Gpio is not Direction.IN, or if something goes wrong while
reading from the filepublic void start()
GpioBridge's signal observing Thread. If no observers are registered with the
register(Gpio, GpioSignalListener)-method, then this method needs not to be called.start in interface GpioBridgepublic void stop()
Threadstop in interface GpioBridgepublic Gpio getGpio(Pin pin, Direction direction) throws GpioException
Returns the Gpio for the given Direction.
Note: This method can not be called multiple times with different Directions. The
GpioBridge does not handle pins that are simultaneously input and output as this is not supported by the
Linux kernel.
getGpio in interface GpioBridgepin - The Pin for which the Gpio in the given Direction is to be returneddirection - the Direction for which this Gpio is to be returnedGpio with the configured DirectionGpioException - If the given Direction does not match the kernel's configured direction, or if the file
permissions are not set so that the Java process can access the file (read access for input pin,
write access for output pin.public void register(Gpio gpio, GpioSignalListener listener) throws GpioException
register in interface GpioBridgegpio - the Gpio being observedlistener - the GpioSignalListener to be notified on changes on the Gpio's SignalGpioException - if the Direction of the Gpio is not Direction.INpublic boolean unregister(GpioBridgeTest gpio, GpioSignalListener listener)
GpioSignalListener from changes to the given Gpiounregister in interface GpioBridgegpio - the Gpio for which the listener is to be removedlistener - the GpioSignalListener to be removed from changes to the given GpioCopyright © 2017. All rights reserved.