Make nicer fanlevel log entry

This commit is contained in:
Luke
2020-04-23 21:09:16 +12:00
parent 588c71d9ae
commit 42a2675a07
5 changed files with 44 additions and 7 deletions

View File

@@ -358,7 +358,8 @@ impl RogCore {
let mut buf = String::new();
if let Ok(_) = file.read_to_string(&mut buf) {
let mut n = u8::from_str_radix(&buf.trim_end(), 10)?;
info!("Current fan mode: {:?}", &n);
let level: &str = FanLevel::from(n).into();
info!("Current fan mode: {}", level);
if n < 2 {
n += 1;
@@ -366,7 +367,8 @@ impl RogCore {
n = 0;
}
info!("Fan mode stepped to: {:?}", &n);
let level: &str = FanLevel::from(n).into();
info!("Fan mode stepped to: {}", level);
file.write(format!("{:?}\n", n).as_bytes())?;
self.config.fan_mode = n;
self.config.write();
@@ -455,3 +457,40 @@ impl FromStr for LedBrightness {
}
}
}
enum FanLevel {
Normal,
Boost,
Silent,
}
impl From<u8> for FanLevel {
fn from(n: u8) -> Self {
match n {
0 => FanLevel::Normal,
1 => FanLevel::Boost,
2 => FanLevel::Silent,
_ => FanLevel::Normal,
}
}
}
impl From<FanLevel> for u8 {
fn from(n: FanLevel) -> Self {
match n {
FanLevel::Normal => 0,
FanLevel::Boost => 1,
FanLevel::Silent => 2,
}
}
}
impl From<FanLevel> for &str {
fn from(n: FanLevel) -> Self {
match n {
FanLevel::Normal => "Normal",
FanLevel::Boost => "Boosted",
FanLevel::Silent => "Silent",
}
}
}