mbox series

[libgpiod,0/2] fix potential glitches in bindings example gpiosets

Message ID 20230609153607.133379-1-warthog618@gmail.com
Headers show
Series fix potential glitches in bindings example gpiosets | expand

Message

Kent Gibson June 9, 2023, 3:36 p.m. UTC
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(-)

Comments

Andy Shevchenko June 9, 2023, 8:18 p.m. UTC | #1
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?
Andy Shevchenko June 12, 2023, 2:44 p.m. UTC | #2
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 :-)