1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-25 12:39:18 +03:00
Files
libgpiod/bindings/python/gpiod/line.py
Kent Gibson 5f9152b0ca bindings: python: support casting line.Value to bool
Python types default to being truthy when cast to bool, so casting
line.Value to bool always returns True.

Add a line.Value.__bool__() operator to map the line value to bool as
one would intuitively expect, so ACTIVE is True and INACTIVE is False.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240522004643.96863-3-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-05-23 09:51:53 +02:00

62 lines
1.2 KiB
Python

# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
from . import _ext
from enum import Enum
__all__ = ["Value", "Direction", "Bias", "Drive", "Edge", "Clock"]
class Value(Enum):
"""Logical line states."""
INACTIVE = _ext.VALUE_INACTIVE
ACTIVE = _ext.VALUE_ACTIVE
def __bool__(self):
return self == self.ACTIVE
class Direction(Enum):
"""Direction settings."""
AS_IS = _ext.DIRECTION_AS_IS
INPUT = _ext.DIRECTION_INPUT
OUTPUT = _ext.DIRECTION_OUTPUT
class Bias(Enum):
"""Internal bias settings."""
AS_IS = _ext.BIAS_AS_IS
UNKNOWN = _ext.BIAS_UNKNOWN
DISABLED = _ext.BIAS_DISABLED
PULL_UP = _ext.BIAS_PULL_UP
PULL_DOWN = _ext.BIAS_PULL_DOWN
class Drive(Enum):
"""Drive settings."""
PUSH_PULL = _ext.DRIVE_PUSH_PULL
OPEN_DRAIN = _ext.DRIVE_OPEN_DRAIN
OPEN_SOURCE = _ext.DRIVE_OPEN_SOURCE
class Edge(Enum):
"""Edge detection settings."""
NONE = _ext.EDGE_NONE
RISING = _ext.EDGE_RISING
FALLING = _ext.EDGE_FALLING
BOTH = _ext.EDGE_BOTH
class Clock(Enum):
"""Event clock settings."""
MONOTONIC = _ext.CLOCK_MONOTONIC
REALTIME = _ext.CLOCK_REALTIME
HTE = _ext.CLOCK_HTE