diff --git a/ggoled_cli/src/main.rs b/ggoled_cli/src/main.rs index 6eb3c31..da08472 100644 --- a/ggoled_cli/src/main.rs +++ b/ggoled_cli/src/main.rs @@ -149,12 +149,22 @@ enum Args { #[arg(help = "Brighness, 1-10", index = 1)] value: u8, }, + + #[command(about = "Dump devices list to stdout", hide = true)] + DumpDevices, } fn main() { let args = Args::parse(); - let dev = Device::connect().unwrap(); + match args { + Args::DumpDevices => { + Device::dump_devices(); + return; + } + _ => {} // Handled later after device connection + } + let dev = Device::connect().unwrap(); match args { Args::Clear => dev.draw(&Bitmap::new(dev.width, dev.height, false), 0, 0).unwrap(), Args::Fill => dev.draw(&Bitmap::new(dev.width, dev.height, true), 0, 0).unwrap(), @@ -263,5 +273,6 @@ fn main() { Args::Brightness { value } => { dev.set_brightness(value).unwrap(); } + Args::DumpDevices => {} // Handled earlier before device connection } } diff --git a/ggoled_lib/src/lib.rs b/ggoled_lib/src/lib.rs index 9a340af..6345b7e 100644 --- a/ggoled_lib/src/lib.rs +++ b/ggoled_lib/src/lib.rs @@ -116,6 +116,39 @@ impl Device { }) } + /// Dump the full device tree info for all SteelSeries devices to stdout for debug purposes + pub fn dump_devices() { + let api = HidApi::new().unwrap(); + + let device_infos: Vec<_> = api + .device_list() + .filter(|d| d.vendor_id() == 0x1038) // SteelSeries + .collect(); + if device_infos.is_empty() { + println!("No devices."); + return; + } + + println!("-----"); + for info in device_infos { + println!("pid={:#04x}", info.product_id()); + println!("interface={}", info.interface_number()); + println!("path={}", info.path().to_string_lossy()); + println!("usage={}", info.usage()); + if let Ok(dev) = info.open_device(&api) { + let mut buf = [0u8; MAX_REPORT_DESCRIPTOR_SIZE]; + if let Ok(sz) = dev.get_report_descriptor(&mut buf) { + println!("report desc sz={sz}, first 16 bytes: {:02x?}", &buf[0..16]); + } else { + println!("getting report descriptor failed"); + } + } else { + println!("opening device failed"); + } + println!("-----"); + } + } + /// Reconnect to a device. pub fn reconnect(&mut self) -> anyhow::Result<()> { *self = Self::connect()?;