aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Gibson <warthog618@gmail.com>2023-06-09 23:36:06 +0800
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-06-12 16:29:22 +0200
commite13ac9764af3550b7ea6a37ae3f637f90421bd41 (patch)
tree77cc0148fc7c19a6d86b09d43ed1fcbd1996bcec
parent9788bdd3d6791205431e65366dcc518446f7ca6a (diff)
downloadlibgpiod-e13ac9764af3550b7ea6a37ae3f637f90421bd41.tar.gz
bindings: python: examples: fix potential glitch in gpioset.py
gpioset.py requests lines without setting their output value, and so sets them all inactive, and subsequently sets them to their requested value. This can result in glitches on lines which were active and are set active. As this is example code, it is also important to demonstrate that the output value can be set by the request itself. Request the lines with the correct output values set in the request itself. Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
-rwxr-xr-xbindings/python/examples/gpioset.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/bindings/python/examples/gpioset.py b/bindings/python/examples/gpioset.py
index 372a9a86..0323e357 100755
--- a/bindings/python/examples/gpioset.py
+++ b/bindings/python/examples/gpioset.py
@@ -21,16 +21,16 @@ if __name__ == "__main__":
x, y = arg.split("=")
return (x, Value(int(y)))
+ def make_settings(val):
+ return gpiod.LineSettings(direction=Direction.OUTPUT, output_value=val)
+
lvs = [parse_value(arg) for arg in sys.argv[2:]]
- lines = [x[0] for x in lvs]
- values = dict(lvs)
+ config = dict([(l, make_settings(v)) for (l, v) in lvs])
request = gpiod.request_lines(
path,
consumer="gpioset.py",
- config={tuple(lines): gpiod.LineSettings(direction=Direction.OUTPUT)},
+ config=config,
)
- vals = request.set_values(values)
-
input()