From 63824510a5133dc15ed8c3cd45321c47c98e8da6 Mon Sep 17 00:00:00 2001 From: Anna Rose Wiggins Date: Fri, 8 Aug 2025 10:21:48 -0400 Subject: [PATCH] Begin implementing is_joystick_like --- src/bin/evinfo.rs | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/bin/evinfo.rs b/src/bin/evinfo.rs index 82665f1..da52482 100644 --- a/src/bin/evinfo.rs +++ b/src/bin/evinfo.rs @@ -6,7 +6,7 @@ use evdev::raw_stream::RawDevice; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Args { - /// Print additional information + /// Print additional information about each device. (-vv for even more verbosity) #[arg(short, long, action = clap::ArgAction::Count)] verbose: u8, } @@ -14,15 +14,35 @@ struct Args { fn main() { let args = Args::parse(); let devices = evdev::raw_stream::enumerate(); - devices.for_each(|(path, dev)| match print_device(path, dev, args.verbose) { - Ok(_) => return, - Err(err) => println!("Failed to print device info: {err}"), + devices.for_each(|(path, dev)| { + if is_joystick_like(&dev) { + print_device(path, dev, args.verbose) + } }); - - println!("{}", args.verbose); } -fn print_device(path: PathBuf, device: RawDevice, verbose: u8) -> Result<(), std::io::Error> { +// Todo: can use a macro here... +const JOYSTICK_BUTTONS: Vec { + evdev::KeyCode::BTN_TRIGGER_HAPPY1, + evdev::KeyCode::BTN_TRIGGER_HAPPY2, + evdev::KeyCode::BTN_TRIGGER_HAPPY3, + evdev::KeyCode::BTN_TRIGGER_HAPPY4, + evdev::KeyCode::BTN_TRIGGER_HAPPY5, + evdev::KeyCode::BTN_TRIGGER_HAPPY6, + evdev::KeyCode::BTN_TRIGGER_HAPPY7, + evdev::KeyCode::BTN_TRIGGER_HAPPY8, + evdev::KeyCode::BTN_TRIGGER_HAPPY9, + evdev::KeyCode::BTN_TRIGGER_HAPPY10, +} + +fn is_joystick_like(device: &RawDevice) -> bool { + + if device.supported_absolute_axes().map_or(false, |axes| axes.contains()); + + return false; +} + +fn print_device(path: PathBuf, device: RawDevice, verbose: u8) { println!( "{}: \"{}\"", path.to_str().unwrap_or_default(), @@ -31,10 +51,10 @@ fn print_device(path: PathBuf, device: RawDevice, verbose: u8) -> Result<(), std if verbose > 0 { let input_id = device.input_id(); - println!("\tUUID:\t{}", device.unique_name().unwrap_or_default()); - println!("\tVendor:\t{}", input_id.vendor()); - println!("\tProduct:\t{}", input_id.product()); - println!("\tVersion:\t{}", input_id.version()); + println!("\tUUID:\t\t'{}'", device.unique_name().unwrap_or_default()); + println!("\tVendor:\t\t'{:x}'", input_id.vendor()); + println!("\tProduct:\t'{:x}'", input_id.product()); + println!("\tVersion:\t'{}'", input_id.version()); } // if verbose > 1 { @@ -44,6 +64,4 @@ fn print_device(path: PathBuf, device: RawDevice, verbose: u8) -> Result<(), std // absInfo.for_each(|info| println!("\t\t{} {}")); // } // } - - Ok(()) }