From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Mon, 12 Jun 2023 14:53:51 +0000 (+0200)
Subject: bindings: cxx: examples: fix potential glitch in gpiosetcxx
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=9a80247cf4a70c837055271c978afda7ef107338;p=qemu-gpiodev%2Flibgpiod.git

bindings: cxx: examples: fix potential glitch in gpiosetcxx

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.

Suggested-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
---

diff --git a/bindings/cxx/examples/gpiosetcxx.cpp b/bindings/cxx/examples/gpiosetcxx.cpp
index dde5379..f46cb85 100644
--- a/bindings/cxx/examples/gpiosetcxx.cpp
+++ b/bindings/cxx/examples/gpiosetcxx.cpp
@@ -44,10 +44,9 @@ int main(int argc, char **argv)
 			::gpiod::line_settings()
 				.set_direction(::gpiod::line::direction::OUTPUT)
 		)
+		.set_output_values(values)
 		.do_request();
 
-	request.set_values(values);
-
 	::std::cin.get();
 
 	return EXIT_SUCCESS;