From: Kent Gibson <warthog618@gmail.com>
To: linux-gpio@vger.kernel.org, brgl@bgdev.pl
Cc: Kent Gibson <warthog618@gmail.com>
Subject: [libgpiod][PATCH 3/8] bindings: cxx: examples: consistency cleanup
Date: Fri, 23 Jun 2023 12:38:56 +0800 [thread overview]
Message-ID: <20230623043901.16764-4-warthog618@gmail.com> (raw)
In-Reply-To: <20230623043901.16764-1-warthog618@gmail.com>
A collection of minor changes to be more consistent with other examples:
- capitalize comments
- add line offset to value outputs
- drop comma from edge event outputs
- drop trailing return where example loops indefintely
- sort includes
Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
.../cxx/examples/async_watch_line_value.cpp | 8 +++---
bindings/cxx/examples/get_line_value.cpp | 28 +++++++++++--------
bindings/cxx/examples/toggle_line_value.cpp | 16 +++++------
bindings/cxx/examples/watch_line_value.cpp | 12 ++++----
4 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/bindings/cxx/examples/async_watch_line_value.cpp b/bindings/cxx/examples/async_watch_line_value.cpp
index e1d4a1e..d8317a5 100644
--- a/bindings/cxx/examples/async_watch_line_value.cpp
+++ b/bindings/cxx/examples/async_watch_line_value.cpp
@@ -7,6 +7,7 @@
#include <cstring>
#include <filesystem>
#include <gpiod.hpp>
+#include <iomanip>
#include <iostream>
#include <poll.h>
@@ -79,10 +80,9 @@ int main(void)
for (const auto& event : buffer)
::std::cout << "offset: " << event.line_offset()
- << ", type: " << edge_event_type_str(event)
- << ", event #" << event.line_seqno()
+ << " type: " << ::std::setw(7)
+ << ::std::left << edge_event_type_str(event)
+ << " event #" << event.line_seqno()
<< ::std::endl;
}
-
- return EXIT_SUCCESS;
}
diff --git a/bindings/cxx/examples/get_line_value.cpp b/bindings/cxx/examples/get_line_value.cpp
index 8f4e739..a14d7e4 100644
--- a/bindings/cxx/examples/get_line_value.cpp
+++ b/bindings/cxx/examples/get_line_value.cpp
@@ -10,7 +10,7 @@
namespace {
-/* example configuration - customize to suit your situation */
+/* Example configuration - customize to suit your situation */
const ::std::filesystem::path chip_path("/dev/gpiochip0");
const ::gpiod::line::offset line_offset = 5;
@@ -18,17 +18,21 @@ const ::gpiod::line::offset line_offset = 5;
int main(void)
{
- auto request =
- ::gpiod::chip(chip_path)
- .prepare_request()
- .set_consumer("get-line-value")
- .add_line_settings(
- line_offset,
- ::gpiod::line_settings().set_direction(
- ::gpiod::line::direction::INPUT))
- .do_request();
-
- ::std::cout << request.get_value(line_offset) << ::std::endl;
+ auto request = ::gpiod::chip(chip_path)
+ .prepare_request()
+ .set_consumer("get-line-value")
+ .add_line_settings(
+ line_offset,
+ ::gpiod::line_settings().set_direction(
+ ::gpiod::line::direction::INPUT))
+ .do_request();
+
+ ::std::cout << line_offset << "="
+ << (request.get_value(line_offset) ==
+ ::gpiod::line::value::ACTIVE ?
+ "Active" :
+ "Inactive")
+ << ::std::endl;
return EXIT_SUCCESS;
}
diff --git a/bindings/cxx/examples/toggle_line_value.cpp b/bindings/cxx/examples/toggle_line_value.cpp
index a060e8a..a17b43b 100644
--- a/bindings/cxx/examples/toggle_line_value.cpp
+++ b/bindings/cxx/examples/toggle_line_value.cpp
@@ -6,8 +6,8 @@
#include <cstdlib>
#include <chrono>
#include <filesystem>
-#include <iostream>
#include <gpiod.hpp>
+#include <iostream>
#include <thread>
namespace {
@@ -19,15 +19,15 @@ const ::gpiod::line::offset line_offset = 5;
::gpiod::line::value toggle_value(::gpiod::line::value v)
{
return (v == ::gpiod::line::value::ACTIVE) ?
- ::gpiod::line::value::INACTIVE :
- ::gpiod::line::value::ACTIVE;
+ ::gpiod::line::value::INACTIVE :
+ ::gpiod::line::value::ACTIVE;
}
} /* namespace */
int main(void)
{
- ::gpiod::line::value val = ::gpiod::line::value::ACTIVE;
+ ::gpiod::line::value value = ::gpiod::line::value::ACTIVE;
auto request =
::gpiod::chip(chip_path)
@@ -40,12 +40,10 @@ int main(void)
.do_request();
for (;;) {
- ::std::cout << val << ::std::endl;
+ ::std::cout << line_offset << "=" << value << ::std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
- val = toggle_value(val);
- request.set_value(line_offset, val);
+ value = toggle_value(value);
+ request.set_value(line_offset, value);
}
-
- return EXIT_SUCCESS;
}
diff --git a/bindings/cxx/examples/watch_line_value.cpp b/bindings/cxx/examples/watch_line_value.cpp
index 5436884..5055789 100644
--- a/bindings/cxx/examples/watch_line_value.cpp
+++ b/bindings/cxx/examples/watch_line_value.cpp
@@ -6,6 +6,7 @@
#include <cstdlib>
#include <filesystem>
#include <gpiod.hpp>
+#include <iomanip>
#include <iostream>
namespace {
@@ -18,7 +19,7 @@ const char *edge_event_type_str(const ::gpiod::edge_event &event)
{
switch (event.type()) {
case ::gpiod::edge_event::event_type::RISING_EDGE:
- return "Rising ";
+ return "Rising";
case ::gpiod::edge_event::event_type::FALLING_EDGE:
return "Falling";
default:
@@ -61,11 +62,10 @@ int main(void)
request.read_edge_events(buffer);
for (const auto &event : buffer)
- ::std::cout << "offset: " << event.line_offset()
- << ", type: " << edge_event_type_str(event)
- << ", event #" << event.line_seqno()
+ ::std::cout << "line: " << event.line_offset()
+ << " type: " << ::std::setw(7)
+ << ::std::left << edge_event_type_str(event)
+ << " event #" << event.line_seqno()
<< ::std::endl;
}
-
- return EXIT_SUCCESS;
}
--
2.41.0
next prev parent reply other threads:[~2023-06-23 4:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-23 4:38 [libgpiod][PATCH 0/8] replace tool examples with use case examples Kent Gibson
2023-06-23 4:38 ` [libgpiod][PATCH 1/8] core: examples: consistency cleanups Kent Gibson
2023-06-23 4:38 ` [libgpiod][PATCH 2/8] core: examples: add more use case examples Kent Gibson
2023-06-23 4:38 ` Kent Gibson [this message]
2023-06-23 4:38 ` [libgpiod][PATCH 4/8] bindings: cxx: examples: replace tools examples with " Kent Gibson
2023-06-23 4:38 ` [libgpiod][PATCH 5/8] bindings: python: examples: consistency cleanup Kent Gibson
2023-06-23 4:38 ` [libgpiod][PATCH 6/8] bindings: python: examples: replace tools examples with use case examples Kent Gibson
2023-06-23 19:31 ` Bartosz Golaszewski
2023-06-23 4:39 ` [libgpiod][PATCH 7/8] bindings: rust: examples: consistency cleanup Kent Gibson
2023-06-23 7:58 ` Erik Schilling
2023-06-23 4:39 ` [libgpiod][PATCH 8/8] bindings: rust: examples: replace tools examples with use case examples Kent Gibson
2023-06-23 7:57 ` Erik Schilling
2023-06-23 8:26 ` Kent Gibson
2023-06-23 19:35 ` [libgpiod][PATCH 0/8] replace tool " Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230623043901.16764-4-warthog618@gmail.com \
--to=warthog618@gmail.com \
--cc=brgl@bgdev.pl \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).