* [libgpiod][PATCH 0/2] fix potential glitches in bindings example gpiosets @ 2023-06-09 15:36 Kent Gibson 2023-06-09 15:36 ` [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py Kent Gibson 2023-06-09 15:36 ` [libgpiod][PATCH 2/2] bindings: cxx: examples: fix potential glitch in gpiosetcxx Kent Gibson 0 siblings, 2 replies; 10+ messages in thread From: Kent Gibson @ 2023-06-09 15:36 UTC (permalink / raw) To: linux-gpio, brgl; +Cc: Kent Gibson A couple of minor fixes to the bindings examples. Noticed the python one in passing, and fixed that, then checked the other bindings to see if they had the same problem. The rust example is ok, but the cxx example has the same issue, so fixed that as well. The checkin comments are virtually identical, as they fix the same thing for each of the bindings, but the alternative of combining them in one patch seemed weird. Cheers, Kent. Kent Gibson (2): bindings: python: examples: fix potential glitch in gpioset.py bindings: cxx: examples: fix potential glitch in gpiosetcxx bindings/cxx/examples/gpiosetcxx.cpp | 25 ++++++++++--------------- bindings/python/examples/gpioset.py | 10 +++++----- 2 files changed, 15 insertions(+), 20 deletions(-) -- 2.40.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py 2023-06-09 15:36 [libgpiod][PATCH 0/2] fix potential glitches in bindings example gpiosets Kent Gibson @ 2023-06-09 15:36 ` Kent Gibson 2023-06-09 20:18 ` andy.shevchenko 2023-06-12 14:27 ` Bartosz Golaszewski 2023-06-09 15:36 ` [libgpiod][PATCH 2/2] bindings: cxx: examples: fix potential glitch in gpiosetcxx Kent Gibson 1 sibling, 2 replies; 10+ messages in thread From: Kent Gibson @ 2023-06-09 15:36 UTC (permalink / raw) To: linux-gpio, brgl; +Cc: Kent Gibson 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> --- bindings/python/examples/gpioset.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bindings/python/examples/gpioset.py b/bindings/python/examples/gpioset.py index 372a9a8..b36b376 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 settings(v): + return gpiod.LineSettings(direction=Direction.OUTPUT, output_value=v) + lvs = [parse_value(arg) for arg in sys.argv[2:]] - lines = [x[0] for x in lvs] - values = dict(lvs) + config = dict([(l, 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() -- 2.40.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py 2023-06-09 15:36 ` [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py Kent Gibson @ 2023-06-09 20:18 ` andy.shevchenko 2023-06-12 14:26 ` Bartosz Golaszewski 2023-06-12 14:27 ` Bartosz Golaszewski 1 sibling, 1 reply; 10+ messages in thread From: andy.shevchenko @ 2023-06-09 20:18 UTC (permalink / raw) To: Kent Gibson; +Cc: linux-gpio, brgl Fri, Jun 09, 2023 at 11:36:06PM +0800, Kent Gibson kirjoitti: > 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. Do we need a comment in the code to specify this? ... > + config = dict([(l, settings(v)) for (l, v) in lvs]) Aren't [] not needed? -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py 2023-06-09 20:18 ` andy.shevchenko @ 2023-06-12 14:26 ` Bartosz Golaszewski 2023-06-12 14:44 ` Andy Shevchenko 2023-06-12 14:53 ` Kent Gibson 0 siblings, 2 replies; 10+ messages in thread From: Bartosz Golaszewski @ 2023-06-12 14:26 UTC (permalink / raw) To: andy.shevchenko; +Cc: Kent Gibson, linux-gpio On Fri, Jun 9, 2023 at 10:19 PM <andy.shevchenko@gmail.com> wrote: > > Fri, Jun 09, 2023 at 11:36:06PM +0800, Kent Gibson kirjoitti: > > 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. > > Do we need a comment in the code to specify this? > > ... > > > + config = dict([(l, settings(v)) for (l, v) in lvs]) > > Aren't [] not needed? > This is a list comprehension used to create the dictionary. Think: >>> config = dict([(1, 2), (3, 4)]) >>> config {1: 2, 3: 4} Bart > -- > With Best Regards, > Andy Shevchenko > > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py 2023-06-12 14:26 ` Bartosz Golaszewski @ 2023-06-12 14:44 ` Andy Shevchenko 2023-06-12 14:53 ` Kent Gibson 1 sibling, 0 replies; 10+ messages in thread From: Andy Shevchenko @ 2023-06-12 14:44 UTC (permalink / raw) To: Bartosz Golaszewski; +Cc: Kent Gibson, linux-gpio On Mon, Jun 12, 2023 at 5:26 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > On Fri, Jun 9, 2023 at 10:19 PM <andy.shevchenko@gmail.com> wrote: > > Fri, Jun 09, 2023 at 11:36:06PM +0800, Kent Gibson kirjoitti: ... > > > + config = dict([(l, settings(v)) for (l, v) in lvs]) > > > > Aren't [] not needed? > > This is a list comprehension used to create the dictionary. Think: > > >>> config = dict([(1, 2), (3, 4)]) > >>> config > {1: 2, 3: 4} Think about it in dynamic: In [1]: x= [(1,2),(2,4)] In [2]: dict((a,b)for a,b in x) Out[2]: {1: 2, 2: 4} [] are redundant, so I remembered that correctly :-) -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py 2023-06-12 14:26 ` Bartosz Golaszewski 2023-06-12 14:44 ` Andy Shevchenko @ 2023-06-12 14:53 ` Kent Gibson 2023-06-12 14:58 ` Bartosz Golaszewski 1 sibling, 1 reply; 10+ messages in thread From: Kent Gibson @ 2023-06-12 14:53 UTC (permalink / raw) To: andy.shevchenko, Bartosz Golaszewski; +Cc: linux-gpio On Mon, Jun 12, 2023 at 04:26:46PM +0200, Bartosz Golaszewski wrote: > On Fri, Jun 9, 2023 at 10:19 PM <andy.shevchenko@gmail.com> wrote: > > > > Fri, Jun 09, 2023 at 11:36:06PM +0800, Kent Gibson kirjoitti: > > > 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. > > > > Do we need a comment in the code to specify this? > > Andy, I'm not ignoring you - I'm still not getting mail from you, and I hadn't looked on the list for replies. Weird. In answer to your point - yes and no. The code is not doing anything unusual, so no. OTOH it does serve as example code, so a bit of commentary wouldn't hurt. > > ... > > > > > + config = dict([(l, settings(v)) for (l, v) in lvs]) > > > > Aren't [] not needed? > > Ok, but now I did get this one: > Think about it in dynamic: > In [1]: x= [(1,2),(2,4)] > In [2]: dict((a,b)for a,b in x) > Out[2]: {1: 2, 2: 4} > [] are redundant, so I remembered that correctly 😄 Terrible example - which 2 is which? 1,2,3,4 would've been better. True - dict() accepts an iterable, so the [] are redundant in thise case. Cheers, Kent. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py 2023-06-12 14:53 ` Kent Gibson @ 2023-06-12 14:58 ` Bartosz Golaszewski 0 siblings, 0 replies; 10+ messages in thread From: Bartosz Golaszewski @ 2023-06-12 14:58 UTC (permalink / raw) To: Kent Gibson; +Cc: andy.shevchenko, linux-gpio On Mon, Jun 12, 2023 at 4:54 PM Kent Gibson <warthog618@gmail.com> wrote: > > On Mon, Jun 12, 2023 at 04:26:46PM +0200, Bartosz Golaszewski wrote: > > On Fri, Jun 9, 2023 at 10:19 PM <andy.shevchenko@gmail.com> wrote: > > > > > > Fri, Jun 09, 2023 at 11:36:06PM +0800, Kent Gibson kirjoitti: > > > > 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. > > > > > > Do we need a comment in the code to specify this? > > > > > Andy, I'm not ignoring you - I'm still not getting mail from you, and I > hadn't looked on the list for replies. Weird. > > In answer to your point - yes and no. The code is not doing anything > unusual, so no. OTOH it does serve as example code, so a bit of > commentary wouldn't hurt. > > > > ... > > > > > > > + config = dict([(l, settings(v)) for (l, v) in lvs]) > > > > > > Aren't [] not needed? > > > > > Ok, but now I did get this one: > > > Think about it in dynamic: > > > In [1]: x= [(1,2),(2,4)] > > In [2]: dict((a,b)for a,b in x) > > Out[2]: {1: 2, 2: 4} > > > [] are redundant, so I remembered that correctly 😄 > > Terrible example - which 2 is which? > 1,2,3,4 would've been better. > > True - dict() accepts an iterable, so the [] are redundant in thise case. > > Cheers, > Kent. Ok, I will add a follow-up commit. Bart ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py 2023-06-09 15:36 ` [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py Kent Gibson 2023-06-09 20:18 ` andy.shevchenko @ 2023-06-12 14:27 ` Bartosz Golaszewski 1 sibling, 0 replies; 10+ messages in thread From: Bartosz Golaszewski @ 2023-06-12 14:27 UTC (permalink / raw) To: Kent Gibson; +Cc: linux-gpio On Fri, Jun 9, 2023 at 5:36 PM Kent Gibson <warthog618@gmail.com> wrote: > > 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> > --- > bindings/python/examples/gpioset.py | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/bindings/python/examples/gpioset.py b/bindings/python/examples/gpioset.py > index 372a9a8..b36b376 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 settings(v): I renamed this to make_settings() when applying. Thanks. Bart > + return gpiod.LineSettings(direction=Direction.OUTPUT, output_value=v) > + > lvs = [parse_value(arg) for arg in sys.argv[2:]] > - lines = [x[0] for x in lvs] > - values = dict(lvs) > + config = dict([(l, 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() > -- > 2.40.1 > ^ permalink raw reply [flat|nested] 10+ messages in thread
* [libgpiod][PATCH 2/2] bindings: cxx: examples: fix potential glitch in gpiosetcxx 2023-06-09 15:36 [libgpiod][PATCH 0/2] fix potential glitches in bindings example gpiosets Kent Gibson 2023-06-09 15:36 ` [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py Kent Gibson @ 2023-06-09 15:36 ` Kent Gibson 2023-06-09 20:19 ` andy.shevchenko 1 sibling, 1 reply; 10+ messages in thread From: Kent Gibson @ 2023-06-09 15:36 UTC (permalink / raw) To: linux-gpio, brgl; +Cc: Kent Gibson gpiosetcxx 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> --- bindings/cxx/examples/gpiosetcxx.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/bindings/cxx/examples/gpiosetcxx.cpp b/bindings/cxx/examples/gpiosetcxx.cpp index dde5379..ae35038 100644 --- a/bindings/cxx/examples/gpiosetcxx.cpp +++ b/bindings/cxx/examples/gpiosetcxx.cpp @@ -16,8 +16,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - ::gpiod::line::offsets offsets; - ::gpiod::line::values values; + auto builder = ::gpiod::chip(argv[1]).prepare_request(); + builder.set_consumer("gpiosetcxx"); for (int i = 2; i < argc; i++) { ::std::string arg(argv[i]); @@ -31,22 +31,17 @@ int main(int argc, char **argv) throw ::std::invalid_argument("invalid offset=value mapping: " + ::std::string(argv[i])); - offsets.push_back(::std::stoul(offset)); - values.push_back(::std::stoul(value) ? ::gpiod::line::value::ACTIVE : - ::gpiod::line::value::INACTIVE); - } - - auto request = ::gpiod::chip(argv[1]) - .prepare_request() - .set_consumer("gpiosetcxx") - .add_line_settings( - offsets, + ::gpiod::line::value v = ::std::stoul(value) ? + ::gpiod::line::value::ACTIVE : + ::gpiod::line::value::INACTIVE; + builder.add_line_settings( + ::std::stoul(offset), ::gpiod::line_settings() .set_direction(::gpiod::line::direction::OUTPUT) - ) - .do_request(); + .set_output_value(v)); + } - request.set_values(values); + auto request = builder.do_request(); ::std::cin.get(); -- 2.40.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [libgpiod][PATCH 2/2] bindings: cxx: examples: fix potential glitch in gpiosetcxx 2023-06-09 15:36 ` [libgpiod][PATCH 2/2] bindings: cxx: examples: fix potential glitch in gpiosetcxx Kent Gibson @ 2023-06-09 20:19 ` andy.shevchenko 0 siblings, 0 replies; 10+ messages in thread From: andy.shevchenko @ 2023-06-09 20:19 UTC (permalink / raw) To: Kent Gibson; +Cc: linux-gpio, brgl Fri, Jun 09, 2023 at 11:36:07PM +0800, Kent Gibson kirjoitti: > gpiosetcxx 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. Same question about commenting in the code. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-06-12 14:58 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-06-09 15:36 [libgpiod][PATCH 0/2] fix potential glitches in bindings example gpiosets Kent Gibson 2023-06-09 15:36 ` [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py Kent Gibson 2023-06-09 20:18 ` andy.shevchenko 2023-06-12 14:26 ` Bartosz Golaszewski 2023-06-12 14:44 ` Andy Shevchenko 2023-06-12 14:53 ` Kent Gibson 2023-06-12 14:58 ` Bartosz Golaszewski 2023-06-12 14:27 ` Bartosz Golaszewski 2023-06-09 15:36 ` [libgpiod][PATCH 2/2] bindings: cxx: examples: fix potential glitch in gpiosetcxx Kent Gibson 2023-06-09 20:19 ` andy.shevchenko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).