From: Kent Gibson <warthog618@gmail.com>
To: linux-gpio@vger.kernel.org, brgl@bgdev.pl
Cc: Kent Gibson <warthog618@gmail.com>
Subject: [libgpiod][PATCH 7/8] bindings: rust: examples: consistency cleanup
Date: Fri, 23 Jun 2023 12:39:00 +0800 [thread overview]
Message-ID: <20230623043901.16764-8-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
Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
.../rust/libgpiod/examples/get_line_value.rs | 4 ++--
.../rust/libgpiod/examples/toggle_line_value.rs | 17 ++++++++---------
.../rust/libgpiod/examples/watch_line_value.rs | 10 +++++-----
3 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/bindings/rust/libgpiod/examples/get_line_value.rs b/bindings/rust/libgpiod/examples/get_line_value.rs
index 732fb71..39141e2 100644
--- a/bindings/rust/libgpiod/examples/get_line_value.rs
+++ b/bindings/rust/libgpiod/examples/get_line_value.rs
@@ -6,7 +6,7 @@
use libgpiod::line;
fn main() -> libgpiod::Result<()> {
- // example configuration - customize to suit your situation
+ // Example configuration - customize to suit your situation
let chip_path = "/dev/gpiochip0";
let line_offset = 5;
@@ -23,6 +23,6 @@ fn main() -> libgpiod::Result<()> {
let request = chip.request_lines(Some(&rconfig), &lconfig)?;
let value = request.value(line_offset)?;
- println!("{:?}", value);
+ println!("{}={:?}", line_offset, value);
Ok(())
}
diff --git a/bindings/rust/libgpiod/examples/toggle_line_value.rs b/bindings/rust/libgpiod/examples/toggle_line_value.rs
index cd7038e..6d5f697 100644
--- a/bindings/rust/libgpiod/examples/toggle_line_value.rs
+++ b/bindings/rust/libgpiod/examples/toggle_line_value.rs
@@ -3,22 +3,21 @@
//
// Minimal example of toggling a single line.
-use libgpiod::line;
-use std::time::Duration;
+use core::time::Duration;
+use libgpiod::line::{self, Value};
-fn toggle_value(value: line::Value) -> line::Value {
+fn toggle_value(value: Value) -> Value {
match value {
- line::Value::Active => line::Value::InActive,
- line::Value::InActive => line::Value::Active,
+ Value::Active => Value::InActive,
+ Value::InActive => Value::Active,
}
}
fn main() -> libgpiod::Result<()> {
- // example configuration - customize to suit your situation
+ // Example configuration - customize to suit your situation
let chip_path = "/dev/gpiochip0";
let line_offset = 5;
-
- let mut value = line::Value::Active;
+ let mut value = Value::Active;
let mut settings = line::Settings::new()?;
settings
@@ -35,7 +34,7 @@ fn main() -> libgpiod::Result<()> {
let mut req = chip.request_lines(Some(&rconfig), &lconfig)?;
loop {
- println!("{:?}", value);
+ println!("{}={:?}", line_offset, value);
std::thread::sleep(Duration::from_secs(1));
value = toggle_value(value);
req.set_value(line_offset, value)?;
diff --git a/bindings/rust/libgpiod/examples/watch_line_value.rs b/bindings/rust/libgpiod/examples/watch_line_value.rs
index 5a95b6a..3bf40af 100644
--- a/bindings/rust/libgpiod/examples/watch_line_value.rs
+++ b/bindings/rust/libgpiod/examples/watch_line_value.rs
@@ -7,12 +7,12 @@ use libgpiod::line;
use std::time::Duration;
fn main() -> libgpiod::Result<()> {
- // example configuration - customize to suit your situation
+ // Example configuration - customize to suit your situation
let chip_path = "/dev/gpiochip0";
let line_offset = 5;
let mut lsettings = line::Settings::new()?;
- // assume a button connecting the pin to ground,
+ // Assume a button connecting the pin to ground,
// so pull it up and provide some debounce.
lsettings
.set_edge_detection(Some(line::Edge::Both))?
@@ -28,7 +28,7 @@ fn main() -> libgpiod::Result<()> {
let chip = libgpiod::chip::Chip::open(&chip_path)?;
let request = chip.request_lines(Some(&rconfig), &lconfig)?;
- // a larger buffer is an optimisation for reading bursts of events from the
+ // A larger buffer is an optimisation for reading bursts of events from the
// kernel, but that is not necessary in this case, so 1 is fine.
let mut buffer = libgpiod::request::Buffer::new(1)?;
loop {
@@ -37,10 +37,10 @@ fn main() -> libgpiod::Result<()> {
for event in events {
let event = event?;
println!(
- "line: {}, type: {}, event #{}",
+ "line: {} type: {:<7} event #{}",
event.line_offset(),
match event.event_type()? {
- line::EdgeKind::Rising => "Rising ",
+ line::EdgeKind::Rising => "Rising",
line::EdgeKind::Falling => "Falling",
},
event.line_seqno()
--
2.41.0
next prev parent reply other threads:[~2023-06-23 4:40 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 ` [libgpiod][PATCH 3/8] bindings: cxx: examples: consistency cleanup Kent Gibson
2023-06-23 4:38 ` [libgpiod][PATCH 4/8] bindings: cxx: examples: replace tools examples with use case examples 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 ` Kent Gibson [this message]
2023-06-23 7:58 ` [libgpiod][PATCH 7/8] bindings: rust: examples: consistency cleanup 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-8-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.