Begin implementing is_joystick_like
This commit is contained in:
parent
3f3382ffa7
commit
63824510a5
1 changed files with 31 additions and 13 deletions
|
@ -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> {
|
||||
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(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue