Package com.kosdev.kos.core.service.gpio
Class GpioInputPinDef
java.lang.Object
com.kosdev.kos.core.service.gpio.GpioPinBinding
com.kosdev.kos.core.service.gpio.GpioInputPinDef
Definition of a GPIO input pin. A pin is defined as a combination of a GPIO chip and a pin on
that chip. See
GpioPinBinding for details about how to specify the chip and pin number.
Input pins support a number of confuration options which are specified in the pin definition and supplied at the time the pin is created.
- Since:
- 9
- Version:
- 9
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines the bias of an input pin. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBias()Return the bias of the input pin.Return the chip name if set.Return the chip number if set.intReturn the debounce duration in micro seconds.Return the pin change callback for when the pin value is false.Return the pin name if set.Return the pin number if set.Return the pin change callback for when the pin value is true.booleanReturn true if the input pin should generate a pin event when the adapter connects.booleanReturn the value of the inverted flag.setBias(GpioInputPinDef.Bias bias) Set the bias of the input pin.setChipName(String name) Set the name of the chip to bind to.setChipNum(Integer num) Set the number of the chip to bind to.setDebounce(int duration) Set the debounce time in micro seconds.setEventOnConnect(boolean flag) Set theeventOnConnectflag.setFalseCallback(GpioPinChangeCallback callback) Set the pin change callback to be called when pin state changes to false.setInverted(boolean inverted) Set the inverted flag.setPinName(String name) Set the name of the pin to bind to.Set the number of the pin to bind to.setTrueCallback(GpioPinChangeCallback callback) Set the pin change callback to be called when pin state changes to true.
-
Constructor Details
-
GpioInputPinDef
public GpioInputPinDef()
-
-
Method Details
-
getChipName
Return the chip name if set.- Since:
- 9
-
setChipName
Set the name of the chip to bind to. If set, this pin will only bind to a gpio chip with this name. Running on different with different chip names will prevent this pin from accidentally binding to an unexpected chip as it would when bound by chip number.- Parameters:
name- name of the gpio chip as returned by the kernel- Since:
- 9
-
getChipNum
Return the chip number if set.- Since:
- 9
-
setChipNum
Set the number of the chip to bind to. If set, this pin will unconditionally bind to the gpio chip with this number, assuming one exists. If running on different hardware, this pin will still bind to the chip with this number and may result in unexpected behavior due to different gpio mappings on different boards. Consider using chip name to only bind to a specific gpio chip.If name and number are both set, only name will be used.
- Parameters:
num- the chip number to use- Since:
- 9
-
getPinName
Return the pin name if set.- Since:
- 9
-
setPinName
Set the name of the pin to bind to. This is the name of the pin on the selected chip as defined by the kernel. By binding to a chip and pin by name, it avoids the case where code running on different hardware accidentally uses gpio pins incorrectly for that hardware.It is common to bind to a chip by name and pin by number. However binding to pin by name provides insight into which pin is being used as pin names are relative to the chip, no the header the pins are exposed though.
- Parameters:
name- the pin name to use- Since:
- 9
-
getPinNum
Return the pin number if set.- Since:
- 9
-
setPinNum
Set the number of the pin to bind to. If set, unconditionally bind to this pin number of the bound chip. If both pin name and number are set, only the pin name will be used.Pin numbers are relative to the associated chip as defined by the kernel. These do not necessarily correspond to positions on an external header.
- Parameters:
num- the pin number to use- Since:
- 9
-
isInverted
public boolean isInverted()Return the value of the inverted flag. When true, all pin values will be inverted internally. This can be used to handle active high vs active low configurations.- Since:
- 9
-
setInverted
Set the inverted flag. When set to true, all pin values will be inverted between this interface and actual hardware.- Parameters:
inverted- if true all values will be inverted- Since:
- 9
-
getBias
Return the bias of the input pin.- Since:
- 9
-
setBias
Set the bias of the input pin. By default the pin has no bias and acts as open collector. The bias can be used to enable pull down or pull up if the hardware supports it.- Parameters:
bias- the bias for the input pin- Since:
- 9
-
getDebounce
public int getDebounce()Return the debounce duration in micro seconds.- Since:
- 9
-
setDebounce
Set the debounce time in micro seconds. This can be used to filter out noisy events that result from mechanical switching.- Parameters:
duration- debounce duration in micro seconds- Since:
- 9
-
getTrueCallback
Return the pin change callback for when the pin value is true.- Since:
- 9
-
setTrueCallback
Set the pin change callback to be called when pin state changes to true. If set, this will be added to theGpioInputPinwhen it is created. Additional callbacks can be added directly to the pin after it is created.- Parameters:
callback- the callback- Since:
- 9
-
getFalseCallback
Return the pin change callback for when the pin value is false.- Since:
- 9
-
setFalseCallback
Set the pin change callback to be called when pin state changes to false. If set, this will be added to theGpioInputPinwhen it is created. Additional callbacks can be added directly to the pin after it is created.- Parameters:
callback- the callback- Since:
- 9
-
isEventOnConnect
public boolean isEventOnConnect()Return true if the input pin should generate a pin event when the adapter connects. If false, pin change events only occur on actual signal changes.- Since:
- 9
-
setEventOnConnect
Set theeventOnConnectflag. When set to true, a pin change event will be triggered when the adapter connects to java using the current value of the gpio pin even though an actual signal transition did not occur. When false, no artificial pin change event will be triggered. Only actual signal changes on the pin will generate events. If not set, defaults to true.
-