| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""Minimal example of reading multiple lines.""" |
| 6 |
|
| 7 |
import gpiod |
| 8 |
|
| 9 |
from gpiod.line import Direction |
| 10 |
|
| 11 |
|
| 12 |
def get_multiple_line_values(chip_path, line_offsets): |
| 13 |
with gpiod.request_lines( |
| 14 |
chip_path, |
| 15 |
consumer="get-multiple-line-values", |
| 16 |
config={tuple(line_offsets): gpiod.LineSettings(direction=Direction.INPUT)}, |
| 17 |
) as request: |
| 18 |
vals = request.get_values() |
| 19 |
|
| 20 |
for offset, val in zip(line_offsets, vals): |
| 21 |
print("{}={} ".format(offset, val), end="") |
| 22 |
print() |
| 23 |
|
| 24 |
|
| 25 |
if __name__ == "__main__": |
| 26 |
try: |
| 27 |
get_multiple_line_values("/dev/gpiochip0", [5, 3, 7]) |
| 28 |
except OSError as ex: |
| 29 |
print(ex, "\nCustomise the example configuration to suit your situation") |