Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
make code more robust by handling case where gpio is not exported alr…
Browse files Browse the repository at this point in the history
…eady
  • Loading branch information
andygrove committed Sep 16, 2016
1 parent ebd27aa commit 53682c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "qik"
description = "Rust library for the Pololu qik dual serial motor controllers"
version = "1.2.2"
version = "1.2.3"
authors = ["Andy Grove <andygrove73@gmail.com>"]
homepage = "https://github.com/andygrove/rust-qik"
documentation = "https://github.com/andygrove/rust-qik"
Expand Down
14 changes: 11 additions & 3 deletions src/lib.rs
Expand Up @@ -165,14 +165,22 @@ impl Qik {
}

pub fn init(&mut self) -> Result<(), QikError> {
//NOTE: the reset pin must be exported first from the command line
if self.reset_pin.is_exported() {
try!(self.reset());
} else {
try!(self.reset_pin.with_exported(|| self.reset()));
};

try!(self.write_byte(0xAA));
Ok(())
}

fn reset(&self) -> Result<(), sysfs_gpio::Error> {
try!(self.reset_pin.set_value(0));
try!(self.reset_pin.set_direction(Direction::Out));
thread::sleep(Duration::from_millis(1));
try!(self.reset_pin.set_direction(Direction::In));
thread::sleep(Duration::from_millis(10));

try!(self.write_byte(0xAA));
Ok(())
}

Expand Down

0 comments on commit 53682c1

Please sign in to comment.