-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add udev iManufacturer/iProduct/iSerial support to linux #14
Conversation
- Fixes tuna-f1sh#13 - Always prefers reading descriptors directly if possible (then udev, then usb id database) - Requires udev feature
Since this is trickier to CI here are the results of the test [udev_istring_support]: cargo test --features udev,usb_test [~/git/cyme](hyatt@Mas5950x:pts/12)
Finished test [unoptimized + debuginfo] target(s) in 0.03s
Running unittests src/lib.rs (target/debug/deps/cyme-20e45df7ce32b859)
running 19 tests
test colour::tests::test_deserialize_color_theme ... ok
test colour::tests::test_serialize_color_theme ... ok
test colour::tests::test_serialize_deserialize_color_theme ... ok
test config::tests::test_deserialize_config_missing_args ... ok
test config::tests::test_deserialize_config_no_theme ... ok
test icon::tests::icon_from_str ... ok
test config::tests::test_deserialize_example_file ... ok
test icon::tests::test_deserialize_icon_tuples ... ok
test icon::tests::test_deserialize_theme ... ok
test icon::tests::test_serialize_example ... ok
test icon::tests::test_serialize_theme ... ok
test icon::tests::test_serialize_defaults ... ok
test system_profiler::tests::test_deserialize_bus ... ok
test system_profiler::tests::test_deserialize_device ... ok
test usb::tests::test_version_from_f32 ... ok
test usb::tests::test_version_to_string ... ok
test udev::tests::test_udev_attribute ... ok
test udev::tests::test_udev_info ... ok
test system_profiler::tests::test_json_dump_read_not_panic ... ok
test result: ok. 19 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running unittests src/main.rs (target/debug/deps/cyme-8157e6aba049dc5e)
running 4 tests
test tests::test_output_args ... ignored
test tests::test_parse_devpath ... ok
test tests::test_parse_show ... ok
test tests::test_parse_vidpid ... ok
test result: ok. 3 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/integration_test.rs (target/debug/deps/integration_test-ffb205d6e766a1bf)
running 5 tests
test test_tree ... ok
test test_tree_filtering ... ok
test test_list ... ok
test test_run ... ok
test test_list_filtering ... ok
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.16s
Running tests/integration_test_lsusb_display.rs (target/debug/deps/integration_test_lsusb_display-48557684c4bead07)
running 6 tests
test test_lsusb_tree_verbose ... ok
test test_lsusb_list ... ok
test test_lsusb_tree ... ok
test test_lsusb_show ... ok
test test_lsusb_device ... ok
test test_lsusb_vidpid ... ok
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.08s
Doc-tests cyme
running 42 tests
test src/lib.rs - (line 15) ... ignored
test src/lib.rs - (line 26) ... ignored
test src/lib.rs - (line 8) ... ignored
test src/lsusb.rs - lsusb::profiler (line 11) - compile ... ok
test src/system_profiler.rs - system_profiler (line 6) - compile ... ok
test src/system_profiler.rs - system_profiler (line 15) - compile ... ok
test src/udev.rs - udev::get_udev_info (line 11) - compile ... ok
test src/udev.rs - udev::get_udev_attribute (line 52) - compile ... ok
test src/usb.rs - usb::Version (line 20) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::get_root_hub (line 737) ... ok
test src/display.rs - display::Encoding::char_is_valid (line 153) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::is_root_hub (line 963) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::is_trunk_device (line 948) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::port_path (line 895) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::is_hub (line 868) ... ok
test src/types.rs - types::NumericalUnit (line 14) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::get_root_hub (line 731) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::parent_path (line 923) ... ok
test src/usb.rs - usb::ClassCode::to_title_case (line 326) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::port_path (line 889) ... ok
test src/icon.rs - icon::Icon::fmt (line 141) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::parent_path (line 911) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::trunk_path (line 933) ... ok
test src/usb.rs - usb::ClassCode::to_lsusb_string (line 312) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::parent_path (line 917) ... ok
test src/usb.rs - usb::Version::fmt (line 78) ... ok
test src/usb.rs - usb::ConfigAttributes::attributes_to_string (line 153) ... ok
test src/system_profiler.rs - system_profiler::USBDevice::to_lsusb_string (line 1001) ... ok
test src/usb.rs - usb::Speed::to_lsusb_speed (line 453) ... ok
test src/usb.rs - usb::USBEndpoint::max_packet_string (line 573) ... ok
test src/usb.rs - usb::Version (line 26) ... ok
test src/system_profiler.rs - system_profiler::USBFilter (line 1257) ... ok
test src/usb.rs - usb::get_interface_path (line 757) ... ok
test src/display.rs - display::truncate_string (line 1517) ... ok
test src/system_profiler.rs - system_profiler::USBFilter (line 1219) ... ok
test src/system_profiler.rs - system_profiler::USBFilter (line 1201) ... ok
test src/display.rs - display::Encoding::str_is_valid (line 189) ... ok
test src/system_profiler.rs - system_profiler::USBFilter (line 1239) ... ok
test src/usb.rs - usb::get_dev_path (line 774) ... ok
test src/usb.rs - usb::get_parent_path (line 722) ... ok
test src/usb.rs - usb::get_port_path (line 697) ... ok
test src/usb.rs - usb::get_trunk_path (line 739) ... ok
test result: ok. 39 passed; 0 failed; 3 ignored; 0 measured; 0 filtered out; finished in 2.21s |
Thanks for the issue and PR to implement it. I tested and looks good to me. I did however end up going down the rabbit hole comparing
Comparisonslsusb
cyme main
cyme udev_istring_support
|
Sorry, I see you were on the same thread with lsusb references in #13 - still I wonder if we can just read the path directly without the udev crate? |
src/udev.rs
Outdated
return None; | ||
} | ||
}; | ||
let value = device.attribute_value(attribute).unwrap_or_default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return device.attribute_value(attribute).map(|s| s.to_str().unwrap_or("").to_string())
so that it will actually fall through to usb_ids if attribute_value returns None
.
I made some changes in https://github.com/tuna-f1sh/cyme/tree/udev-linux. Using sysfs style name means that the root_hubs are correctly captured:
Still need to see if we can do it without udev and just read the file directly. Open to exploration on macOS on this but I'm fairly confident there is nothing extra to add; this was originally based on the output of system_profiler. Windows might have something. I also fixed the character alignment on Sync Type since it was bugging me after seeing it! That can just be merged with main. |
Yeah, with the sysfs path you don't actually need the udev feature at all to read these fields. |
- Adds support for iConfiguration (only the current active configuration) and iInterface on Linux - get_udev_attribute() is still available but likely shouldn't be used
9c1f382
to
e5a1f90
Compare
Reading from sysfs directly works like a charm. I left the I also ran Output looks great now! cyme -t -vvv
└──○ 27 0x308f 0x0013 Keyboard - Kira PixelMap USB 5337310036384B323430313035353031 - sam4s8
└──• 1 500 mA xXXx
├──◦ 5-4.3:1.0 0x00 HID 0x01 0x01 Boot Keyboard
│ └──→ 1 In Interrupt None Data 1x 8
├──◦ 5-4.3:1.1 0x00 HID 0x00 0x01 NKRO Keyboard
│ └──→ 2 In Interrupt None Data 1x 64
├──◦ 5-4.3:1.2 0x00 HID 0x00 0x00 Media Keys
│ └──→ 3 In Interrupt None Data 1x 8
├──◦ 5-4.3:1.3 0x00 HID 0x00 0x02 Mouse
│ └──→ 4 In Interrupt None Data 1x 8
└──◦ 5-4.3:1.4 0x00 HID 0x00 0x00 HID-IO Interface
├──→ 5 In Interrupt None Data 1x 64
└──← 6 Out Interrupt None Data 1x 64
|
Nice thanks for updating that. The check for |
cargo fmt --all
then usb id database)
I don't really like how the
cfg
's turned out, but it is fairly clear.It would be nice to see if there are equivalents on Windows and macOS (I haven't investigated yet). I may dig around on Windows later to see what I come up with (or if it's even possible).