File: line_info.py

package info (click to toggle)
libgpiod 2.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,108 kB
  • sloc: ansic: 26,612; sh: 7,554; cpp: 4,944; python: 2,426; makefile: 811; xml: 49
file content (87 lines) | stat: -rw-r--r-- 2,768 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>

from . import _ext
from dataclasses import dataclass
from datetime import timedelta
from gpiod.line import Direction, Bias, Drive, Edge, Clock

__all__ = "LineInfo"


@dataclass(frozen=True, init=False, repr=False)
class LineInfo:
    """
    Snapshot of a line's status.
    """

    offset: int
    """Offset of the line."""
    name: str
    """Name of the line."""
    used: bool
    """Indicates whether line is in use."""
    consumer: str
    """Name of the consumer of the line."""
    direction: Direction
    """Direction setting of the line."""
    active_low: bool
    """Active-low setting of the line."""
    bias: Bias
    """Bias setting of the line."""
    drive: Drive
    """Drive setting of the line."""
    edge_detection: Edge
    """Edge detection setting of the line."""
    event_clock: Clock
    """Event clock setting used for edge event timestamps for the line."""
    debounced: bool
    """Indicates whether line is debounced."""
    debounce_period: timedelta
    """Debounce period of the line."""

    def __init__(
        self,
        offset: int,
        name: str,
        used: bool,
        consumer: str,
        direction: int,
        active_low: bool,
        bias: int,
        drive: int,
        edge_detection: int,
        event_clock: int,
        debounced: bool,
        debounce_period_us: int,
    ):
        object.__setattr__(self, "offset", offset)
        object.__setattr__(self, "name", name)
        object.__setattr__(self, "used", used)
        object.__setattr__(self, "consumer", consumer)
        object.__setattr__(self, "direction", Direction(direction))
        object.__setattr__(self, "active_low", active_low)
        object.__setattr__(self, "bias", Bias(bias))
        object.__setattr__(self, "drive", Drive(drive))
        object.__setattr__(self, "edge_detection", Edge(edge_detection))
        object.__setattr__(self, "event_clock", Clock(event_clock))
        object.__setattr__(self, "debounced", debounced)
        object.__setattr__(
            self, "debounce_period", timedelta(microseconds=debounce_period_us)
        )

    def __str__(self):
        return '<LineInfo offset={} name="{}" used={} consumer="{}" direction={} active_low={} bias={} drive={} edge_detection={} event_clock={} debounced={} debounce_period={}>'.format(
            self.offset,
            self.name,
            self.used,
            self.consumer,
            self.direction,
            self.active_low,
            self.bias,
            self.drive,
            self.edge_detection,
            self.event_clock,
            self.debounced,
            self.debounce_period,
        )