From 629bdc221384c27ac57108b8fcda7c5b59803936 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 6 Feb 2021 23:18:01 +1300 Subject: [PATCH] Large code cleanup --- CHANGELOG.md | 4 +- Cargo.lock | 11 ++--- asus-notify/Cargo.toml | 2 +- asusctl/Cargo.toml | 3 +- asusctl/src/main.rs | 4 +- daemon/Cargo.toml | 2 +- daemon/src/config.rs | 63 +++++++++++++++---------- daemon/src/ctrl_anime.rs | 25 ++++------ daemon/src/ctrl_charge.rs | 2 +- daemon/src/ctrl_fan_cpu.rs | 49 ++----------------- daemon/src/ctrl_gfx/gfx.rs | 11 ++--- daemon/src/ctrl_gfx/mod.rs | 2 - daemon/src/ctrl_gfx/vendors.rs | 86 ---------------------------------- daemon/src/ctrl_leds.rs | 9 ++-- daemon/src/ctrl_rog_bios.rs | 3 +- daemon/src/daemon.rs | 5 +- daemon/src/error.rs | 9 ++++ daemon/src/lib.rs | 20 ++++++-- daemon/src/supported.rs | 56 ---------------------- rog-dbus/Cargo.toml | 2 +- rog-types/Cargo.toml | 2 +- rog-types/src/anime_matrix.rs | 6 +++ rog-types/src/aura_modes.rs | 28 +++++------ rog-types/src/cli_options.rs | 5 +- rog-types/src/lib.rs | 2 + 25 files changed, 124 insertions(+), 287 deletions(-) delete mode 100644 daemon/src/ctrl_gfx/vendors.rs delete mode 100644 daemon/src/supported.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cc78c2f..6db9804d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Write set+apply after each array in multizone - Remove misc bad logic -- Use same code path as 0x1866 device to configure led support +- Use same code path as 0x1866 device to configure led support for 0x1854 device - Remove duplicate code - Set correct speeds for multizone - 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 # [2.2.2] - 2021-01-31 ### Changed diff --git a/Cargo.lock b/Cargo.lock index bb6f5f4c..2f470716 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "asus-notify" -version = "2.0.4" +version = "3.0.0" dependencies = [ "daemon", "notify-rust", @@ -33,9 +33,8 @@ dependencies = [ [[package]] name = "asusctl" -version = "2.0.4" +version = "3.0.0" dependencies = [ - "daemon", "gumdrop", "rog_dbus", "rog_types", @@ -187,7 +186,7 @@ dependencies = [ [[package]] name = "daemon" -version = "2.2.2" +version = "3.0.0" dependencies = [ "env_logger", "intel-pstate", @@ -786,7 +785,7 @@ checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" [[package]] name = "rog_dbus" -version = "2.2.1" +version = "3.0.0" dependencies = [ "rog_fan_curve", "rog_types", @@ -807,7 +806,7 @@ dependencies = [ [[package]] name = "rog_types" -version = "2.2.1" +version = "3.0.0" dependencies = [ "gumdrop", "rog_fan_curve", diff --git a/asus-notify/Cargo.toml b/asus-notify/Cargo.toml index 17ffd508..8081b9fd 100644 --- a/asus-notify/Cargo.toml +++ b/asus-notify/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "asus-notify" -version = "2.0.4" +version = "3.0.0" authors = ["Luke D Jones "] edition = "2018" diff --git a/asusctl/Cargo.toml b/asusctl/Cargo.toml index 7dff35b6..ecd032f2 100644 --- a/asusctl/Cargo.toml +++ b/asusctl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "asusctl" -version = "2.0.4" +version = "3.0.0" authors = ["Luke D Jones "] edition = "2018" @@ -11,7 +11,6 @@ edition = "2018" serde_json = "^1.0" rog_dbus = { path = "../rog-dbus" } rog_types = { path = "../rog-types" } -daemon = { path = "../daemon" } gumdrop = "^0.8" yansi-term = "^0.1" diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 2b2a57ea..e647c1e1 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -1,10 +1,9 @@ -use daemon::{ctrl_fan_cpu::FanLevel, ctrl_gfx::vendors::GfxVendors}; use gumdrop::{Opt, Options}; use rog_dbus::AuraDbusClient; 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}, profile::{ProfileCommand, ProfileEvent}}; +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 { @@ -129,7 +128,6 @@ fn main() -> Result<(), Box> { if parsed.version { println!(" asusctl version {}", env!("CARGO_PKG_VERSION")); - println!(" daemon version {}", daemon::VERSION); println!(" rog-dbus version {}", rog_dbus::VERSION); println!("rog-types version {}", rog_types::VERSION); } diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index c4b8cfd8..633845db 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "daemon" -version = "2.2.2" +version = "3.0.0" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/daemon/src/config.rs b/daemon/src/config.rs index e3bf0e89..390fccc7 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -42,7 +42,7 @@ impl ConfigV212 { } } -#[derive(Default, Deserialize, Serialize)] +#[derive(Deserialize, Serialize)] pub struct Config { pub gfx_managed: bool, pub gfx_nv_mode_is_dedicated: bool, @@ -57,6 +57,28 @@ pub struct Config { pub power_profiles: BTreeMap, } +impl Default for Config { + fn default() -> Self { + let mut pwr = BTreeMap::new(); + pwr.insert("normal".into(), Profile::new(0, 100, true, 0, None)); + pwr.insert("boost".into(), Profile::new(0, 100, true, 1, None)); + pwr.insert("silent".into(), Profile::new(0, 100, true, 2, None)); + + Config { + gfx_managed: true, + 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, + kbd_led_brightness: 1, + kbd_backlight_mode: 0, + kbd_backlight_modes: Vec::new(), + power_profiles: pwr, + } + } +} + impl Config { /// `load` will attempt to read the config, and panic if the dir is missing pub fn load(supported_led_modes: &[u8]) -> Self { @@ -92,36 +114,11 @@ impl Config { fn create_default(file: &mut File, supported_led_modes: &[u8]) -> Self { // create a default config here let mut config = Config::default(); - config.gfx_managed = true; - config.gfx_nv_mode_is_dedicated = true; - - config.bat_charge_limit = 100; - config.kbd_backlight_mode = 0; - config.kbd_led_brightness = 1; for n in supported_led_modes { config.kbd_backlight_modes.push(AuraModes::from(*n)) } - let mut profile = Profile::default(); - profile.fan_preset = 0; - profile.turbo = true; - config.power_profiles.insert("normal".into(), profile); - - let mut profile = Profile::default(); - profile.fan_preset = 1; - profile.turbo = true; - config.power_profiles.insert("boost".into(), profile); - - let mut profile = Profile::default(); - profile.fan_preset = 2; - config.power_profiles.insert("silent".into(), profile); - - config.toggle_profiles.push("normal".into()); - config.toggle_profiles.push("boost".into()); - config.toggle_profiles.push("silent".into()); - config.active_profile = "normal".into(); - // Should be okay to unwrap this as is since it is a Default let json = serde_json::to_string_pretty(&config).unwrap(); file.write_all(json.as_bytes()) @@ -208,3 +205,17 @@ impl Default for Profile { } } } + +impl Profile { + 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 1c3f8945..7bd4f97b 100644 --- a/daemon/src/ctrl_anime.rs +++ b/daemon/src/ctrl_anime.rs @@ -89,19 +89,13 @@ impl Dbus for CtrlAnimeDisplay { buffer[1] = WRITE; buffer[2] = ON_OFF; - let status_str; if status { buffer[3] = 0x03; - status_str = "on"; } else { buffer[3] = 0x00; - status_str = "off"; } - self.write_bytes(&buffer).map_or_else( - |err| warn!("{}", err), - |()| info!("Turning {} the AniMe", status_str), - ); + self.write_bytes(&buffer); } fn set_boot_on_off(&self, status: bool) { @@ -159,7 +153,7 @@ impl CtrlAnimeDisplay { /// Should only be used if the bytes you are writing are verified correct #[inline] - fn write_bytes(&self, message: &[u8]) -> Result<(), AuraError> { + fn write_bytes(&self, message: &[u8]) { match self.handle.write_control( 0x21, // request_type 0x09, // request @@ -174,7 +168,6 @@ impl CtrlAnimeDisplay { _ => error!("Failed to write to led interrupt: {}", err), }, } - Ok(()) } #[inline] fn write_data_buffer(&self, buffer: AniMeDataBuffer) -> Result<(), AuraError> { @@ -183,7 +176,7 @@ impl CtrlAnimeDisplay { image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX); for row in image.iter() { - self.write_bytes(row)?; + self.write_bytes(row); } self.do_flush()?; Ok(()) @@ -211,7 +204,7 @@ impl CtrlAnimeDisplay { image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX); for row in image.iter() { - self.write_bytes(row)?; + self.write_bytes(row); } self.do_flush()?; Ok(()) @@ -224,7 +217,7 @@ impl CtrlAnimeDisplay { for (idx, byte) in INIT_STR.as_bytes().iter().enumerate() { init[idx + 1] = *byte } - self.write_bytes(&init)?; + self.write_bytes(&init); // clear the init array and write other init message for ch in init.iter_mut() { @@ -233,7 +226,7 @@ impl CtrlAnimeDisplay { init[0] = DEV_PAGE; // write it to be sure? init[1] = INIT; - self.write_bytes(&init)?; + self.write_bytes(&init); Ok(()) } @@ -244,7 +237,7 @@ impl CtrlAnimeDisplay { flush[1] = WRITE; flush[2] = 0x03; - self.write_bytes(&flush)?; + self.write_bytes(&flush); Ok(()) } @@ -256,7 +249,7 @@ impl CtrlAnimeDisplay { flush[2] = 0x01; flush[3] = if status { 0x00 } else { 0x80 }; - self.write_bytes(&flush)?; + self.write_bytes(&flush); Ok(()) } @@ -268,7 +261,7 @@ impl CtrlAnimeDisplay { flush[2] = 0x01; flush[3] = 0x80; - self.write_bytes(&flush)?; + self.write_bytes(&flush); Ok(()) } } diff --git a/daemon/src/ctrl_charge.rs b/daemon/src/ctrl_charge.rs index 5666e613..65bb5a11 100644 --- a/daemon/src/ctrl_charge.rs +++ b/daemon/src/ctrl_charge.rs @@ -101,7 +101,7 @@ impl CtrlCharge { } pub(super) fn set(&self, limit: u8, config: &mut Config) -> Result<(), RogError> { - if limit < 20 || limit > 100 { + if !(20..=100).contains(&limit) { warn!( "Unable to set battery charge limit, must be between 20-100: requested {}", limit diff --git a/daemon/src/ctrl_fan_cpu.rs b/daemon/src/ctrl_fan_cpu.rs index a708f50b..60340bfc 100644 --- a/daemon/src/ctrl_fan_cpu.rs +++ b/daemon/src/ctrl_fan_cpu.rs @@ -2,17 +2,17 @@ use crate::{ config::{Config, Profile}, GetSupported, }; -use rog_types::profile::ProfileEvent; +use rog_types::profile::{FanLevel, ProfileEvent}; use log::{info, warn}; use serde_derive::{Deserialize, Serialize}; use std::convert::TryInto; use std::fs::OpenOptions; use std::io::{Read, Write}; use std::path::Path; -use std::str::FromStr; 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"; @@ -63,7 +63,7 @@ impl DbusFanAndCpu { ctrl.handle_profile_event(&event, &mut cfg) .unwrap_or_else(|err| warn!("{}", err)); self.notify_profile(&cfg.active_profile) - .unwrap_or_else(|_| ()); + .unwrap_or(()); } } } @@ -393,46 +393,3 @@ impl CtrlFanAndCPU { Ok(()) } } - -use crate::error::RogError; - -#[derive(Debug)] -pub enum FanLevel { - Normal, - Boost, - Silent, -} - -impl FromStr for FanLevel { - type Err = RogError; - - fn from_str(s: &str) -> Result { - match s.to_lowercase().as_str() { - "normal" => Ok(FanLevel::Normal), - "boost" => Ok(FanLevel::Boost), - "silent" => Ok(FanLevel::Silent), - _ => Err(RogError::ParseFanLevel), - } - } -} - -impl From for FanLevel { - fn from(n: u8) -> Self { - match n { - 0 => FanLevel::Normal, - 1 => FanLevel::Boost, - 2 => FanLevel::Silent, - _ => FanLevel::Normal, - } - } -} - -impl From for u8 { - fn from(n: FanLevel) -> Self { - match n { - FanLevel::Normal => 0, - FanLevel::Boost => 1, - FanLevel::Silent => 2, - } - } -} diff --git a/daemon/src/ctrl_gfx/gfx.rs b/daemon/src/ctrl_gfx/gfx.rs index 8bdc1818..7e80e519 100644 --- a/daemon/src/ctrl_gfx/gfx.rs +++ b/daemon/src/ctrl_gfx/gfx.rs @@ -10,7 +10,7 @@ use std::str::FromStr; use std::{sync::Arc, sync::Mutex}; use sysfs_class::{PciDevice, SysClass}; use system::{GraphicsDevice, Module, PciBus}; -use vendors::{GfxCtrlAction, GfxVendors}; +use rog_types::gfx_vendors::{GfxCtrlAction, GfxVendors}; use zbus::dbus_interface; use crate::*; @@ -190,14 +190,9 @@ impl CtrlGraphics { }; let modules = Module::all().map_err(|err| GfxError::Read("get_vendor".into(), err))?; - let driver_loaded = if modules + let driver_loaded = modules .iter() - .any(|module| module.name == "nouveau" || module.name == "nvidia") - { - true - } else { - false - }; + .any(|module| module.name == "nouveau" || module.name == "nvidia"); let vendor = if mode == "off" { if driver_loaded { diff --git a/daemon/src/ctrl_gfx/mod.rs b/daemon/src/ctrl_gfx/mod.rs index b68e2c41..00b64538 100644 --- a/daemon/src/ctrl_gfx/mod.rs +++ b/daemon/src/ctrl_gfx/mod.rs @@ -1,5 +1,3 @@ -pub mod vendors; - pub mod error; pub mod gfx; diff --git a/daemon/src/ctrl_gfx/vendors.rs b/daemon/src/ctrl_gfx/vendors.rs deleted file mode 100644 index c0e90a2d..00000000 --- a/daemon/src/ctrl_gfx/vendors.rs +++ /dev/null @@ -1,86 +0,0 @@ -#[derive(Debug, PartialEq, Clone)] -pub enum GfxVendors { - Nvidia, - Integrated, - Compute, - Hybrid, -} - -use std::str::FromStr; - -use super::error::GfxError; - -impl FromStr for GfxVendors { - type Err = GfxError; - - 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(GfxError::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 = GfxError; - - 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(GfxError::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() - } -} diff --git a/daemon/src/ctrl_leds.rs b/daemon/src/ctrl_leds.rs index df14ca33..db14b07d 100644 --- a/daemon/src/ctrl_leds.rs +++ b/daemon/src/ctrl_leds.rs @@ -46,8 +46,7 @@ impl GetSupported for CtrlKbdBacklight { per_key_led_mode = true; let modes = modes .iter() - .filter(|x| **x != PER_KEY) - .map(|x| *x) + .filter(|x| **x != PER_KEY).copied() .collect(); stock_led_modes = Some(modes); } else { @@ -293,7 +292,7 @@ impl CtrlKbdBacklight { warn!("led_node: {}", err); None }, - |node| Some(node), + Some, ); let kbd_node = Self::get_node_failover(id_product, condev_iface, Self::scan_kbd_node) @@ -302,7 +301,7 @@ impl CtrlKbdBacklight { warn!("kbd_node: {}", err); None }, - |node| Some(node), + Some, ); let bright_node = Self::get_kbd_bright_path(); @@ -375,7 +374,7 @@ impl CtrlKbdBacklight { { if parent .attribute_value("idProduct") - .ok_or(RogError::NotFound("LED idProduct".into()))? + .ok_or_else(|| RogError::NotFound("LED idProduct".into()))? == id_product { if let Some(dev_node) = device.devnode() { diff --git a/daemon/src/ctrl_rog_bios.rs b/daemon/src/ctrl_rog_bios.rs index 0fd8670e..5fab528e 100644 --- a/daemon/src/ctrl_rog_bios.rs +++ b/daemon/src/ctrl_rog_bios.rs @@ -1,11 +1,12 @@ use crate::{ config::Config, - ctrl_gfx::{gfx::CtrlGraphics, vendors::GfxVendors}, + ctrl_gfx::{gfx::CtrlGraphics}, error::RogError, GetSupported, }; //use crate::dbus::DbusEvents; use log::{info, warn}; +use rog_types::gfx_vendors::GfxVendors; use serde_derive::{Deserialize, Serialize}; use std::convert::TryInto; use std::fs::OpenOptions; diff --git a/daemon/src/daemon.rs b/daemon/src/daemon.rs index eb3a8c98..9806a6e5 100644 --- a/daemon/src/daemon.rs +++ b/daemon/src/daemon.rs @@ -3,17 +3,18 @@ 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, supported::SupportedFunctions, GetSupported, + config::Config, laptops::print_board_info, ctrl_supported::SupportedFunctions, GetSupported, }; use daemon::{ ctrl_anime::CtrlAnimeDisplay, - ctrl_gfx::{gfx::CtrlGraphics, vendors::GfxVendors}, + ctrl_gfx::{gfx::CtrlGraphics}, }; use rog_dbus::DBUS_NAME; use daemon::{CtrlTask, Reloadable, ZbusAdd}; use log::LevelFilter; use log::{error, info, warn}; +use rog_types::gfx_vendors::GfxVendors; use std::error::Error; use std::io::Write; use std::sync::Arc; diff --git a/daemon/src/error.rs b/daemon/src/error.rs index 6aca7113..be80c59d 100644 --- a/daemon/src/error.rs +++ b/daemon/src/error.rs @@ -1,5 +1,6 @@ use intel_pstate::PStateError; use rog_fan_curve::CurveError; +use rog_types::error::GraphicsError; use std::convert::From; use std::fmt; @@ -64,3 +65,11 @@ impl From for RogError { RogError::FanCurve(err) } } + +impl From for RogError { + fn from(err: GraphicsError) -> Self { + match err { + GraphicsError::ParseVendor => RogError::GfxSwitching(GfxError::ParseVendor) + } + } +} \ No newline at end of file diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index 0ff59f1c..529a32f6 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -1,15 +1,25 @@ #![deny(unused_must_use)] /// Configuration loading, saving pub mod config; -/// +/// Control of AniMe matrix display pub mod ctrl_anime; -/// +/// Control of battery charge level pub mod ctrl_charge; +/// Control CPU min/max freq and turbo, fan mode, fan curves /// +/// Intel machines can control: +/// - CPU min/max frequency +/// - CPU turbo enable/disable +/// - Fan mode (normal, boost, silent) +/// +/// AMD machines can control: +/// - CPU turbo enable/disable +/// - Fan mode (normal, boost, silent) +/// - Fan min/max RPM curve pub mod ctrl_fan_cpu; -/// +/// GPU switching and power pub mod ctrl_gfx; -/// +/// Keyboard LED brightness control, RGB, and LED display modes pub mod ctrl_leds; /// Control ASUS bios function such as boot sound, Optimus/Dedicated gfx mode pub mod ctrl_rog_bios; @@ -17,7 +27,7 @@ pub mod ctrl_rog_bios; pub mod laptops; /// Fetch all supported functions for the laptop -pub mod supported; +pub mod ctrl_supported; mod error; diff --git a/daemon/src/supported.rs b/daemon/src/supported.rs deleted file mode 100644 index 9f2b6601..00000000 --- a/daemon/src/supported.rs +++ /dev/null @@ -1,56 +0,0 @@ -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/rog-dbus/Cargo.toml b/rog-dbus/Cargo.toml index 88b2e0de..f87f64e2 100644 --- a/rog-dbus/Cargo.toml +++ b/rog-dbus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rog_dbus" -version = "2.2.1" +version = "3.0.0" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/rog-types/Cargo.toml b/rog-types/Cargo.toml index 890d9e2d..87106aeb 100644 --- a/rog-types/Cargo.toml +++ b/rog-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rog_types" -version = "2.2.1" +version = "3.0.0" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/rog-types/src/anime_matrix.rs b/rog-types/src/anime_matrix.rs index 4d9c08dd..05f1e039 100644 --- a/rog-types/src/anime_matrix.rs +++ b/rog-types/src/anime_matrix.rs @@ -17,6 +17,12 @@ pub const ANIME_PANE2_PREFIX: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x0 #[derive(Debug, Deserialize, Serialize, Type)] pub struct AniMeDataBuffer(Vec); +impl Default for AniMeDataBuffer { + fn default() -> Self { + Self::new() + } + } + impl AniMeDataBuffer { pub fn new() -> Self { AniMeDataBuffer(vec![0u8; FULL_PANE_LEN]) diff --git a/rog-types/src/aura_modes.rs b/rog-types/src/aura_modes.rs index f2757439..1d97a070 100644 --- a/rog-types/src/aura_modes.rs +++ b/rog-types/src/aura_modes.rs @@ -205,20 +205,20 @@ pub enum AuraModes { impl From for AuraModes { fn from(mode: SetAuraBuiltin) -> Self { match mode { - SetAuraBuiltin::Static(x) => AuraModes::Static(x.into()), - SetAuraBuiltin::Breathe(x) => AuraModes::Breathe(x.into()), - SetAuraBuiltin::Strobe(x) => AuraModes::Strobe(x.into()), - SetAuraBuiltin::Rainbow(x) => AuraModes::Rainbow(x.into()), - SetAuraBuiltin::Star(x) => AuraModes::Star(x.into()), - SetAuraBuiltin::Rain(x) => AuraModes::Rain(x.into()), - SetAuraBuiltin::Highlight(x) => AuraModes::Highlight(x.into()), - SetAuraBuiltin::Laser(x) => AuraModes::Laser(x.into()), - SetAuraBuiltin::Ripple(x) => AuraModes::Ripple(x.into()), - SetAuraBuiltin::Pulse(x) => AuraModes::Pulse(x.into()), - SetAuraBuiltin::Comet(x) => AuraModes::Comet(x.into()), - SetAuraBuiltin::Flash(x) => AuraModes::Flash(x.into()), - SetAuraBuiltin::MultiStatic(x) => AuraModes::MultiStatic(x.into()), - SetAuraBuiltin::MultiBreathe(x) => AuraModes::MultiBreathe(x.into()), + SetAuraBuiltin::Static(x) => AuraModes::Static(x), + SetAuraBuiltin::Breathe(x) => AuraModes::Breathe(x), + SetAuraBuiltin::Strobe(x) => AuraModes::Strobe(x), + SetAuraBuiltin::Rainbow(x) => AuraModes::Rainbow(x), + SetAuraBuiltin::Star(x) => AuraModes::Star(x), + SetAuraBuiltin::Rain(x) => AuraModes::Rain(x), + SetAuraBuiltin::Highlight(x) => AuraModes::Highlight(x), + SetAuraBuiltin::Laser(x) => AuraModes::Laser(x), + SetAuraBuiltin::Ripple(x) => AuraModes::Ripple(x), + SetAuraBuiltin::Pulse(x) => AuraModes::Pulse(x), + SetAuraBuiltin::Comet(x) => AuraModes::Comet(x), + SetAuraBuiltin::Flash(x) => AuraModes::Flash(x), + SetAuraBuiltin::MultiStatic(x) => AuraModes::MultiStatic(x), + SetAuraBuiltin::MultiBreathe(x) => AuraModes::MultiBreathe(x), } } } diff --git a/rog-types/src/cli_options.rs b/rog-types/src/cli_options.rs index d462dc8e..864ef574 100644 --- a/rog-types/src/cli_options.rs +++ b/rog-types/src/cli_options.rs @@ -34,8 +34,7 @@ impl FromStr for LedBrightness { "high" => Ok(LedBrightness { level: Some(0x03) }), _ => { print!( - "{}\n{}\n", - "Invalid argument, must be one of:", "off, low, med, high" + "Invalid argument, must be one of: off, low, med, high" ); Err(AuraError::ParseBrightness) } @@ -109,7 +108,7 @@ impl FromStr for AniMeStatusValue { "on" => Ok(AniMeStatusValue::On), "off" => Ok(AniMeStatusValue::Off), _ => { - print!("{}\n{}\n", "Invalid argument, must be one of:", "on, off"); + print!("Invalid argument, must be one of: on, off"); Err(AuraError::ParseAnime) } } diff --git a/rog-types/src/lib.rs b/rog-types/src/lib.rs index 02a6e8d3..872626e8 100644 --- a/rog-types/src/lib.rs +++ b/rog-types/src/lib.rs @@ -17,6 +17,8 @@ pub mod fancy; /// Helper functions for the AniMe display pub mod anime_matrix; +pub mod gfx_vendors; + pub mod error; pub static VERSION: &str = env!("CARGO_PKG_VERSION");