mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 09:23:19 +01:00
@@ -13,6 +13,7 @@ pub enum ProfileError {
|
||||
/// (pwm/temp, prev, next)
|
||||
ParseFanCurvePrevHigher(&'static str, u8, u8),
|
||||
ParseFanCurvePercentOver100(u8),
|
||||
NotEnoughPoints,
|
||||
// Zbus(zbus::Error),
|
||||
}
|
||||
|
||||
@@ -24,6 +25,7 @@ impl fmt::Display for ProfileError {
|
||||
ProfileError::Read(path, error) => write!(f, "Read {}: {}", path, error),
|
||||
ProfileError::Write(path, error) => write!(f, "Write {}: {}", path, error),
|
||||
ProfileError::NotSupported => write!(f, "Not supported"),
|
||||
ProfileError::NotEnoughPoints => write!(f, "Less than 8 curve points supplied"),
|
||||
ProfileError::NotFound(deets) => write!(f, "Not found: {}", deets),
|
||||
ProfileError::Io(detail) => write!(f, "std::io error: {}", detail),
|
||||
ProfileError::ParseProfileName => write!(f, "Invalid profile name"),
|
||||
|
||||
@@ -75,6 +75,10 @@ impl std::str::FromStr for CurveData {
|
||||
let mut pwm_prev = 0;
|
||||
let mut percentages = false;
|
||||
|
||||
if input.split(',').count() < 8 {
|
||||
return Err(ProfileError::NotEnoughPoints);
|
||||
}
|
||||
|
||||
for (index, value) in input.split(',').enumerate() {
|
||||
for (select, num) in value.splitn(2, |c| c == 'c' || c == ':').enumerate() {
|
||||
if num.contains('%') {
|
||||
@@ -265,7 +269,12 @@ mod tests {
|
||||
assert_eq!(
|
||||
string.as_str(),
|
||||
"CPU: 30c:1%,49c:1%,59c:3%,69c:3%,79c:30%,89c:49%,99c:56%,109c:58%"
|
||||
)
|
||||
);
|
||||
|
||||
let curve =
|
||||
CurveData::from_str("30c:1%,49c:2%,59c:3%,69c:4%,79c:31%,89c:49%,99c:56%");
|
||||
|
||||
assert!(curve.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user