| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
""" |
| 5 |
Python bindings for libgpiod. |
| 6 |
|
| 7 |
This module wraps the native C API of libgpiod in a set of python classes. |
| 8 |
""" |
| 9 |
|
| 10 |
from . import _ext |
| 11 |
from . import line |
| 12 |
from .chip import Chip |
| 13 |
from .chip_info import ChipInfo |
| 14 |
from .edge_event import EdgeEvent |
| 15 |
from .exception import ChipClosedError, RequestReleasedError |
| 16 |
from .info_event import InfoEvent |
| 17 |
from .line_info import LineInfo |
| 18 |
from .line_request import LineRequest |
| 19 |
from .line_settings import LineSettings |
| 20 |
from .version import __version__ |
| 21 |
|
| 22 |
api_version = _ext.api_version |
| 23 |
|
| 24 |
|
| 25 |
def is_gpiochip_device(path: str) -> bool: |
| 26 |
""" |
| 27 |
Check if the file pointed to by path is a GPIO chip character device. |
| 28 |
|
| 29 |
Args: |
| 30 |
path |
| 31 |
Path to the file that should be checked. |
| 32 |
|
| 33 |
Returns: |
| 34 |
Returns true if so, False otherwise. |
| 35 |
""" |
| 36 |
return _ext.is_gpiochip_device(path) |
| 37 |
|
| 38 |
|
| 39 |
def request_lines(path: str, *args, **kwargs) -> LineRequest: |
| 40 |
""" |
| 41 |
Open a GPIO chip pointed to by 'path', request lines according to the |
| 42 |
configuration arguments, close the chip and return the request object. |
| 43 |
|
| 44 |
Args: |
| 45 |
path |
| 46 |
Path to the GPIO character device file. |
| 47 |
config: |
| 48 |
Dictionary mapping offsets or names (or tuples thereof) to |
| 49 |
LineSettings. If None is passed as the value of the mapping, |
| 50 |
default settings are used. |
| 51 |
consumer: |
| 52 |
Consumer string to use for this request. |
| 53 |
event_buffer_size: |
| 54 |
Size of the kernel edge event buffer to configure for this request. |
| 55 |
output_values: |
| 56 |
Dictionary mapping offsets or names to line.Value. This can be used |
| 57 |
to set the desired output values globally while reusing LineSettings |
| 58 |
for more lines. |
| 59 |
|
| 60 |
Returns: |
| 61 |
Returns a new LineRequest object. |
| 62 |
""" |
| 63 |
with Chip(path) as chip: |
| 64 |
return chip.request_lines(*args, **kwargs) |