fixed read, code clean uo
This commit is contained in:
@@ -32,9 +32,7 @@ fn write(path: &str, value: &str) {
|
||||
#[cfg(debug_assertions)]
|
||||
println!("Wrote value '{}' to '{}'.", value, path);
|
||||
}
|
||||
|
||||
fn read(path: &str) -> String {
|
||||
return String::new();
|
||||
let mut file = File::open(Path::new(path))
|
||||
.expect(format!("Open file '{}' failed", path).as_str());
|
||||
let mut contents = String::new();
|
||||
@@ -62,7 +60,6 @@ fn set_direction(port: &str, direction: &str) {
|
||||
fn set_value(port: &str, value: &str) {
|
||||
write(format!("/sys/class/gpio/gpio{}/value", port).as_str(), value);
|
||||
}
|
||||
|
||||
fn get_value(port: &str) -> String {
|
||||
read(format!("/sys/class/gpio/gpio{}/value", port).as_str())
|
||||
}
|
||||
@@ -70,11 +67,14 @@ fn get_value(port: &str) -> String {
|
||||
fn main() {
|
||||
let signal = chan_signal::notify(&[Signal::INT, Signal::TERM]);
|
||||
let (sdone, rdone) = chan::sync(0);
|
||||
let worker = thread::spawn(move || run(rdone));
|
||||
let worker = thread::Builder::new()
|
||||
.name("worker".to_string())
|
||||
.spawn(move || run(rdone))
|
||||
.expect("Create worker thread failed");
|
||||
|
||||
chan_select! {
|
||||
default => {
|
||||
worker.join();
|
||||
worker.join().expect("Worker thread paniced");
|
||||
},
|
||||
signal.recv() -> signal => {
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -84,6 +84,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run(rdone: chan::Receiver<()>) {
|
||||
// init
|
||||
export(GPIO_PORT_BTN);
|
||||
|
||||
Reference in New Issue
Block a user