Cleanup fan+cpu+config

This commit is contained in:
Luke
2021-02-07 00:21:04 +13:00
parent 629bdc2213
commit 50756046cf
24 changed files with 238 additions and 127 deletions

View File

@@ -18,11 +18,11 @@ pub const ANIME_PANE2_PREFIX: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x0
pub struct AniMeDataBuffer(Vec<u8>);
impl Default for AniMeDataBuffer {
fn default() -> Self {
Self::new()
}
fn default() -> Self {
Self::new()
}
}
impl AniMeDataBuffer {
pub fn new() -> Self {
AniMeDataBuffer(vec![0u8; FULL_PANE_LEN])

View File

@@ -33,9 +33,7 @@ impl FromStr for LedBrightness {
"med" => Ok(LedBrightness { level: Some(0x02) }),
"high" => Ok(LedBrightness { level: Some(0x03) }),
_ => {
print!(
"Invalid argument, must be one of: off, low, med, high"
);
print!("Invalid argument, must be one of: off, low, med, high");
Err(AuraError::ParseBrightness)
}
}

View File

@@ -0,0 +1,86 @@
#[derive(Debug, PartialEq, Clone)]
pub enum GfxVendors {
Nvidia,
Integrated,
Compute,
Hybrid,
}
use std::str::FromStr;
use crate::error::GraphicsError;
impl FromStr for GfxVendors {
type Err = GraphicsError;
fn from_str(s: &str) -> Result<Self, GraphicsError> {
match s.to_lowercase().as_str() {
"nvidia" => Ok(GfxVendors::Nvidia),
"hybrid" => Ok(GfxVendors::Hybrid),
"compute" => Ok(GfxVendors::Compute),
"integrated" => Ok(GfxVendors::Integrated),
"nvidia\n" => Ok(GfxVendors::Nvidia),
"hybrid\n" => Ok(GfxVendors::Hybrid),
"compute\n" => Ok(GfxVendors::Compute),
"integrated\n" => Ok(GfxVendors::Integrated),
_ => Err(GraphicsError::ParseVendor),
}
}
}
impl From<&GfxVendors> for &str {
fn from(mode: &GfxVendors) -> Self {
match mode {
GfxVendors::Nvidia => "nvidia",
GfxVendors::Hybrid => "hybrid",
GfxVendors::Compute => "compute",
GfxVendors::Integrated => "integrated",
}
}
}
#[derive(Debug)]
pub enum GfxCtrlAction {
Reboot,
RestartX,
None,
}
impl FromStr for GfxCtrlAction {
type Err = GraphicsError;
fn from_str(s: &str) -> Result<Self, GraphicsError> {
match s.to_lowercase().as_str() {
"reboot" => Ok(GfxCtrlAction::Reboot),
"restartx" => Ok(GfxCtrlAction::RestartX),
"none" => Ok(GfxCtrlAction::None),
_ => Err(GraphicsError::ParseVendor),
}
}
}
impl From<&GfxCtrlAction> for &str {
fn from(mode: &GfxCtrlAction) -> Self {
match mode {
GfxCtrlAction::Reboot => "reboot",
GfxCtrlAction::RestartX => "restartx",
GfxCtrlAction::None => "none",
}
}
}
impl From<&GfxCtrlAction> for String {
fn from(mode: &GfxCtrlAction) -> Self {
match mode {
GfxCtrlAction::Reboot => "reboot".into(),
GfxCtrlAction::RestartX => "restartx".into(),
GfxCtrlAction::None => "none".into(),
}
}
}
impl From<GfxCtrlAction> for String {
fn from(mode: GfxCtrlAction) -> Self {
(&mode).into()
}
}