Eh.
This commit is contained in:
parent
63824510a5
commit
43bdc008a1
1 changed files with 33 additions and 18 deletions
|
@ -14,15 +14,15 @@ struct Args {
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let devices = evdev::raw_stream::enumerate();
|
let devices = evdev::raw_stream::enumerate();
|
||||||
devices.for_each(|(path, dev)| {
|
|
||||||
|
for (path, dev) in devices {
|
||||||
if is_joystick_like(&dev) {
|
if is_joystick_like(&dev) {
|
||||||
print_device(path, dev, args.verbose)
|
print_device(path, dev, args.verbose)
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo: can use a macro here...
|
const JOYSTICK_BUTTONS: &[evdev::KeyCode] = &[
|
||||||
const JOYSTICK_BUTTONS: Vec<evdev::KeyCode> {
|
|
||||||
evdev::KeyCode::BTN_TRIGGER_HAPPY1,
|
evdev::KeyCode::BTN_TRIGGER_HAPPY1,
|
||||||
evdev::KeyCode::BTN_TRIGGER_HAPPY2,
|
evdev::KeyCode::BTN_TRIGGER_HAPPY2,
|
||||||
evdev::KeyCode::BTN_TRIGGER_HAPPY3,
|
evdev::KeyCode::BTN_TRIGGER_HAPPY3,
|
||||||
|
@ -33,11 +33,21 @@ const JOYSTICK_BUTTONS: Vec<evdev::KeyCode> {
|
||||||
evdev::KeyCode::BTN_TRIGGER_HAPPY8,
|
evdev::KeyCode::BTN_TRIGGER_HAPPY8,
|
||||||
evdev::KeyCode::BTN_TRIGGER_HAPPY9,
|
evdev::KeyCode::BTN_TRIGGER_HAPPY9,
|
||||||
evdev::KeyCode::BTN_TRIGGER_HAPPY10,
|
evdev::KeyCode::BTN_TRIGGER_HAPPY10,
|
||||||
}
|
evdev::KeyCode::BTN_TRIGGER_HAPPY11,
|
||||||
|
];
|
||||||
|
|
||||||
fn is_joystick_like(device: &RawDevice) -> bool {
|
fn is_joystick_like(device: &RawDevice) -> bool {
|
||||||
|
if let Some(_) = device.supported_absolute_axes() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if device.supported_absolute_axes().map_or(false, |axes| axes.contains());
|
if let Some(keys) = device.supported_keys() {
|
||||||
|
for key in keys.iter() {
|
||||||
|
if JOYSTICK_BUTTONS.contains(&key) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -45,23 +55,28 @@ fn is_joystick_like(device: &RawDevice) -> bool {
|
||||||
fn print_device(path: PathBuf, device: RawDevice, verbose: u8) {
|
fn print_device(path: PathBuf, device: RawDevice, verbose: u8) {
|
||||||
println!(
|
println!(
|
||||||
"{}: \"{}\"",
|
"{}: \"{}\"",
|
||||||
path.to_str().unwrap_or_default(),
|
path.to_str().unwrap_or("unknown_device_path"),
|
||||||
device.name().unwrap_or_default()
|
device.name().unwrap_or("unknown_device_name")
|
||||||
);
|
);
|
||||||
|
|
||||||
if verbose > 0 {
|
if verbose > 0 {
|
||||||
let input_id = device.input_id();
|
let input_id = device.input_id();
|
||||||
println!("\tUUID:\t\t'{}'", device.unique_name().unwrap_or_default());
|
println!("\tUUID:\t\t'{}'", device.unique_name().unwrap_or("n/a"));
|
||||||
println!("\tVendor:\t\t'{:x}'", input_id.vendor());
|
println!("\tVendor:\t\t'0x{:x}'", input_id.vendor());
|
||||||
println!("\tProduct:\t'{:x}'", input_id.product());
|
println!("\tProduct:\t'0x{:x}'", input_id.product());
|
||||||
println!("\tVersion:\t'{}'", input_id.version());
|
println!("\tVersion:\t'{}'", input_id.version());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if verbose > 1 {
|
if verbose > 1 {
|
||||||
// let absInfo = device.get_absinfo()?;
|
if let Ok(abs_info) = device.get_absinfo() {
|
||||||
// if absInfo.count() > 0 {
|
if abs_info.count() > 0 {
|
||||||
// println!("\tAxis Data:");
|
println!("\tAxis Data:");
|
||||||
// absInfo.for_each(|info| println!("\t\t{} {}"));
|
abs_info.for_each(|info| println!("\t\t{} {}"));
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if verbose > 0 {
|
||||||
|
println!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue