Class GpioInputPinDef

java.lang.Object
com.kosdev.kos.core.service.gpio.GpioPinBinding
com.kosdev.kos.core.service.gpio.GpioInputPinDef

public class GpioInputPinDef extends GpioPinBinding
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
  • Constructor Details

    • GpioInputPinDef

      public GpioInputPinDef()
  • Method Details

    • getChipName

      public String getChipName()
      Return the chip name if set.
      Since:
      9
    • setChipName

      public GpioInputPinDef setChipName(String name)
      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

      public Integer getChipNum()
      Return the chip number if set.
      Since:
      9
    • setChipNum

      public GpioInputPinDef setChipNum(Integer num)
      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

      public String getPinName()
      Return the pin name if set.
      Since:
      9
    • setPinName

      public GpioInputPinDef setPinName(String name)
      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

      public Integer getPinNum()
      Return the pin number if set.
      Since:
      9
    • setPinNum

      public GpioInputPinDef setPinNum(Integer num)
      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

      public GpioInputPinDef setInverted(boolean inverted)
      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

      public GpioInputPinDef.Bias getBias()
      Return the bias of the input pin.
      Since:
      9
    • setBias

      public GpioInputPinDef setBias(GpioInputPinDef.Bias bias)
      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

      public GpioInputPinDef setDebounce(int duration)
      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

      public GpioPinChangeCallback getTrueCallback()
      Return the pin change callback for when the pin value is true.
      Since:
      9
    • setTrueCallback

      public GpioInputPinDef setTrueCallback(GpioPinChangeCallback callback)
      Set the pin change callback to be called when pin state changes to true. If set, this will be added to the GpioInputPin when it is created. Additional callbacks can be added directly to the pin after it is created.
      Parameters:
      callback - the callback
      Since:
      9
    • getFalseCallback

      public GpioPinChangeCallback getFalseCallback()
      Return the pin change callback for when the pin value is false.
      Since:
      9
    • setFalseCallback

      public GpioInputPinDef setFalseCallback(GpioPinChangeCallback callback)
      Set the pin change callback to be called when pin state changes to false. If set, this will be added to the GpioInputPin when 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

      public GpioInputPinDef setEventOnConnect(boolean flag)
      Set the eventOnConnect flag. 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.