Skip to content

Commit

Permalink
lib & cli: add dump-devices
Browse files Browse the repository at this point in the history
  • Loading branch information
JerwuQu committed Feb 1, 2025
1 parent 9815c12 commit 41c8fa9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ggoled_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -263,5 +273,6 @@ fn main() {
Args::Brightness { value } => {
dev.set_brightness(value).unwrap();
}
Args::DumpDevices => {} // Handled earlier before device connection
}
}
33 changes: 33 additions & 0 deletions ggoled_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down

0 comments on commit 41c8fa9

Please sign in to comment.