mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-28 13:55:08 +03:00
Unlike the C++ bindings: we can't expect the python runtime to call the Chip object's destructor when all references are dropped. We need to close each chip explicitly. Either call the close() method directly or use controlled execution in all examples. Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
29 lines
709 B
Python
Executable File
29 lines
709 B
Python
Executable File
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
#
|
|
# This file is part of libgpiod.
|
|
#
|
|
# Copyright (C) 2017-2018 Bartosz Golaszewski <bartekgola@gmail.com>
|
|
#
|
|
|
|
'''Simplified reimplementation of the gpioset tool in Python.'''
|
|
|
|
import gpiod
|
|
import sys
|
|
|
|
if len(sys.argv) < 3:
|
|
raise TypeError('usage: gpioset.py <gpiochip> <offset1>=<value1> ...')
|
|
|
|
with gpiod.Chip(sys.argv[1]) as chip:
|
|
offsets = []
|
|
values = []
|
|
for arg in sys.argv[2:]:
|
|
arg = arg.split('=')
|
|
offsets.append(int(arg[0]))
|
|
values.append(int(arg[1]))
|
|
|
|
lines = chip.get_lines(offsets)
|
|
lines.request(consumer=sys.argv[0], type=gpiod.LINE_REQ_DIR_OUT)
|
|
vals = lines.set_values(values)
|