From 515888393cefb0e509064a0ad14cde8737e6fb3e Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 24 Apr 2020 07:31:24 +1200 Subject: [PATCH] Make laptop matching more generic using product_id instead of board_name --- src/laptops/gl753.rs | 2 +- src/laptops/mod.rs | 50 ++++++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/laptops/gl753.rs b/src/laptops/gl753.rs index aa92c34b..44c031e6 100644 --- a/src/laptops/gl753.rs +++ b/src/laptops/gl753.rs @@ -28,7 +28,7 @@ impl LaptopGL753 { // from `cat /sys/class/dmi/id/board_name` board_name: "LaptopGL753VE", // from `cat /sys/class/dmi/id/product_family` - prod_family: "ROG Strix", + prod_family: "", report_filter_bytes: [0x5a, 0x02], min_led_bright: 0x00, max_led_bright: 0x03, diff --git a/src/laptops/mod.rs b/src/laptops/mod.rs index 98e07d86..7e653697 100644 --- a/src/laptops/mod.rs +++ b/src/laptops/mod.rs @@ -13,24 +13,42 @@ mod gx502; use gx502::LaptopGX502; pub(crate) fn match_laptop() -> Box { - let dmi = sysfs_class::DmiId::default(); - let board_name = dmi.board_name().unwrap(); - match &board_name.as_str()[..5] { - // TODO: FX503VD - 0x1869, - // These two models seem to have the same characteristics - "GX502" | "GA502" => { - info!("Found GX502 or GA502 series"); - Box::new(LaptopGX502::new()) - } - // LED should work for this, but unsure of keys - "GL753" => { - info!("Found GL753 series"); - Box::new(LaptopGL753::new()) - } - _ => { - panic!("could not match laptop"); + for device in rusb::devices().unwrap().iter() { + let device_desc = device.device_descriptor().unwrap(); + if device_desc.vendor_id() == 0x0b05 { + match device_desc.product_id() { + 0x1866 => { + info!("Found GX502 or similar"); + return Box::new(LaptopGX502::new()); + } + 0x1854 => { + info!("Found GL753 or similar"); + return Box::new(LaptopGL753::new()); + } + _ => {} + } } } + panic!("could not match laptop"); + + // let dmi = sysfs_class::DmiId::default(); + // let board_name = dmi.board_name().unwrap(); + // match &board_name.as_str()[..5] { + // // TODO: FX503VD - 0x1869, + // // These two models seem to have the same characteristics + // "GX502" | "GA502" | "GU502" => { + // info!("Found GX502 or GA502 series"); + // Box::new(LaptopGX502::new()) + // } + // // LED should work for this, but unsure of keys + // "GL753" => { + // info!("Found GL753 series"); + // Box::new(LaptopGL753::new()) + // } + // _ => { + // panic!("could not match laptop"); + // } + // } } /// All laptop models should implement this trait. The role of a `Laptop` is to