herosdevices.core.gpio - Heros Devices 0.6.0 documentation

Skip to content
Back to top
View this page

# herosdevices.core.gpio

General drivers for GPIO pins which can be used with the gpiod library.

## Module Contents

class herosdevices.core.gpio.GPIOOutput(gpiochip: int, pin: int, drive: str = 'PUSH_PULL')

  Bases: `herosdevices.interfaces.atomiq.Switch`

  A single GPIO configured as output.

  The access to the GPIO is based on libgpiod and thus uses the standard linux kernel interface (i.e. /dev/gpiochip* devices).

  Parameters:

    - gpiochip – number of the gpiochip as exposed by the linux kernel.

    - pin – number of the GPIO pin

    - drive – how to drive the GPIO pin. Possible values: PUSH_PULL (default), OPEN_SOURCE, OPEN_DRAIN

  gpio_chip
  gpio
  pin
  on() → None

    Set GPIO pin to logically active state.

    Default is that active means the pin is high, but the behavior can be changed.

  off() → None

    Set GPIO pin to logically inactive state.

    Default is that inactive means the pin is low, but the behavior can be changed.

  is_on() → bool

    Return the current logical state of the GPIO pin (ACTIVE = True, INACTIVE = False).

class herosdevices.core.gpio.GPIOInput(gpiochip: int, pin: int, drive: str = 'PUSH_PULL', bias: str = 'AS_IS', debounce_ms: int = 5, edge_detection: str = 'NONE', loop: asyncio.AbstractEventLoop | None = None)

  Bases: `herosdevices.interfaces.atomiq.Measurable`

  A single GPIO configured as input.

  The access to the GPIO is based on libgpiod and thus uses the standard linux kernel interface (i.e. /dev/gpiochip* devices).

  Parameters:

    - gpiochip – number of the gpiochip as exposed by the linux kernel.

    - pin – number of the GPIO pin

    - bias – bis to apply to the GPIO pin. Possible values: AS_IS (default), DISABLED, PULL_DOWN, PULL_UP, UNKNOWN

    - debounce_ms – debouncing time in milliseconds.

    - edge_detection – If given it performs the specified edge detection an issues an edge event. Valid values are BOTH, FALLING, NONE, RISING. For this to work, an asyncio loop has to given as well.

    - loop – asyncio loop in which the edge detection task can be performed. This is required if edge detection is set.

    - drive – Currently unused.

  gpio_chip
  gpio
  pin
  debounce_ms = 5
  status() → bool

    Get the current input level of the GPIO pin. (True = ACTIVE, False = INACTIVE).

    Default is that active means the pin is high, but the behavior can be changed.

  is_on() → bool

    Alias for `status()`.

  measure(channel: str = '') → bool

    Alias for `status()`.

  edge_event(edge: gpiod.EdgeEvent) → dict

    Emit an HEROS event with the edge event data.

    Returns:

      A dict with the keys type and timestamp.