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

@@ -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. - Remove dbus crate in favour of zbus. This removes the external dbus lib requirement.
- Huge internal refactor - Huge internal refactor
- BREAKING CHANGE: Anime code refactor. DBUS method names have changed - BREAKING CHANGE: Anime code refactor. DBUS method names have changed
- Cleanup fan and cpu control + configs
# [2.2.2] - 2021-01-31 # [2.2.2] - 2021-01-31
### Changed ### Changed

View File

@@ -1,4 +1,4 @@
use daemon::{config::Profile}; use daemon::config::Profile;
use notify_rust::{Hint, Notification, NotificationHandle}; use notify_rust::{Hint, Notification, NotificationHandle};
use rog_dbus::{DbusProxies, Signals}; use rog_dbus::{DbusProxies, Signals};
use std::error::Error; use std::error::Error;

View File

@@ -1,7 +1,5 @@
use rog_dbus::AuraDbusClient; use rog_dbus::AuraDbusClient;
use rog_types::{ use rog_types::anime_matrix::{AniMeImageBuffer, AniMePacketType, HEIGHT, WIDTH};
anime_matrix::{AniMeImageBuffer, AniMePacketType, HEIGHT, WIDTH},
};
use tinybmp::{Bmp, Pixel}; use tinybmp::{Bmp, Pixel};
fn main() { fn main() {

View File

@@ -1,7 +1,5 @@
use rog_types::{
fancy::{GX502Layout, Key, KeyColourArray, KeyLayout},
};
use rog_dbus::AuraDbusClient; use rog_dbus::AuraDbusClient;
use rog_types::fancy::{GX502Layout, Key, KeyColourArray, KeyLayout};
use std::collections::LinkedList; use std::collections::LinkedList;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@@ -1,7 +1,5 @@
use rog_types::{
fancy::{GX502Layout, KeyColourArray, KeyLayout},
};
use rog_dbus::AuraDbusClient; use rog_dbus::AuraDbusClient;
use rog_types::fancy::{GX502Layout, KeyColourArray, KeyLayout};
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let (dbus, _) = AuraDbusClient::new()?; let (dbus, _) = AuraDbusClient::new()?;

View File

@@ -1,7 +1,5 @@
use rog_types::{
fancy::{GX502Layout, Key, KeyColourArray, KeyLayout},
};
use rog_dbus::AuraDbusClient; use rog_dbus::AuraDbusClient;
use rog_types::fancy::{GX502Layout, Key, KeyColourArray, KeyLayout};
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let (dbus, _) = AuraDbusClient::new()?; let (dbus, _) = AuraDbusClient::new()?;

View File

@@ -1,7 +1,5 @@
use rog_types::{
fancy::{Key, KeyColourArray},
};
use rog_dbus::AuraDbusClient; use rog_dbus::AuraDbusClient;
use rog_types::fancy::{Key, KeyColourArray};
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let (dbus, _) = AuraDbusClient::new()?; let (dbus, _) = AuraDbusClient::new()?;

View File

@@ -1,7 +1,5 @@
use rog_types::{
fancy::{GX502Layout, KeyColourArray, KeyLayout},
};
use rog_dbus::AuraDbusClient; use rog_dbus::AuraDbusClient;
use rog_types::fancy::{GX502Layout, KeyColourArray, KeyLayout};
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let (dbus, _) = AuraDbusClient::new()?; let (dbus, _) = AuraDbusClient::new()?;

View File

@@ -1,9 +1,14 @@
use gumdrop::{Opt, Options}; use gumdrop::{Opt, Options};
use rog_dbus::AuraDbusClient; 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 std::{env::args, process::Command};
use yansi_term::Colour::Green; use yansi_term::Colour::Green;
use yansi_term::Colour::Red; 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)] #[derive(Default, Options)]
struct CLIStart { struct CLIStart {

View File

@@ -1,6 +1,6 @@
use rog_types::aura_modes::AuraModes;
use log::{error, info, warn}; use log::{error, info, warn};
use rog_fan_curve::Curve; use rog_fan_curve::Curve;
use rog_types::aura_modes::AuraModes;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
@@ -18,7 +18,6 @@ struct ConfigV212 {
active_profile: String, active_profile: String,
toggle_profiles: Vec<String>, toggle_profiles: Vec<String>,
power_profiles: BTreeMap<String, Profile>, power_profiles: BTreeMap<String, Profile>,
// TODO: remove power_profile
power_profile: u8, power_profile: u8,
kbd_led_brightness: u8, kbd_led_brightness: u8,
kbd_backlight_mode: u8, kbd_backlight_mode: u8,
@@ -32,7 +31,38 @@ impl ConfigV212 {
gfx_nv_mode_is_dedicated: true, gfx_nv_mode_is_dedicated: true,
active_profile: self.active_profile, active_profile: self.active_profile,
toggle_profiles: self.toggle_profiles, 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<String>,
power_profiles: BTreeMap<String, Profile>,
power_profile: u8,
kbd_led_brightness: u8,
kbd_backlight_mode: u8,
kbd_backlight_modes: Vec<AuraModes>,
}
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, bat_charge_limit: self.bat_charge_limit,
kbd_led_brightness: self.kbd_led_brightness, kbd_led_brightness: self.kbd_led_brightness,
kbd_backlight_mode: self.kbd_backlight_mode, kbd_backlight_mode: self.kbd_backlight_mode,
@@ -49,7 +79,8 @@ pub struct Config {
pub active_profile: String, pub active_profile: String,
pub toggle_profiles: Vec<String>, pub toggle_profiles: Vec<String>,
// TODO: remove power_profile // TODO: remove power_profile
pub power_profile: u8, #[serde(skip)]
pub curr_fan_mode: u8,
pub bat_charge_limit: u8, pub bat_charge_limit: u8,
pub kbd_led_brightness: u8, pub kbd_led_brightness: u8,
pub kbd_backlight_mode: u8, pub kbd_backlight_mode: u8,
@@ -57,7 +88,7 @@ pub struct Config {
pub power_profiles: BTreeMap<String, Profile>, pub power_profiles: BTreeMap<String, Profile>,
} }
impl Default for Config { impl Default for Config {
fn default() -> Self { fn default() -> Self {
let mut pwr = BTreeMap::new(); let mut pwr = BTreeMap::new();
pwr.insert("normal".into(), Profile::new(0, 100, true, 0, None)); 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, gfx_nv_mode_is_dedicated: true,
active_profile: "normal".into(), active_profile: "normal".into(),
toggle_profiles: vec!["normal".into(), "boost".into(), "silent".into()], toggle_profiles: vec!["normal".into(), "boost".into(), "silent".into()],
power_profile: 0, curr_fan_mode: 0,
bat_charge_limit:100, bat_charge_limit: 100,
kbd_led_brightness: 1, kbd_led_brightness: 1,
kbd_backlight_mode: 0, kbd_backlight_mode: 0,
kbd_backlight_modes: Vec::new(), kbd_backlight_modes: Vec::new(),
@@ -98,6 +129,11 @@ impl Config {
} else { } else {
if let Ok(data) = serde_json::from_str(&buf) { if let Ok(data) = serde_json::from_str(&buf) {
return data; return data;
} else if let Ok(data) = serde_json::from_str::<ConfigV222>(&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::<ConfigV212>(&buf) { } else if let Ok(data) = serde_json::from_str::<ConfigV212>(&buf) {
let config = data.into_current(); let config = data.into_current();
config.write(); config.write();
@@ -207,15 +243,19 @@ impl Default for Profile {
} }
impl Profile { impl Profile {
pub fn new(min_percentage: u8, max_percentage: u8, turbo: bool, pub fn new(
fan_preset: u8, fan_curve: Option<Curve>) -> Self { min_percentage: u8,
max_percentage: u8,
turbo: bool,
fan_preset: u8,
fan_curve: Option<Curve>,
) -> Self {
Profile { Profile {
min_percentage, min_percentage,
max_percentage, max_percentage,
turbo, turbo,
fan_preset, fan_preset,
fan_curve, fan_curve,
} }
} }
} }

View File

@@ -132,9 +132,7 @@ impl CtrlAnimeDisplay {
})?; })?;
info!("Device has an AniMe Matrix display"); info!("Device has an AniMe Matrix display");
let ctrl = CtrlAnimeDisplay { let ctrl = CtrlAnimeDisplay { handle: device };
handle: device,
};
ctrl.do_initialization()?; ctrl.do_initialization()?;
Ok(ctrl) Ok(ctrl)

View File

@@ -1,9 +1,10 @@
use crate::error::RogError;
use crate::{ use crate::{
config::{Config, Profile}, config::{Config, Profile},
GetSupported, GetSupported,
}; };
use rog_types::profile::{FanLevel, ProfileEvent};
use log::{info, warn}; use log::{info, warn};
use rog_types::profile::{FanLevel, ProfileEvent};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::convert::TryInto; use std::convert::TryInto;
use std::fs::OpenOptions; use std::fs::OpenOptions;
@@ -12,7 +13,6 @@ use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use zbus::dbus_interface; 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_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"; static FAN_TYPE_2_PATH: &str = "/sys/devices/platform/asus-nb-wmi/fan_boost_mode";
@@ -62,8 +62,7 @@ impl DbusFanAndCpu {
cfg.read(); cfg.read();
ctrl.handle_profile_event(&event, &mut cfg) ctrl.handle_profile_event(&event, &mut cfg)
.unwrap_or_else(|err| warn!("{}", err)); .unwrap_or_else(|err| warn!("{}", err));
self.notify_profile(&cfg.active_profile) self.notify_profile(&cfg.active_profile).unwrap_or(());
.unwrap_or(());
} }
} }
} }
@@ -142,65 +141,17 @@ impl crate::ZbusAdd for DbusFanAndCpu {
impl crate::Reloadable for CtrlFanAndCPU { impl crate::Reloadable for CtrlFanAndCPU {
fn reload(&mut self) -> Result<(), RogError> { fn reload(&mut self) -> Result<(), RogError> {
if let Ok(mut config) = self.config.clone().try_lock() { 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(); let profile = config.active_profile.clone();
self.set(&profile, &mut config)?; self.set(&profile, &mut config)?;
info!( // info!(
"Reloaded fan mode: {:?}", // "Reloaded fan mode: {:?}",
FanLevel::from(config.power_profile) // FanLevel::from(config.power_profile)
); // );
} }
Ok(()) 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 { impl CtrlFanAndCPU {
pub fn new(config: Arc<Mutex<Config>>) -> Result<Self, RogError> { pub fn new(config: Arc<Mutex<Config>>) -> Result<Self, RogError> {
let path = CtrlFanAndCPU::get_fan_path()?; let path = CtrlFanAndCPU::get_fan_path()?;
@@ -246,7 +197,7 @@ impl CtrlFanAndCPU {
Ok(()) 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 mode = config.active_profile.clone();
let mut fan_ctrl = OpenOptions::new() let mut fan_ctrl = OpenOptions::new()
.write(true) .write(true)
@@ -257,15 +208,13 @@ impl CtrlFanAndCPU {
.power_profiles .power_profiles
.get_mut(&mode) .get_mut(&mode)
.ok_or_else(|| RogError::MissingProfile(mode.clone()))?; .ok_or_else(|| RogError::MissingProfile(mode.clone()))?;
config.power_profile = preset; config.curr_fan_mode = preset;
mode_config.fan_preset = preset; mode_config.fan_preset = preset;
config.write(); config.write();
fan_ctrl fan_ctrl
.write_all(format!("{}\n", preset).as_bytes()) .write_all(format!("{}\n", preset).as_bytes())
.map_err(|err| RogError::Write(self.path.into(), err))?; .map_err(|err| RogError::Write(self.path.into(), err))?;
info!("Fan mode set to: {:?}", FanLevel::from(preset)); 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(()) Ok(())
} }
@@ -278,6 +227,9 @@ impl CtrlFanAndCPU {
ProfileEvent::Toggle => self.do_next_profile(config)?, ProfileEvent::Toggle => self.do_next_profile(config)?,
ProfileEvent::ChangeMode(mode) => { ProfileEvent::ChangeMode(mode) => {
self.set_fan_mode(*mode, config)?; 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) => { ProfileEvent::Cli(command) => {
let profile_key = match command.profile.as_ref() { let profile_key = match command.profile.as_ref() {
@@ -328,10 +280,10 @@ impl CtrlFanAndCPU {
.write(true) .write(true)
.open(self.path) .open(self.path)
.map_err(|err| RogError::Path(self.path.into(), err))?; .map_err(|err| RogError::Path(self.path.into(), err))?;
config.curr_fan_mode = mode_config.fan_preset;
fan_ctrl fan_ctrl
.write_all(format!("{}\n", mode_config.fan_preset).as_bytes()) .write_all(format!("{}\n", mode_config.fan_preset).as_bytes())
.map_err(|err| RogError::Write(self.path.into(), err))?; .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_pstate_for_fan_mode(profile, config)?;
self.set_fan_curve_for_fan_mode(profile, config)?; self.set_fan_curve_for_fan_mode(profile, config)?;

View File

@@ -2,6 +2,7 @@ use ctrl_gfx::error::GfxError;
use ctrl_gfx::*; use ctrl_gfx::*;
use ctrl_rog_bios::CtrlRogBios; use ctrl_rog_bios::CtrlRogBios;
use log::{error, info, warn}; use log::{error, info, warn};
use rog_types::gfx_vendors::{GfxCtrlAction, GfxVendors};
use std::io::Write; use std::io::Write;
use std::iter::FromIterator; use std::iter::FromIterator;
use std::path::Path; use std::path::Path;
@@ -10,7 +11,6 @@ use std::str::FromStr;
use std::{sync::Arc, sync::Mutex}; use std::{sync::Arc, sync::Mutex};
use sysfs_class::{PciDevice, SysClass}; use sysfs_class::{PciDevice, SysClass};
use system::{GraphicsDevice, Module, PciBus}; use system::{GraphicsDevice, Module, PciBus};
use rog_types::gfx_vendors::{GfxCtrlAction, GfxVendors};
use zbus::dbus_interface; use zbus::dbus_interface;
use crate::*; use crate::*;

View File

@@ -9,13 +9,13 @@ use crate::{
error::RogError, error::RogError,
laptops::{match_laptop, HELP_ADDRESS}, laptops::{match_laptop, HELP_ADDRESS},
}; };
use log::{error, info, warn};
use rog_types::{ use rog_types::{
aura_brightness_bytes, aura_brightness_bytes,
aura_modes::{AuraModes, PER_KEY}, aura_modes::{AuraModes, PER_KEY},
fancy::KeyColourArray, fancy::KeyColourArray,
LED_MSG_LEN, LED_MSG_LEN,
}; };
use log::{error, info, warn};
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::sync::Arc; use std::sync::Arc;
@@ -44,10 +44,7 @@ impl GetSupported for CtrlKbdBacklight {
let modes = laptop.supported_modes().to_vec(); let modes = laptop.supported_modes().to_vec();
if modes.contains(&PER_KEY) { if modes.contains(&PER_KEY) {
per_key_led_mode = true; per_key_led_mode = true;
let modes = modes let modes = modes.iter().filter(|x| **x != PER_KEY).copied().collect();
.iter()
.filter(|x| **x != PER_KEY).copied()
.collect();
stock_led_modes = Some(modes); stock_led_modes = Some(modes);
} else { } else {
stock_led_modes = Some(modes); stock_led_modes = Some(modes);

View File

@@ -1,9 +1,4 @@
use crate::{ use crate::{config::Config, ctrl_gfx::gfx::CtrlGraphics, error::RogError, GetSupported};
config::Config,
ctrl_gfx::{gfx::CtrlGraphics},
error::RogError,
GetSupported,
};
//use crate::dbus::DbusEvents; //use crate::dbus::DbusEvents;
use log::{info, warn}; use log::{info, warn};
use rog_types::gfx_vendors::GfxVendors; use rog_types::gfx_vendors::GfxVendors;

View File

@@ -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(),
}
}
}

View File

@@ -3,17 +3,14 @@ use daemon::ctrl_fan_cpu::{CtrlFanAndCPU, DbusFanAndCpu};
use daemon::ctrl_leds::{CtrlKbdBacklight, DbusKbdBacklight}; use daemon::ctrl_leds::{CtrlKbdBacklight, DbusKbdBacklight};
use daemon::laptops::match_laptop; use daemon::laptops::match_laptop;
use daemon::{ use daemon::{
config::Config, laptops::print_board_info, ctrl_supported::SupportedFunctions, GetSupported, config::Config, ctrl_supported::SupportedFunctions, laptops::print_board_info, GetSupported,
};
use daemon::{
ctrl_anime::CtrlAnimeDisplay,
ctrl_gfx::{gfx::CtrlGraphics},
}; };
use daemon::{ctrl_anime::CtrlAnimeDisplay, ctrl_gfx::gfx::CtrlGraphics};
use rog_dbus::DBUS_NAME;
use daemon::{CtrlTask, Reloadable, ZbusAdd}; use daemon::{CtrlTask, Reloadable, ZbusAdd};
use log::LevelFilter; use log::LevelFilter;
use log::{error, info, warn}; use log::{error, info, warn};
use rog_dbus::DBUS_NAME;
use rog_types::gfx_vendors::GfxVendors; use rog_types::gfx_vendors::GfxVendors;
use std::error::Error; use std::error::Error;
use std::io::Write; use std::io::Write;
@@ -34,7 +31,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
.filter(None, LevelFilter::Info) .filter(None, LevelFilter::Info)
.init(); .init();
info!( "daemon version {}", daemon::VERSION); info!("daemon version {}", daemon::VERSION);
info!(" rog-dbus version {}", rog_dbus::VERSION); info!(" rog-dbus version {}", rog_dbus::VERSION);
info!("rog-types version {}", rog_types::VERSION); info!("rog-types version {}", rog_types::VERSION);
@@ -142,8 +139,7 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
ctrl.reload() ctrl.reload()
.unwrap_or_else(|err| warn!("Profile control: {}", err)); .unwrap_or_else(|err| warn!("Profile control: {}", err));
let tmp = Arc::new(Mutex::new(ctrl)); let tmp = Arc::new(Mutex::new(ctrl));
DbusFanAndCpu::new(tmp.clone()).add_to_server(&mut object_server); DbusFanAndCpu::new(tmp).add_to_server(&mut object_server);
tasks.push(tmp);
}; };
if let Some(laptop) = laptop { if let Some(laptop) = laptop {

View File

@@ -69,7 +69,7 @@ impl From<CurveError> for RogError {
impl From<GraphicsError> for RogError { impl From<GraphicsError> for RogError {
fn from(err: GraphicsError) -> Self { fn from(err: GraphicsError) -> Self {
match err { match err {
GraphicsError::ParseVendor => RogError::GfxSwitching(GfxError::ParseVendor) GraphicsError::ParseVendor => RogError::GfxSwitching(GfxError::ParseVendor),
} }
} }
} }

View File

@@ -1,5 +1,5 @@
use rog_types::aura_modes::{AuraModes, BREATHING, STATIC};
use log::{info, warn}; use log::{info, warn};
use rog_types::aura_modes::{AuraModes, BREATHING, STATIC};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::Read; use std::io::Read;

View File

@@ -11,8 +11,8 @@ pub mod zbus_profile;
pub mod zbus_rogbios; pub mod zbus_rogbios;
pub mod zbus_supported; pub mod zbus_supported;
use std::sync::{Arc, Mutex};
use rog_types::aura_modes::AuraModes; use rog_types::aura_modes::AuraModes;
use std::sync::{Arc, Mutex};
use zbus::{Connection, Result, SignalReceiver}; use zbus::{Connection, Result, SignalReceiver};
pub static VERSION: &str = env!("CARGO_PKG_VERSION"); pub static VERSION: &str = env!("CARGO_PKG_VERSION");

View File

@@ -40,7 +40,6 @@ trait Daemon {
fn write_image(&self, input: &[Vec<u8>]) -> zbus::Result<()>; fn write_image(&self, input: &[Vec<u8>]) -> zbus::Result<()>;
} }
pub struct AnimeProxy<'a>(DaemonProxy<'a>); pub struct AnimeProxy<'a>(DaemonProxy<'a>);
impl<'a> AnimeProxy<'a> { impl<'a> AnimeProxy<'a> {

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>); pub struct AniMeDataBuffer(Vec<u8>);
impl Default for AniMeDataBuffer { impl Default for AniMeDataBuffer {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
}
} }
}
impl AniMeDataBuffer { impl AniMeDataBuffer {
pub fn new() -> Self { pub fn new() -> Self {
AniMeDataBuffer(vec![0u8; FULL_PANE_LEN]) AniMeDataBuffer(vec![0u8; FULL_PANE_LEN])

View File

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