|
|
|
@ -1,4 +1,4 @@
|
|
|
|
use std::io::Write;
|
|
|
|
use std::io::Write; //for .flush()
|
|
|
|
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
extern crate lazy_static;
|
|
|
|
@ -7,21 +7,21 @@ mod pedals;
|
|
|
|
|
|
|
|
|
|
|
|
fn main() -> () {
|
|
|
|
fn main() -> () {
|
|
|
|
lazy_static! {
|
|
|
|
lazy_static! {
|
|
|
|
static ref D: evdev::Device = {
|
|
|
|
static ref INPUT_DEVICE: evdev::Device = {
|
|
|
|
let d = pick_device();
|
|
|
|
let d = pick_device();
|
|
|
|
d
|
|
|
|
d
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
println!("{}", D.name().unwrap_or("Unknown device"));
|
|
|
|
println!("{}", INPUT_DEVICE.name().unwrap_or("Unknown device"));
|
|
|
|
|
|
|
|
|
|
|
|
run(&D, crate::pedals::pedals().into_iter());
|
|
|
|
run(&INPUT_DEVICE, crate::pedals::pedals().into_iter());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn run(device: &'static evdev::Device, pedals: impl Iterator<Item = Pedal>) {
|
|
|
|
fn run(input_device: &'static evdev::Device, pedals: impl Iterator<Item = Pedal>) {
|
|
|
|
let mut handles: Vec<_> = Vec::new();
|
|
|
|
let mut handles: Vec<_> = Vec::new();
|
|
|
|
for pedal in pedals {
|
|
|
|
for pedal in pedals {
|
|
|
|
let handle = std::thread::spawn(move || loop {
|
|
|
|
let handle = std::thread::spawn(move || loop {
|
|
|
|
if device.get_key_state().unwrap().contains(pedal.key) {
|
|
|
|
if input_device.get_key_state().unwrap().contains(pedal.key) {
|
|
|
|
(*pedal.action)();
|
|
|
|
(*pedal.action)();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
|
|
|