Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Cargo.lock

# Intellij IDEA
.idea

# macOS DS_Store files
.DS_Store
24 changes: 11 additions & 13 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

extern crate sysfs_gpio;

use sysfs_gpio::{Direction, Pin};
use std::time::Duration;
use std::thread::sleep;
use std::env;
use std::thread::sleep;
use std::time::Duration;
use sysfs_gpio::{Direction, Pin};

struct Arguments {
pin: u64,
Expand Down Expand Up @@ -58,20 +58,18 @@ fn get_args() -> Option<Arguments> {
Err(_) => return None,
};
Some(Arguments {
pin: pin,
duration_ms: duration_ms,
period_ms: period_ms,
})
pin: pin,
duration_ms: duration_ms,
period_ms: period_ms,
})
}

fn main() {
match get_args() {
None => print_usage(),
Some(args) => {
match blink_my_led(args.pin, args.duration_ms, args.period_ms) {
Ok(()) => println!("Success!"),
Err(err) => println!("We have a blinking problem: {}", err),
}
}
Some(args) => match blink_my_led(args.pin, args.duration_ms, args.period_ms) {
Ok(()) => println!("Success!"),
Err(err) => println!("We have a blinking problem: {}", err),
},
}
}
12 changes: 5 additions & 7 deletions examples/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

extern crate sysfs_gpio;

use sysfs_gpio::{Direction, Edge, Pin};
use std::env;
use std::io::prelude::*;
use std::io::stdout;
use sysfs_gpio::{Direction, Edge, Pin};

fn interrupt(pin: u64) -> sysfs_gpio::Result<()> {
let input = Pin::new(pin);
Expand All @@ -38,12 +38,10 @@ fn main() {
println!("Usage: ./interrupt <pin>");
} else {
match args[1].parse::<u64>() {
Ok(pin) => {
match interrupt(pin) {
Ok(()) => println!("Interrupting Complete!"),
Err(err) => println!("Error: {}", err),
}
}
Ok(pin) => match interrupt(pin) {
Ok(()) => println!("Interrupting Complete!"),
Err(err) => println!("Error: {}", err),
},
Err(_) => println!("Usage: ./interrupt <pin>"),
}
}
Expand Down
12 changes: 5 additions & 7 deletions examples/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

extern crate sysfs_gpio;

use sysfs_gpio::{Direction, Pin};
use std::env;
use std::thread::sleep;
use std::time::Duration;
use sysfs_gpio::{Direction, Pin};

fn poll(pin_num: u64) -> sysfs_gpio::Result<()> {
// NOTE: this currently runs forever and as such if
Expand Down Expand Up @@ -40,12 +40,10 @@ fn main() {
println!("Usage: ./poll <pin>");
} else {
match args[1].parse::<u64>() {
Ok(pin) => {
match poll(pin) {
Ok(()) => println!("Polling Complete!"),
Err(err) => println!("Error: {}", err),
}
}
Ok(pin) => match poll(pin) {
Ok(()) => println!("Polling Complete!"),
Err(err) => println!("Error: {}", err),
},
Err(_) => println!("Usage: ./poll <pin>"),
}
}
Expand Down
17 changes: 10 additions & 7 deletions examples/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate tokio;
use std::env;

#[cfg(feature = "use_tokio")]
use futures::{Future, lazy, Stream};
use futures::{lazy, Future, Stream};

#[cfg(feature = "use_tokio")]
use sysfs_gpio::{Direction, Edge, Pin};
Expand All @@ -27,12 +27,15 @@ fn stream(pin_nums: Vec<u64>) -> sysfs_gpio::Result<()> {
pin.export().unwrap();
pin.set_direction(Direction::In).unwrap();
pin.set_edge(Edge::BothEdges).unwrap();
tokio::spawn(pin.get_value_stream().unwrap()
.for_each(move |val| {
println!("Pin {} changed value to {}", i, val);
Ok(())
})
.map_err(|_| ()));
tokio::spawn(
pin.get_value_stream()
.unwrap()
.for_each(move |val| {
println!("Pin {} changed value to {}", i, val);
Ok(())
})
.map_err(|_| ()),
);
}
Ok(())
});
Expand Down
5 changes: 2 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use nix;
use std::convert;
use std::fmt;
use std::io;
use nix;

#[derive(Debug)]
pub enum Error {
Expand All @@ -25,7 +25,7 @@ impl ::std::error::Error for Error {
}
}

fn cause(&self) -> Option<&::std::error::Error> {
fn cause(&self) -> Option<&dyn std::error::Error> {
match *self {
Error::Io(ref e) => Some(e),
_ => None,
Expand All @@ -44,7 +44,6 @@ impl fmt::Display for Error {
}
}


impl convert::From<io::Error> for Error {
fn from(e: io::Error) -> Error {
Error::Io(e)
Expand Down
Loading