mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-24 00:48:53 +03:00
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>
This commit is contained in:
committed by
Bartosz Golaszewski
parent
36a2127e58
commit
b37bd9edd0
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user