From 7259c836c83793900e7c6cdeaadb7b991d32d402 Mon Sep 17 00:00:00 2001 From: rrr-marble Date: Sun, 27 Jun 2021 21:54:50 +0300 Subject: [PATCH] add: event emission --- src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index cac8b71..2a8f5d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,17 +11,23 @@ fn main() -> () { let d = pick_device(); d }; - static ref OUTPUT_DEVICE: evdev::uinput::VirtualDevice = { - let d = create_device().unwrap(); - d - }; } println!("{}", INPUT_DEVICE.name().unwrap_or("Unknown device")); - run(&INPUT_DEVICE, crate::pedals::pedals().into_iter()); + let mut drum_pedal: evdev::uinput::VirtualDevice = create_device().unwrap(); + + run( + &INPUT_DEVICE, + &mut drum_pedal, + crate::pedals::pedals().into_iter(), + ); } -fn run(input_device: &'static evdev::Device, pedals: impl Iterator) { +fn run( + input_device: &'static evdev::Device, + output_device: &mut evdev::uinput::VirtualDevice, + pedals: impl Iterator, +) { let mut handles: Vec<_> = Vec::new(); let (tx, rx) = std::sync::mpsc::channel(); for pedal in pedals { @@ -36,7 +42,7 @@ fn run(input_device: &'static evdev::Device, pedals: impl Iterator } for recieved in rx { - println!("{:?}", recieved); + output_device.emit(&[recieved]).unwrap(); } for handle in handles {