Debian Codegraph @

bindings/python/examples/watch_line_rising.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # SPDX-FileCopyrightText: 2023 Kent Gibson <[email protected]>
4
5 """Minimal example of watching for rising edges on a single line."""
6
7 import gpiod
8
9 from gpiod.line import Edge
10
11
12 def watch_line_rising(chip_path, line_offset):
13 with gpiod.request_lines(
14 chip_path,
15 consumer="watch-line-rising",
16 config={line_offset: gpiod.LineSettings(edge_detection=Edge.RISING)},
17 ) as request:
18 while True:
19 # Blocks until at least one event is available
20 for event in request.read_edge_events():
21 print(
22 "line: {} type: Rising event #{}".format(
23 event.line_offset, event.line_seqno
24 )
25 )
26
27
28 if __name__ == "__main__":
29 try:
30 watch_line_rising("/dev/gpiochip0", 5)
31 except OSError as ex:
32 print(ex, "\nCustomise the example configuration to suit your situation")