[libgpiod][PATCH 7/8] bindings: rust: examples: consistency cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 .../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




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux