| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""Example of a bi-directional line requested as input and then switched to output.""" |
| 6 |
|
| 7 |
import gpiod |
| 8 |
|
| 9 |
from gpiod.line import Direction, Value |
| 10 |
|
| 11 |
|
| 12 |
def reconfigure_input_to_output(chip_path, line_offset): |
| 13 |
|
| 14 |
with gpiod.request_lines( |
| 15 |
chip_path, |
| 16 |
consumer="reconfigure-input-to-output", |
| 17 |
config={line_offset: gpiod.LineSettings(direction=Direction.INPUT)}, |
| 18 |
) as request: |
| 19 |
|
| 20 |
value = request.get_value(line_offset) |
| 21 |
print("{}={} (input)".format(line_offset, value)) |
| 22 |
|
| 23 |
request.reconfigure_lines( |
| 24 |
config={ |
| 25 |
line_offset: gpiod.LineSettings( |
| 26 |
direction=Direction.OUTPUT, output_value=Value.INACTIVE |
| 27 |
) |
| 28 |
} |
| 29 |
) |
| 30 |
|
| 31 |
value = request.get_value(line_offset) |
| 32 |
print("{}={} (output)".format(line_offset, value)) |
| 33 |
|
| 34 |
|
| 35 |
if __name__ == "__main__": |
| 36 |
try: |
| 37 |
reconfigure_input_to_output("/dev/gpiochip0", 5) |
| 38 |
except OSError as ex: |
| 39 |
print(ex, "\nCustomise the example configuration to suit your situation") |