Refactor print connector and connectors

This commit is contained in:
Florian RICHER 2024-10-04 00:23:02 +02:00
parent 0860a4cd7b
commit 17d4e59f76

View file

@ -11,26 +11,32 @@ fn main() {
};
println!("{:?}", gpu);
print_connectors(&gpu);
}
fn print_connectors(gpu: &card::Card) {
let resource_handles = gpu.resource_handles().unwrap();
println!("Connectors:");
for handle in resource_handles.connectors() {
match gpu.get_connector(*handle, false) {
Ok(connector) => {
println!("\t{} ({:?})", connector.interface().as_str(), connector.state());
let encoder_info = format_encoder(&gpu, connector.current_encoder());
println!("\t\tEncoder: {}", encoder_info);
println!(""); // Add blank line
},
Err(_) => {}
}
print_connector(&gpu, handle);
}
}
fn print_connector(gpu: &card::Card, connector_handle: &drm::control::connector::Handle) {
match gpu.get_connector(*connector_handle, false) {
Ok(connector) => {
println!("\t{} ({:?})", connector.interface().as_str(), connector.state());
let encoder_info = format_encoder(&gpu, connector.current_encoder());
println!("\t\tEncoder: {}", encoder_info);
println!(""); // Add blank line
},
Err(_) => {}
};
}
fn format_encoder(gpu: &card::Card, encoder_handle: Option<drm::control::encoder::Handle>) -> String {
match encoder_handle.and_then(|handle| gpu.get_encoder(handle).ok()) {
Some(encoder) => {