diff --git a/README.md b/README.md index 2fb2600..2bcecce 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ ![License][license] [![CI][CI]](https://github.com/tiagocoutinho/linuxpy/actions/workflows/ci.yml) +[![Source][source]](https://github.com/tiagocoutinho/linuxpy/) +[![Documentation][documentation]](https://tiagocoutinho.github.io/linuxpy/) + Human friendly interface to linux subsystems using python. Provides python access to several linux subsystems like V4L2, GPIO, Led, thermal, @@ -348,3 +351,5 @@ $ python -m linuxpy.midi.cli listen 0:1 14:0 [pypi-status]: https://img.shields.io/pypi/status/linuxpy.svg [license]: https://img.shields.io/pypi/l/linuxpy.svg [CI]: https://github.com/tiagocoutinho/linuxpy/actions/workflows/ci.yml/badge.svg +[documentation]: https://img.shields.io/badge/Documentation-blue?color=grey&logo=mdBook +[source]: https://img.shields.io/badge/Source-grey?logo=git diff --git a/docs/index.md b/docs/index.md index 3ad8409..0b04eff 100644 --- a/docs/index.md +++ b/docs/index.md @@ -11,6 +11,9 @@ hide: [![License][license]]() [![CI][CI]](https://github.com/tiagocoutinho/linuxpy/actions/workflows/ci.yml) +[![Source][source]](https://github.com/tiagocoutinho/linuxpy/) +[![Documentation][documentation]](https://tiagocoutinho.github.io/linuxpy/) + Human friendly interface to linux subsystems using python. Provides python access to several linux subsystems like V4L2, input, GPIO and MIDI. @@ -101,3 +104,5 @@ with providing a common API on different platforms. [pypi-status]: https://img.shields.io/pypi/status/linuxpy.svg [license]: https://img.shields.io/pypi/l/linuxpy.svg [CI]: https://github.com/tiagocoutinho/linuxpy/actions/workflows/ci.yml/badge.svg +[documentation]: https://img.shields.io/badge/Documentation-blue?color=grey&logo=mdBook +[source]: https://img.shields.io/badge/Source-grey?logo=git diff --git a/linuxpy/gpio/device.py b/linuxpy/gpio/device.py index 7bc740b..b6340b1 100644 --- a/linuxpy/gpio/device.py +++ b/linuxpy/gpio/device.py @@ -293,6 +293,12 @@ def set_values(self, values: dict[int, Union[int, bool]]): class Device(BaseDevice): + """ + A device represents a connection to the underlying gpio chip + + + """ + PREFIX = "/dev/gpiochip" def __len__(self) -> int: @@ -306,6 +312,13 @@ def __getitem__(self, key: Union[int, tuple, slice]) -> Request: return self.request(lines) def get_info(self) -> Info: + """ + Reads all information available including chip info and detailed information + about each chip line information + + Returns: + Info: The full chip information + """ return get_info(self) def request(self, lines: Optional[Sequence[int]] = None, name: str = "", flags: LineFlag = LineFlag(0)) -> Request: @@ -324,4 +337,4 @@ def iter_devices(path: PathLike = "/dev", **kwargs) -> Iterable[Device]: return (Device(name, **kwargs) for name in iter_gpio_files(path=path)) -find = make_find(iter_devices) +find = make_find(iter_devices, needs_open=False) diff --git a/scripts/setup-gpio-sim.py b/scripts/setup-gpio-sim.py index 6d2138b..6f08d39 100644 --- a/scripts/setup-gpio-sim.py +++ b/scripts/setup-gpio-sim.py @@ -27,6 +27,7 @@ def Line(name, direction=None): Line("L-I2", "input"), Line("L-O0", "output-high"), Line("L-O1", "output-low"), + Line("L-O2"), ] }, ], diff --git a/tests/test_gpio.py b/tests/test_gpio.py index e863a2c..21ae484 100644 --- a/tests/test_gpio.py +++ b/tests/test_gpio.py @@ -437,6 +437,7 @@ def _(): assert l0.flags == raw.LineFlag.INPUT assert l0.name == "L-I0" assert l0.consumer == "" + assert l0.offset == 0 assert l0.attributes.flags == 0 assert isclose(l0.attributes.debounce_period, 0) @@ -444,24 +445,28 @@ def _(): assert l1.flags == raw.LineFlag.INPUT assert l1.name == "L-I1" assert l1.consumer == "" + assert l1.offset == 1 assert l1.attributes.flags == 0 l2 = info.lines[2] assert l2.flags == raw.LineFlag.USED | raw.LineFlag.INPUT assert l2.name == "L-I2" assert l2.consumer == "L-I2-hog" + assert l2.offset == 2 assert l2.attributes.flags == 0 l3 = info.lines[3] assert l3.flags == raw.LineFlag.USED | raw.LineFlag.OUTPUT assert l3.name == "L-O0" assert l3.consumer == "L-O0-hog" + assert l3.offset == 3 assert l3.attributes.flags == 0 l4 = info.lines[4] assert l4.flags == raw.LineFlag.USED | raw.LineFlag.OUTPUT assert l4.name == "L-O1" assert l4.consumer == "L-O1-hog" + assert l4.offset == 4 assert l4.attributes.flags == 0 @@ -495,6 +500,14 @@ def _(): # close the request to make sure it always succeeds request.close() + with device.request([5, 12], "myself", raw.LineFlag.OUTPUT) as request: + info = device.get_info() + l5 = info.lines[5] + assert l5.flags == raw.LineFlag.USED | raw.LineFlag.OUTPUT + assert l5.name == "L-O2" + assert l5.consumer == "myself" + assert l5.attributes.flags == 0 + @test("sim get value") def _():