Merge pull request #1 from AuroransSolis/main
Filter out non-AMD cards.
This commit is contained in:
commit
b458d1c0e7
@ -1,4 +1,4 @@
|
||||
use crate::{AmdFanError, CONFIG_PATH};
|
||||
use crate::{AmdFanError, CONFIG_PATH, ROOT_DIR};
|
||||
use log::LevelFilter;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::fmt::Formatter;
|
||||
@ -24,10 +24,19 @@ impl FromStr for Card {
|
||||
if value.len() < 5 {
|
||||
return Err(AmdFanError::InputTooShort);
|
||||
}
|
||||
value[4..]
|
||||
let card = value[4..]
|
||||
.parse::<u32>()
|
||||
.map_err(|e| AmdFanError::InvalidSuffix(format!("{:?}", e)))
|
||||
.map(|n| Card(n))
|
||||
.map(|n| Card(n))?;
|
||||
std::fs::read_to_string(format!("{}/{}/device/vendor", ROOT_DIR, card))
|
||||
.map_err(|_| AmdFanError::FailedReadVendor)
|
||||
.and_then(|vendor| {
|
||||
if vendor.trim() == "0x1002" {
|
||||
Ok(card)
|
||||
} else {
|
||||
Err(AmdFanError::NotAmdCard)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,6 +70,13 @@ impl<'de> Deserialize<'de> for Card {
|
||||
"{:?} must have at least 5 characters",
|
||||
value
|
||||
))),
|
||||
Err(AmdFanError::NotAmdCard) => {
|
||||
Err(E::custom(format!("{} is not an AMD GPU", value)))
|
||||
}
|
||||
Err(AmdFanError::FailedReadVendor) => Err(E::custom(format!(
|
||||
"Failed to read vendor file for {}",
|
||||
value
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ pub enum AmdFanError {
|
||||
InvalidPrefix,
|
||||
InputTooShort,
|
||||
InvalidSuffix(String),
|
||||
NotAmdCard,
|
||||
FailedReadVendor,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
Loading…
Reference in New Issue
Block a user