From a05ed22f267bd9c1d817b1a62cf2e7ed2ce17bed Mon Sep 17 00:00:00 2001 From: rrr-marble Date: Sat, 26 Jun 2021 21:22:36 +0300 Subject: [PATCH] add: threaded prototype press checker --- src/main.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0703bb3..82a5804 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::{io::Write, thread::sleep}; #[macro_use] extern crate lazy_static; -fn main() -> ! { +fn main() -> () { lazy_static! { static ref D: evdev::Device = { let d = pick_device(); @@ -10,12 +10,23 @@ fn main() -> ! { }; } println!("{}", D.name().unwrap_or("Unknown device")); - loop { + + let side_handle = std::thread::spawn(|| loop { if D.get_key_state().unwrap().contains(evdev::Key::BTN_SIDE) { println!("BTN_SIDE"); } std::thread::sleep(std::time::Duration::from_millis(100)); - } + }); + + let extra_handle = std::thread::spawn(|| loop { + if D.get_key_state().unwrap().contains(evdev::Key::BTN_EXTRA) { + println!("BTN_EXTRA"); + } + std::thread::sleep(std::time::Duration::from_millis(100)); + }); + + extra_handle.join().expect("Couldn't join"); + side_handle.join().expect("Couldn't join"); } fn pick_device() -> evdev::Device {