| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
from . import _ext |
| 5 |
from dataclasses import dataclass |
| 6 |
from datetime import timedelta |
| 7 |
from gpiod.line import Direction, Bias, Drive, Edge, Clock, Value |
| 8 |
|
| 9 |
__all__ = "LineSettings" |
| 10 |
|
| 11 |
|
| 12 |
@dataclass(repr=False) |
| 13 |
class LineSettings: |
| 14 |
""" |
| 15 |
Stores a set of line properties. |
| 16 |
""" |
| 17 |
|
| 18 |
direction: Direction = Direction.AS_IS |
| 19 |
"""Line direction.""" |
| 20 |
edge_detection: Edge = Edge.NONE |
| 21 |
"""Edge detection setting.""" |
| 22 |
bias: Bias = Bias.AS_IS |
| 23 |
"""Line bias setting.""" |
| 24 |
drive: Drive = Drive.PUSH_PULL |
| 25 |
"""Line drive setting.""" |
| 26 |
active_low: bool = False |
| 27 |
"""Active-low switch.""" |
| 28 |
debounce_period: timedelta = timedelta() |
| 29 |
"""Debounce period of the line.""" |
| 30 |
event_clock: Clock = Clock.MONOTONIC |
| 31 |
"""Edge event timestamping clock setting.""" |
| 32 |
output_value: Value = Value.INACTIVE |
| 33 |
"""Output value of the line.""" |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
def __repr__(self): |
| 38 |
return "gpiod.LineSettings(direction=gpiod.line.{}, edge_detection=gpiod.line.{}, bias=gpiod.line.{}, drive=gpiod.line.{}, active_low={}, debounce_period={}, event_clock=gpiod.line.{}, output_value=gpiod.line.{})".format( |
| 39 |
str(self.direction), |
| 40 |
str(self.edge_detection), |
| 41 |
str(self.bias), |
| 42 |
str(self.drive), |
| 43 |
self.active_low, |
| 44 |
repr(self.debounce_period), |
| 45 |
str(self.event_clock), |
| 46 |
str(self.output_value), |
| 47 |
) |
| 48 |
|
| 49 |
def __str__(self): |
| 50 |
return "<LineSettings direction={} edge_detection={} bias={} drive={} active_low={} debounce_period={} event_clock={} output_value={}>".format( |
| 51 |
self.direction, |
| 52 |
self.edge_detection, |
| 53 |
self.bias, |
| 54 |
self.drive, |
| 55 |
self.active_low, |
| 56 |
self.debounce_period, |
| 57 |
self.event_clock, |
| 58 |
self.output_value, |
| 59 |
) |
| 60 |
|
| 61 |
|
| 62 |
def _line_settings_to_ext(settings: LineSettings) -> _ext.LineSettings: |
| 63 |
return _ext.LineSettings( |
| 64 |
direction=settings.direction.value, |
| 65 |
edge_detection=settings.edge_detection.value, |
| 66 |
bias=settings.bias.value, |
| 67 |
drive=settings.drive.value, |
| 68 |
active_low=settings.active_low, |
| 69 |
debounce_period=int(settings.debounce_period.total_seconds() * 1000000), |
| 70 |
event_clock=settings.event_clock.value, |
| 71 |
output_value=settings.output_value.value, |
| 72 |
) |