aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Gibson <warthog618@gmail.com>2023-06-23 12:39:00 +0800
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-06-23 21:32:10 +0200
commitb37bd9edd0927e547e899fc4c21f13d30818d2bd (patch)
tree891ce8c6f61ca07eafcf522a319391c7bfc41f61
parent36a2127e581f57e10b801c1098d863d59a4381d5 (diff)
downloadlibgpiod-b37bd9edd0927e547e899fc4c21f13d30818d2bd.tar.gz
bindings: rust: examples: consistency cleanup
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> Reviewed-by: Erik Schilling <erik.schilling@linaro.org> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
-rw-r--r--bindings/rust/libgpiod/examples/get_line_value.rs4
-rw-r--r--bindings/rust/libgpiod/examples/toggle_line_value.rs17
-rw-r--r--bindings/rust/libgpiod/examples/watch_line_value.rs10
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 732fb716..39141e23 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 cd7038e0..6d5f6973 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 5a95b6ad..3bf40af4 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()