|
|
|
|
@ -23,15 +23,22 @@ fn main() -> () {
|
|
|
|
|
|
|
|
|
|
fn run(input_device: &'static evdev::Device, pedals: impl Iterator<Item = Pedal>) {
|
|
|
|
|
let mut handles: Vec<_> = Vec::new();
|
|
|
|
|
let (tx, rx) = std::sync::mpsc::channel();
|
|
|
|
|
for pedal in pedals {
|
|
|
|
|
let tx = tx.clone();
|
|
|
|
|
let handle = std::thread::spawn(move || loop {
|
|
|
|
|
if input_device.get_key_state().unwrap().contains(pedal.key) {
|
|
|
|
|
(*pedal.action)();
|
|
|
|
|
(*pedal.action)(&tx);
|
|
|
|
|
}
|
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
|
|
|
});
|
|
|
|
|
handles.push(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for recieved in rx {
|
|
|
|
|
println!("{}", recieved);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for handle in handles {
|
|
|
|
|
handle.join().expect("Couldn't join");
|
|
|
|
|
}
|
|
|
|
|
@ -74,5 +81,5 @@ fn create_device() -> Result<evdev::uinput::VirtualDevice, Box<dyn std::error::E
|
|
|
|
|
|
|
|
|
|
pub struct Pedal {
|
|
|
|
|
key: evdev::Key,
|
|
|
|
|
action: Box<dyn Fn() -> () + Send + 'static>,
|
|
|
|
|
action: Box<dyn Fn(&std::sync::mpsc::Sender<String>) -> () + Send + 'static>,
|
|
|
|
|
}
|
|
|
|
|
|