rog-platform: additional check against manufacturer attr

Should close #242
This commit is contained in:
Luke D. Jones
2022-08-22 09:01:08 +12:00
parent 45641c928d
commit fa1feaf9d9
4 changed files with 32 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
use std::path::PathBuf;
use log::warn;
use log::{info, warn};
use crate::{
attr_u8,
@@ -36,6 +36,7 @@ impl KeyboardLed {
warn!("{}", err);
PlatformError::Udev("scan_devices failed".into(), err)
})? {
info!("Found keyboard LED controls at {:?}", device.sysname());
return Ok(Self {
path: device.syspath().to_owned(),
});

View File

@@ -1,6 +1,6 @@
use std::path::PathBuf;
use log::warn;
use log::{info, warn};
use serde::{Deserialize, Serialize};
use zvariant::Type;
@@ -41,6 +41,7 @@ impl AsusPlatform {
warn!("{}", err);
PlatformError::Udev("scan_devices failed".into(), err)
})? {
info!("Found platform support at {:?}", device.sysname());
return Ok(Self {
path: device.syspath().to_owned(),
});

View File

@@ -1,6 +1,6 @@
use std::path::PathBuf;
use log::warn;
use log::{info, warn};
use crate::{
attr_u8,
@@ -43,9 +43,25 @@ impl AsusPower {
})? {
if let Some(attr) = device.attribute_value("type") {
match attr.to_os_string().as_os_str().to_str() {
Some("Mains") => mains = device.syspath().to_path_buf(),
Some("Battery") => battery = device.syspath().to_path_buf(),
Some("USB") => usb = Some(device.syspath().to_path_buf()),
Some("Mains") => {
info!("Found mains power at {:?}", device.sysname());
mains = device.syspath().to_path_buf();
}
Some("Battery") => {
// This check required due to an instance where another "not"
// battery can be found
if let Some(m) = device.attribute_value("manufacturer") {
// Should always be ASUSTeK, but match on a lowercase part to be sure
if m.to_string_lossy().to_lowercase().contains("asus") {
info!("Found battery power at {:?}", device.sysname());
battery = device.syspath().to_path_buf();
}
}
}
Some("USB") => {
info!("Found USB-C power at {:?}", device.sysname());
usb = Some(device.syspath().to_path_buf());
}
_ => {}
};
}