Debian Codegraph @

bindings/python/examples/watch_multiple_line_values.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 edges on multiple lines."""
6
7 import gpiod
8
9 from gpiod.line import Edge
10
11
12 def edge_type_str(event):
13 if event.event_type is event.Type.RISING_EDGE:
14 return "Rising"
15 if event.event_type is event.Type.FALLING_EDGE:
16 return "Falling"
17 return "Unknown"
18
19
20 def watch_multiple_line_values(chip_path, line_offsets):
21 with gpiod.request_lines(
22 chip_path,
23 consumer="watch-multiple-line-values",
24 config={tuple(line_offsets): gpiod.LineSettings(edge_detection=Edge.BOTH)},
25 ) as request:
26 while True:
27 for event in request.read_edge_events():
28 print(
29 "offset: {} type: {:<7} event #{} line event #{}".format(
30 event.line_offset,
31 edge_type_str(event),
32 event.global_seqno,
33 event.line_seqno,
34 )
35 )
36
37
38 if __name__ == "__main__":
39 try:
40 watch_multiple_line_values("/dev/gpiochip0", [5, 3, 7])
41 except OSError as ex:
42 print(ex, "\nCustomise the example configuration to suit your situation")