From: Bartosz Golaszewski Date: Fri, 10 Mar 2023 09:59:47 +0000 (+0100) Subject: bindings: python: examples: add gpionotify.py X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=40252603516b510b8c728a7d22b1ac99dcefbe1d;p=qemu-gpiodev%2Flibgpiod.git bindings: python: examples: add gpionotify.py Add a new Python code examples - gpionotify.py - which is a simplified reimplementation of the gpionotify tool. Signed-off-by: Bartosz Golaszewski --- diff --git a/bindings/python/examples/Makefile.am b/bindings/python/examples/Makefile.am index f42b80e..9463a9f 100644 --- a/bindings/python/examples/Makefile.am +++ b/bindings/python/examples/Makefile.am @@ -7,4 +7,5 @@ EXTRA_DIST = \ gpioget.py \ gpioinfo.py \ gpiomon.py \ + gpionotify.py \ gpioset.py diff --git a/bindings/python/examples/gpionotify.py b/bindings/python/examples/gpionotify.py new file mode 100755 index 0000000..4e50515 --- /dev/null +++ b/bindings/python/examples/gpionotify.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later +# SPDX-FileCopyrightText: 2023 Bartosz Golaszewski + +"""Simplified reimplementation of the gpionotify tool in Python.""" + +import gpiod +import sys + +if __name__ == "__main__": + if len(sys.argv) < 3: + raise TypeError("usage: gpionotify.py ...") + + path = sys.argv[1] + + with gpiod.Chip(path) as chip: + for line in sys.argv[2:]: + chip.watch_line_info(line) + + while True: + print(chip.read_info_event())