diff --git a/CHANGELOG.md b/CHANGELOG.md index 6db9804d..22fdc52a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove dbus crate in favour of zbus. This removes the external dbus lib requirement. - Huge internal refactor - BREAKING CHANGE: Anime code refactor. DBUS method names have changed +- Cleanup fan and cpu control + configs # [2.2.2] - 2021-01-31 ### Changed diff --git a/asus-notify/src/main.rs b/asus-notify/src/main.rs index 65a33bc6..6f715eae 100644 --- a/asus-notify/src/main.rs +++ b/asus-notify/src/main.rs @@ -1,4 +1,4 @@ -use daemon::{config::Profile}; +use daemon::config::Profile; use notify_rust::{Hint, Notification, NotificationHandle}; use rog_dbus::{DbusProxies, Signals}; use std::error::Error; diff --git a/asusctl/examples/animatrix.rs b/asusctl/examples/animatrix.rs index 93566e20..1850d31f 100644 --- a/asusctl/examples/animatrix.rs +++ b/asusctl/examples/animatrix.rs @@ -1,7 +1,5 @@ use rog_dbus::AuraDbusClient; -use rog_types::{ - anime_matrix::{AniMeImageBuffer, AniMePacketType, HEIGHT, WIDTH}, -}; +use rog_types::anime_matrix::{AniMeImageBuffer, AniMePacketType, HEIGHT, WIDTH}; use tinybmp::{Bmp, Pixel}; fn main() { diff --git a/asusctl/examples/ball.rs b/asusctl/examples/ball.rs index 8873b565..1436038c 100644 --- a/asusctl/examples/ball.rs +++ b/asusctl/examples/ball.rs @@ -1,7 +1,5 @@ -use rog_types::{ - fancy::{GX502Layout, Key, KeyColourArray, KeyLayout}, -}; use rog_dbus::AuraDbusClient; +use rog_types::fancy::{GX502Layout, Key, KeyColourArray, KeyLayout}; use std::collections::LinkedList; #[derive(Debug, Clone)] diff --git a/asusctl/examples/comet.rs b/asusctl/examples/comet.rs index c121c1e3..590f8744 100644 --- a/asusctl/examples/comet.rs +++ b/asusctl/examples/comet.rs @@ -1,7 +1,5 @@ -use rog_types::{ - fancy::{GX502Layout, KeyColourArray, KeyLayout}, -}; use rog_dbus::AuraDbusClient; +use rog_types::fancy::{GX502Layout, KeyColourArray, KeyLayout}; fn main() -> Result<(), Box> { let (dbus, _) = AuraDbusClient::new()?; diff --git a/asusctl/examples/iterate-keys.rs b/asusctl/examples/iterate-keys.rs index 9f948655..3d52a577 100644 --- a/asusctl/examples/iterate-keys.rs +++ b/asusctl/examples/iterate-keys.rs @@ -1,7 +1,5 @@ -use rog_types::{ - fancy::{GX502Layout, Key, KeyColourArray, KeyLayout}, -}; use rog_dbus::AuraDbusClient; +use rog_types::fancy::{GX502Layout, Key, KeyColourArray, KeyLayout}; fn main() -> Result<(), Box> { let (dbus, _) = AuraDbusClient::new()?; diff --git a/asusctl/examples/per-key-effect-2.rs b/asusctl/examples/per-key-effect-2.rs index 9be11fbf..e35a7e9c 100644 --- a/asusctl/examples/per-key-effect-2.rs +++ b/asusctl/examples/per-key-effect-2.rs @@ -1,7 +1,5 @@ -use rog_types::{ - fancy::{Key, KeyColourArray}, -}; use rog_dbus::AuraDbusClient; +use rog_types::fancy::{Key, KeyColourArray}; fn main() -> Result<(), Box> { let (dbus, _) = AuraDbusClient::new()?; diff --git a/asusctl/examples/pulser.rs b/asusctl/examples/pulser.rs index c355d99a..61c79f29 100644 --- a/asusctl/examples/pulser.rs +++ b/asusctl/examples/pulser.rs @@ -1,7 +1,5 @@ -use rog_types::{ - fancy::{GX502Layout, KeyColourArray, KeyLayout}, -}; use rog_dbus::AuraDbusClient; +use rog_types::fancy::{GX502Layout, KeyColourArray, KeyLayout}; fn main() -> Result<(), Box> { let (dbus, _) = AuraDbusClient::new()?; diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index e647c1e1..803bb9b6 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -1,9 +1,14 @@ use gumdrop::{Opt, Options}; use rog_dbus::AuraDbusClient; +use rog_types::{ + anime_matrix::{AniMeDataBuffer, FULL_PANE_LEN}, + cli_options::{AniMeActions, AniMeStatusValue, LedBrightness, SetAuraBuiltin}, + gfx_vendors::GfxVendors, + profile::{FanLevel, ProfileCommand, ProfileEvent}, +}; use std::{env::args, process::Command}; use yansi_term::Colour::Green; use yansi_term::Colour::Red; -use rog_types::{anime_matrix::{AniMeDataBuffer, FULL_PANE_LEN}, cli_options::{AniMeActions, AniMeStatusValue, LedBrightness, SetAuraBuiltin}, gfx_vendors::GfxVendors, profile::{FanLevel, ProfileCommand, ProfileEvent}}; #[derive(Default, Options)] struct CLIStart { diff --git a/daemon/src/config.rs b/daemon/src/config.rs index 390fccc7..0e455a89 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -1,6 +1,6 @@ -use rog_types::aura_modes::AuraModes; use log::{error, info, warn}; use rog_fan_curve::Curve; +use rog_types::aura_modes::AuraModes; use serde_derive::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::fs::{File, OpenOptions}; @@ -18,7 +18,6 @@ struct ConfigV212 { active_profile: String, toggle_profiles: Vec, power_profiles: BTreeMap, - // TODO: remove power_profile power_profile: u8, kbd_led_brightness: u8, kbd_backlight_mode: u8, @@ -32,7 +31,38 @@ impl ConfigV212 { gfx_nv_mode_is_dedicated: true, active_profile: self.active_profile, toggle_profiles: self.toggle_profiles, - power_profile: self.power_profile, + curr_fan_mode: self.power_profile, + bat_charge_limit: self.bat_charge_limit, + kbd_led_brightness: self.kbd_led_brightness, + kbd_backlight_mode: self.kbd_backlight_mode, + kbd_backlight_modes: self.kbd_backlight_modes, + power_profiles: self.power_profiles, + } + } +} + +/// for parsing old v2.2.2 config +#[derive(Deserialize)] +struct ConfigV222 { + gfx_managed: bool, + bat_charge_limit: u8, + active_profile: String, + toggle_profiles: Vec, + power_profiles: BTreeMap, + power_profile: u8, + kbd_led_brightness: u8, + kbd_backlight_mode: u8, + kbd_backlight_modes: Vec, +} + +impl ConfigV222 { + fn into_current(self) -> Config { + Config { + gfx_managed: self.gfx_managed, + gfx_nv_mode_is_dedicated: true, + active_profile: self.active_profile, + toggle_profiles: self.toggle_profiles, + curr_fan_mode: self.power_profile, bat_charge_limit: self.bat_charge_limit, kbd_led_brightness: self.kbd_led_brightness, kbd_backlight_mode: self.kbd_backlight_mode, @@ -49,7 +79,8 @@ pub struct Config { pub active_profile: String, pub toggle_profiles: Vec, // TODO: remove power_profile - pub power_profile: u8, + #[serde(skip)] + pub curr_fan_mode: u8, pub bat_charge_limit: u8, pub kbd_led_brightness: u8, pub kbd_backlight_mode: u8, @@ -57,7 +88,7 @@ pub struct Config { pub power_profiles: BTreeMap, } -impl Default for Config { +impl Default for Config { fn default() -> Self { let mut pwr = BTreeMap::new(); pwr.insert("normal".into(), Profile::new(0, 100, true, 0, None)); @@ -69,8 +100,8 @@ impl Default for Config { gfx_nv_mode_is_dedicated: true, active_profile: "normal".into(), toggle_profiles: vec!["normal".into(), "boost".into(), "silent".into()], - power_profile: 0, - bat_charge_limit:100, + curr_fan_mode: 0, + bat_charge_limit: 100, kbd_led_brightness: 1, kbd_backlight_mode: 0, kbd_backlight_modes: Vec::new(), @@ -98,6 +129,11 @@ impl Config { } else { if let Ok(data) = serde_json::from_str(&buf) { return data; + } else if let Ok(data) = serde_json::from_str::(&buf) { + let config = data.into_current(); + config.write(); + info!("Updated config version to: {}", VERSION); + return config; } else if let Ok(data) = serde_json::from_str::(&buf) { let config = data.into_current(); config.write(); @@ -207,15 +243,19 @@ impl Default for Profile { } impl Profile { - pub fn new(min_percentage: u8, max_percentage: u8, turbo: bool, - fan_preset: u8, fan_curve: Option) -> Self { + pub fn new( + min_percentage: u8, + max_percentage: u8, + turbo: bool, + fan_preset: u8, + fan_curve: Option, + ) -> Self { Profile { min_percentage, max_percentage, turbo, fan_preset, fan_curve, - } } } diff --git a/daemon/src/ctrl_anime.rs b/daemon/src/ctrl_anime.rs index 7bd4f97b..e4c8e712 100644 --- a/daemon/src/ctrl_anime.rs +++ b/daemon/src/ctrl_anime.rs @@ -132,9 +132,7 @@ impl CtrlAnimeDisplay { })?; info!("Device has an AniMe Matrix display"); - let ctrl = CtrlAnimeDisplay { - handle: device, - }; + let ctrl = CtrlAnimeDisplay { handle: device }; ctrl.do_initialization()?; Ok(ctrl) diff --git a/daemon/src/ctrl_fan_cpu.rs b/daemon/src/ctrl_fan_cpu.rs index 60340bfc..a4842674 100644 --- a/daemon/src/ctrl_fan_cpu.rs +++ b/daemon/src/ctrl_fan_cpu.rs @@ -1,9 +1,10 @@ +use crate::error::RogError; use crate::{ config::{Config, Profile}, GetSupported, }; -use rog_types::profile::{FanLevel, ProfileEvent}; use log::{info, warn}; +use rog_types::profile::{FanLevel, ProfileEvent}; use serde_derive::{Deserialize, Serialize}; use std::convert::TryInto; use std::fs::OpenOptions; @@ -12,7 +13,6 @@ use std::path::Path; use std::sync::Arc; use std::sync::Mutex; use zbus::dbus_interface; -use crate::error::RogError; static FAN_TYPE_1_PATH: &str = "/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy"; static FAN_TYPE_2_PATH: &str = "/sys/devices/platform/asus-nb-wmi/fan_boost_mode"; @@ -62,8 +62,7 @@ impl DbusFanAndCpu { cfg.read(); ctrl.handle_profile_event(&event, &mut cfg) .unwrap_or_else(|err| warn!("{}", err)); - self.notify_profile(&cfg.active_profile) - .unwrap_or(()); + self.notify_profile(&cfg.active_profile).unwrap_or(()); } } } @@ -142,65 +141,17 @@ impl crate::ZbusAdd for DbusFanAndCpu { impl crate::Reloadable for CtrlFanAndCPU { fn reload(&mut self) -> Result<(), RogError> { if let Ok(mut config) = self.config.clone().try_lock() { - let mut file = OpenOptions::new() - .write(true) - .open(self.path) - .map_err(|err| RogError::Path(self.path.into(), err))?; - file.write_all(format!("{}\n", config.power_profile).as_bytes()) - .map_err(|err| RogError::Write(self.path.into(), err))?; let profile = config.active_profile.clone(); self.set(&profile, &mut config)?; - info!( - "Reloaded fan mode: {:?}", - FanLevel::from(config.power_profile) - ); + // info!( + // "Reloaded fan mode: {:?}", + // FanLevel::from(config.power_profile) + // ); } Ok(()) } } -impl crate::CtrlTask for CtrlFanAndCPU { - fn do_task(&mut self) -> Result<(), RogError> { - let mut file = OpenOptions::new() - .read(true) - .open(self.path) - .map_err(|err| RogError::Path(self.path.into(), err))?; - let mut buf = [0u8; 1]; - file.read_exact(&mut buf) - .map_err(|err| RogError::Read(self.path.into(), err))?; - if let Some(num) = char::from(buf[0]).to_digit(10) { - if let Ok(mut config) = self.config.clone().try_lock() { - if config.power_profile != num as u8 { - config.read(); - - let mut i = config - .toggle_profiles - .iter() - .position(|x| x == &config.active_profile) - .map(|i| i + 1) - .unwrap_or(0); - if i >= config.toggle_profiles.len() { - i = 0; - } - - let new_profile = config - .toggle_profiles - .get(i) - .unwrap_or(&config.active_profile) - .clone(); - - self.set(&new_profile, &mut config)?; - - info!("Profile was changed: {}", &new_profile); - } - } - return Ok(()); - } - - Err(RogError::DoTask("Fan-level could not be parsed".into())) - } -} - impl CtrlFanAndCPU { pub fn new(config: Arc>) -> Result { let path = CtrlFanAndCPU::get_fan_path()?; @@ -246,7 +197,7 @@ impl CtrlFanAndCPU { Ok(()) } - pub(super) fn set_fan_mode(&mut self, preset: u8, config: &mut Config) -> Result<(), RogError> { + fn set_fan_mode(&mut self, preset: u8, config: &mut Config) -> Result<(), RogError> { let mode = config.active_profile.clone(); let mut fan_ctrl = OpenOptions::new() .write(true) @@ -257,15 +208,13 @@ impl CtrlFanAndCPU { .power_profiles .get_mut(&mode) .ok_or_else(|| RogError::MissingProfile(mode.clone()))?; - config.power_profile = preset; + config.curr_fan_mode = preset; mode_config.fan_preset = preset; config.write(); fan_ctrl .write_all(format!("{}\n", preset).as_bytes()) .map_err(|err| RogError::Write(self.path.into(), err))?; info!("Fan mode set to: {:?}", FanLevel::from(preset)); - self.set_pstate_for_fan_mode(&mode, config)?; - self.set_fan_curve_for_fan_mode(&mode, config)?; Ok(()) } @@ -278,6 +227,9 @@ impl CtrlFanAndCPU { ProfileEvent::Toggle => self.do_next_profile(config)?, ProfileEvent::ChangeMode(mode) => { self.set_fan_mode(*mode, config)?; + let mode = config.active_profile.clone(); + self.set_pstate_for_fan_mode(&mode, config)?; + self.set_fan_curve_for_fan_mode(&mode, config)?; } ProfileEvent::Cli(command) => { let profile_key = match command.profile.as_ref() { @@ -328,10 +280,10 @@ impl CtrlFanAndCPU { .write(true) .open(self.path) .map_err(|err| RogError::Path(self.path.into(), err))?; + config.curr_fan_mode = mode_config.fan_preset; fan_ctrl .write_all(format!("{}\n", mode_config.fan_preset).as_bytes()) .map_err(|err| RogError::Write(self.path.into(), err))?; - config.power_profile = mode_config.fan_preset; self.set_pstate_for_fan_mode(profile, config)?; self.set_fan_curve_for_fan_mode(profile, config)?; diff --git a/daemon/src/ctrl_gfx/gfx.rs b/daemon/src/ctrl_gfx/gfx.rs index 7e80e519..4c01ef27 100644 --- a/daemon/src/ctrl_gfx/gfx.rs +++ b/daemon/src/ctrl_gfx/gfx.rs @@ -2,6 +2,7 @@ use ctrl_gfx::error::GfxError; use ctrl_gfx::*; use ctrl_rog_bios::CtrlRogBios; use log::{error, info, warn}; +use rog_types::gfx_vendors::{GfxCtrlAction, GfxVendors}; use std::io::Write; use std::iter::FromIterator; use std::path::Path; @@ -10,7 +11,6 @@ use std::str::FromStr; use std::{sync::Arc, sync::Mutex}; use sysfs_class::{PciDevice, SysClass}; use system::{GraphicsDevice, Module, PciBus}; -use rog_types::gfx_vendors::{GfxCtrlAction, GfxVendors}; use zbus::dbus_interface; use crate::*; diff --git a/daemon/src/ctrl_leds.rs b/daemon/src/ctrl_leds.rs index db14b07d..3ba4e20b 100644 --- a/daemon/src/ctrl_leds.rs +++ b/daemon/src/ctrl_leds.rs @@ -9,13 +9,13 @@ use crate::{ error::RogError, laptops::{match_laptop, HELP_ADDRESS}, }; +use log::{error, info, warn}; use rog_types::{ aura_brightness_bytes, aura_modes::{AuraModes, PER_KEY}, fancy::KeyColourArray, LED_MSG_LEN, }; -use log::{error, info, warn}; use std::fs::OpenOptions; use std::io::{Read, Write}; use std::sync::Arc; @@ -44,10 +44,7 @@ impl GetSupported for CtrlKbdBacklight { let modes = laptop.supported_modes().to_vec(); if modes.contains(&PER_KEY) { per_key_led_mode = true; - let modes = modes - .iter() - .filter(|x| **x != PER_KEY).copied() - .collect(); + let modes = modes.iter().filter(|x| **x != PER_KEY).copied().collect(); stock_led_modes = Some(modes); } else { stock_led_modes = Some(modes); diff --git a/daemon/src/ctrl_rog_bios.rs b/daemon/src/ctrl_rog_bios.rs index 5fab528e..f498f0a5 100644 --- a/daemon/src/ctrl_rog_bios.rs +++ b/daemon/src/ctrl_rog_bios.rs @@ -1,9 +1,4 @@ -use crate::{ - config::Config, - ctrl_gfx::{gfx::CtrlGraphics}, - error::RogError, - GetSupported, -}; +use crate::{config::Config, ctrl_gfx::gfx::CtrlGraphics, error::RogError, GetSupported}; //use crate::dbus::DbusEvents; use log::{info, warn}; use rog_types::gfx_vendors::GfxVendors; diff --git a/daemon/src/ctrl_supported.rs b/daemon/src/ctrl_supported.rs new file mode 100644 index 00000000..9f2b6601 --- /dev/null +++ b/daemon/src/ctrl_supported.rs @@ -0,0 +1,56 @@ +use std::convert::TryInto; + +use log::warn; +use serde_derive::{Deserialize, Serialize}; +use zbus::dbus_interface; + +use crate::{ + ctrl_anime::{AnimeSupportedFunctions, CtrlAnimeDisplay}, + ctrl_charge::{ChargeSupportedFunctions, CtrlCharge}, + ctrl_fan_cpu::{CtrlFanAndCPU, FanCpuSupportedFunctions}, + ctrl_leds::{CtrlKbdBacklight, LedSupportedFunctions}, + ctrl_rog_bios::{CtrlRogBios, RogBiosSupportedFunctions}, + GetSupported, +}; + +#[derive(Serialize, Deserialize)] +pub struct SupportedFunctions { + anime_ctrl: AnimeSupportedFunctions, + charge_ctrl: ChargeSupportedFunctions, + fan_cpu_ctrl: FanCpuSupportedFunctions, + keyboard_led: LedSupportedFunctions, + rog_bios_ctrl: RogBiosSupportedFunctions, +} + +#[dbus_interface(name = "org.asuslinux.Daemon")] +impl SupportedFunctions { + fn supported_functions(&self) -> String { + serde_json::to_string_pretty(self).unwrap() + } +} + +impl crate::ZbusAdd for SupportedFunctions { + fn add_to_server(self, server: &mut zbus::ObjectServer) { + server + .at(&"/org/asuslinux/Supported".try_into().unwrap(), self) + .map_err(|err| { + warn!("SupportedFunctions: add_to_server {}", err); + err + }) + .ok(); + } +} + +impl GetSupported for SupportedFunctions { + type A = SupportedFunctions; + + fn get_supported() -> Self::A { + SupportedFunctions { + keyboard_led: CtrlKbdBacklight::get_supported(), + anime_ctrl: CtrlAnimeDisplay::get_supported(), + charge_ctrl: CtrlCharge::get_supported(), + fan_cpu_ctrl: CtrlFanAndCPU::get_supported(), + rog_bios_ctrl: CtrlRogBios::get_supported(), + } + } +} diff --git a/daemon/src/daemon.rs b/daemon/src/daemon.rs index 9806a6e5..3cc823c6 100644 --- a/daemon/src/daemon.rs +++ b/daemon/src/daemon.rs @@ -3,17 +3,14 @@ use daemon::ctrl_fan_cpu::{CtrlFanAndCPU, DbusFanAndCpu}; use daemon::ctrl_leds::{CtrlKbdBacklight, DbusKbdBacklight}; use daemon::laptops::match_laptop; use daemon::{ - config::Config, laptops::print_board_info, ctrl_supported::SupportedFunctions, GetSupported, -}; -use daemon::{ - ctrl_anime::CtrlAnimeDisplay, - ctrl_gfx::{gfx::CtrlGraphics}, + config::Config, ctrl_supported::SupportedFunctions, laptops::print_board_info, GetSupported, }; +use daemon::{ctrl_anime::CtrlAnimeDisplay, ctrl_gfx::gfx::CtrlGraphics}; -use rog_dbus::DBUS_NAME; use daemon::{CtrlTask, Reloadable, ZbusAdd}; use log::LevelFilter; use log::{error, info, warn}; +use rog_dbus::DBUS_NAME; use rog_types::gfx_vendors::GfxVendors; use std::error::Error; use std::io::Write; @@ -34,7 +31,7 @@ pub fn main() -> Result<(), Box> { .filter(None, LevelFilter::Info) .init(); - info!( "daemon version {}", daemon::VERSION); + info!("daemon version {}", daemon::VERSION); info!(" rog-dbus version {}", rog_dbus::VERSION); info!("rog-types version {}", rog_types::VERSION); @@ -142,8 +139,7 @@ fn start_daemon() -> Result<(), Box> { ctrl.reload() .unwrap_or_else(|err| warn!("Profile control: {}", err)); let tmp = Arc::new(Mutex::new(ctrl)); - DbusFanAndCpu::new(tmp.clone()).add_to_server(&mut object_server); - tasks.push(tmp); + DbusFanAndCpu::new(tmp).add_to_server(&mut object_server); }; if let Some(laptop) = laptop { diff --git a/daemon/src/error.rs b/daemon/src/error.rs index be80c59d..670ca2e9 100644 --- a/daemon/src/error.rs +++ b/daemon/src/error.rs @@ -69,7 +69,7 @@ impl From for RogError { impl From for RogError { fn from(err: GraphicsError) -> Self { match err { - GraphicsError::ParseVendor => RogError::GfxSwitching(GfxError::ParseVendor) + GraphicsError::ParseVendor => RogError::GfxSwitching(GfxError::ParseVendor), } } -} \ No newline at end of file +} diff --git a/daemon/src/laptops.rs b/daemon/src/laptops.rs index 461e0edd..e25ca33f 100644 --- a/daemon/src/laptops.rs +++ b/daemon/src/laptops.rs @@ -1,5 +1,5 @@ -use rog_types::aura_modes::{AuraModes, BREATHING, STATIC}; use log::{info, warn}; +use rog_types::aura_modes::{AuraModes, BREATHING, STATIC}; use serde_derive::{Deserialize, Serialize}; use std::fs::OpenOptions; use std::io::Read; diff --git a/rog-dbus/src/lib.rs b/rog-dbus/src/lib.rs index 28456c58..13f2fe66 100644 --- a/rog-dbus/src/lib.rs +++ b/rog-dbus/src/lib.rs @@ -11,8 +11,8 @@ pub mod zbus_profile; pub mod zbus_rogbios; pub mod zbus_supported; -use std::sync::{Arc, Mutex}; use rog_types::aura_modes::AuraModes; +use std::sync::{Arc, Mutex}; use zbus::{Connection, Result, SignalReceiver}; pub static VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/rog-dbus/src/zbus_anime.rs b/rog-dbus/src/zbus_anime.rs index 6cb42b72..209e6432 100644 --- a/rog-dbus/src/zbus_anime.rs +++ b/rog-dbus/src/zbus_anime.rs @@ -40,7 +40,6 @@ trait Daemon { fn write_image(&self, input: &[Vec]) -> zbus::Result<()>; } - pub struct AnimeProxy<'a>(DaemonProxy<'a>); impl<'a> AnimeProxy<'a> { diff --git a/rog-types/src/anime_matrix.rs b/rog-types/src/anime_matrix.rs index 05f1e039..fa5c6ad2 100644 --- a/rog-types/src/anime_matrix.rs +++ b/rog-types/src/anime_matrix.rs @@ -18,11 +18,11 @@ pub const ANIME_PANE2_PREFIX: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x0 pub struct AniMeDataBuffer(Vec); 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]) diff --git a/rog-types/src/cli_options.rs b/rog-types/src/cli_options.rs index 864ef574..7323b37a 100644 --- a/rog-types/src/cli_options.rs +++ b/rog-types/src/cli_options.rs @@ -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) } } diff --git a/rog-types/src/gfx_vendors.rs b/rog-types/src/gfx_vendors.rs new file mode 100644 index 00000000..05a43732 --- /dev/null +++ b/rog-types/src/gfx_vendors.rs @@ -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 { + 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 { + 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 for String { + fn from(mode: GfxCtrlAction) -> Self { + (&mode).into() + } +}