mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Refactor and rename a large amount of things to cleanup meanings
This commit is contained in:
@@ -7,12 +7,12 @@ pub static CONFIG_PATH: &str = "/etc/asusd.conf";
|
||||
|
||||
#[derive(Default, Deserialize, Serialize)]
|
||||
pub struct Config {
|
||||
pub fan_mode: u8,
|
||||
pub power_profile: u8,
|
||||
pub bat_charge_limit: u8,
|
||||
pub brightness: u8,
|
||||
pub current_mode: u8,
|
||||
pub builtin_modes: Vec<AuraModes>,
|
||||
pub mode_performance: FanModeSettings,
|
||||
pub kbd_boot_brightness: u8,
|
||||
pub kbd_backlight_mode: u8,
|
||||
pub kbd_backlight_modes: Vec<AuraModes>,
|
||||
pub power_profiles: FanModeProfile,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -31,10 +31,10 @@ impl Config {
|
||||
// create a default config here
|
||||
let mut c = Config::default();
|
||||
c.bat_charge_limit = 100;
|
||||
c.current_mode = 0;
|
||||
c.kbd_backlight_mode = 0;
|
||||
|
||||
for n in supported_led_modes {
|
||||
c.builtin_modes.push(AuraModes::from(*n))
|
||||
c.kbd_backlight_modes.push(AuraModes::from(*n))
|
||||
}
|
||||
|
||||
// Should be okay to unwrap this as is since it is a Default
|
||||
@@ -76,17 +76,17 @@ impl Config {
|
||||
|
||||
pub fn set_mode_data(&mut self, mode: AuraModes) {
|
||||
let byte: u8 = (&mode).into();
|
||||
for (index, n) in self.builtin_modes.iter().enumerate() {
|
||||
for (index, n) in self.kbd_backlight_modes.iter().enumerate() {
|
||||
if byte == u8::from(n) {
|
||||
// Consume it, OMNOMNOMNOM
|
||||
self.builtin_modes[index] = mode;
|
||||
self.kbd_backlight_modes[index] = mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_led_mode_data(&self, num: u8) -> Option<&AuraModes> {
|
||||
for mode in &self.builtin_modes {
|
||||
for mode in &self.kbd_backlight_modes {
|
||||
if u8::from(mode) == num {
|
||||
return Some(mode);
|
||||
}
|
||||
@@ -96,22 +96,22 @@ impl Config {
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, Serialize)]
|
||||
pub struct FanModeSettings {
|
||||
pub normal: IntelPState,
|
||||
pub boost: IntelPState,
|
||||
pub silent: IntelPState,
|
||||
pub struct FanModeProfile {
|
||||
pub normal: CPUSettings,
|
||||
pub boost: CPUSettings,
|
||||
pub silent: CPUSettings,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct IntelPState {
|
||||
pub struct CPUSettings {
|
||||
pub min_percentage: u8,
|
||||
pub max_percentage: u8,
|
||||
pub no_turbo: bool,
|
||||
}
|
||||
|
||||
impl Default for IntelPState {
|
||||
impl Default for CPUSettings {
|
||||
fn default() -> Self {
|
||||
IntelPState {
|
||||
CPUSettings {
|
||||
min_percentage: 0,
|
||||
max_percentage: 100,
|
||||
no_turbo: false,
|
||||
|
||||
@@ -62,10 +62,10 @@ impl crate::Controller for CtrlFanAndCPU {
|
||||
|
||||
async fn reload_from_config(&mut self, config: &mut Config) -> Result<(), Box<dyn Error>> {
|
||||
let mut file = OpenOptions::new().write(true).open(self.path)?;
|
||||
file.write_all(format!("{:?}\n", config.fan_mode).as_bytes())
|
||||
file.write_all(format!("{:?}\n", config.power_profile).as_bytes())
|
||||
.unwrap_or_else(|err| error!("Could not write to {}, {:?}", self.path, err));
|
||||
self.set_pstate_for_fan_mode(FanLevel::from(config.fan_mode), config)?;
|
||||
info!("Reloaded fan mode: {:?}", FanLevel::from(config.fan_mode));
|
||||
self.set_pstate_for_fan_mode(FanLevel::from(config.power_profile), config)?;
|
||||
info!("Reloaded fan mode: {:?}", FanLevel::from(config.power_profile));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -98,13 +98,13 @@ impl CtrlFanAndCPU {
|
||||
let mut buf = [0u8; 1];
|
||||
file.read_exact(&mut buf)?;
|
||||
if let Some(num) = char::from(buf[0]).to_digit(10) {
|
||||
if config.fan_mode != num as u8 {
|
||||
config.fan_mode = num as u8;
|
||||
if config.power_profile != num as u8 {
|
||||
config.power_profile = num as u8;
|
||||
config.write();
|
||||
self.set_pstate_for_fan_mode(FanLevel::from(config.fan_mode), config)?;
|
||||
self.set_pstate_for_fan_mode(FanLevel::from(config.power_profile), config)?;
|
||||
info!(
|
||||
"Fan mode was changed: {:?}",
|
||||
FanLevel::from(config.fan_mode)
|
||||
FanLevel::from(config.power_profile)
|
||||
);
|
||||
}
|
||||
return Ok(());
|
||||
@@ -123,12 +123,12 @@ impl CtrlFanAndCPU {
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let mut fan_ctrl = OpenOptions::new().write(true).open(self.path)?;
|
||||
|
||||
config.fan_mode = n;
|
||||
config.power_profile = n;
|
||||
config.write();
|
||||
fan_ctrl
|
||||
.write_all(format!("{:?}\n", config.fan_mode).as_bytes())
|
||||
.write_all(format!("{:?}\n", config.power_profile).as_bytes())
|
||||
.unwrap_or_else(|err| error!("Could not write to {}, {:?}", self.path, err));
|
||||
info!("Fan mode set to: {:?}", FanLevel::from(config.fan_mode));
|
||||
info!("Fan mode set to: {:?}", FanLevel::from(config.power_profile));
|
||||
self.set_pstate_for_fan_mode(FanLevel::from(n), config)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -142,36 +142,36 @@ impl CtrlFanAndCPU {
|
||||
if let Ok(pstate) = intel_pstate::PState::new() {
|
||||
match mode {
|
||||
FanLevel::Normal => {
|
||||
pstate.set_min_perf_pct(config.mode_performance.normal.min_percentage)?;
|
||||
pstate.set_max_perf_pct(config.mode_performance.normal.max_percentage)?;
|
||||
pstate.set_no_turbo(config.mode_performance.normal.no_turbo)?;
|
||||
pstate.set_min_perf_pct(config.power_profiles.normal.min_percentage)?;
|
||||
pstate.set_max_perf_pct(config.power_profiles.normal.max_percentage)?;
|
||||
pstate.set_no_turbo(config.power_profiles.normal.no_turbo)?;
|
||||
info!(
|
||||
"Intel CPU Power: min: {:?}%, max: {:?}%, turbo: {:?}",
|
||||
config.mode_performance.normal.min_percentage,
|
||||
config.mode_performance.normal.max_percentage,
|
||||
!config.mode_performance.normal.no_turbo
|
||||
config.power_profiles.normal.min_percentage,
|
||||
config.power_profiles.normal.max_percentage,
|
||||
!config.power_profiles.normal.no_turbo
|
||||
);
|
||||
}
|
||||
FanLevel::Boost => {
|
||||
pstate.set_min_perf_pct(config.mode_performance.boost.min_percentage)?;
|
||||
pstate.set_max_perf_pct(config.mode_performance.boost.max_percentage)?;
|
||||
pstate.set_no_turbo(config.mode_performance.boost.no_turbo)?;
|
||||
pstate.set_min_perf_pct(config.power_profiles.boost.min_percentage)?;
|
||||
pstate.set_max_perf_pct(config.power_profiles.boost.max_percentage)?;
|
||||
pstate.set_no_turbo(config.power_profiles.boost.no_turbo)?;
|
||||
info!(
|
||||
"Intel CPU Power: min: {:?}%, max: {:?}%, turbo: {:?}",
|
||||
config.mode_performance.boost.min_percentage,
|
||||
config.mode_performance.boost.max_percentage,
|
||||
!config.mode_performance.boost.no_turbo
|
||||
config.power_profiles.boost.min_percentage,
|
||||
config.power_profiles.boost.max_percentage,
|
||||
!config.power_profiles.boost.no_turbo
|
||||
);
|
||||
}
|
||||
FanLevel::Silent => {
|
||||
pstate.set_min_perf_pct(config.mode_performance.silent.min_percentage)?;
|
||||
pstate.set_max_perf_pct(config.mode_performance.silent.max_percentage)?;
|
||||
pstate.set_no_turbo(config.mode_performance.silent.no_turbo)?;
|
||||
pstate.set_min_perf_pct(config.power_profiles.silent.min_percentage)?;
|
||||
pstate.set_max_perf_pct(config.power_profiles.silent.max_percentage)?;
|
||||
pstate.set_no_turbo(config.power_profiles.silent.no_turbo)?;
|
||||
info!(
|
||||
"Intel CPU Power: min: {:?}%, max: {:?}%, turbo: {:?}",
|
||||
config.mode_performance.silent.min_percentage,
|
||||
config.mode_performance.silent.max_percentage,
|
||||
!config.mode_performance.silent.no_turbo
|
||||
config.power_profiles.silent.min_percentage,
|
||||
config.power_profiles.silent.max_percentage,
|
||||
!config.power_profiles.silent.no_turbo
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ impl CtrlFanAndCPU {
|
||||
})?;
|
||||
match mode {
|
||||
FanLevel::Normal => {
|
||||
let boost = if config.mode_performance.normal.no_turbo {
|
||||
let boost = if config.power_profiles.normal.no_turbo {
|
||||
"0"
|
||||
} else {
|
||||
"1"
|
||||
@@ -198,7 +198,7 @@ impl CtrlFanAndCPU {
|
||||
info!("AMD CPU Turbo: {:?}", boost);
|
||||
}
|
||||
FanLevel::Boost => {
|
||||
let boost = if config.mode_performance.boost.no_turbo {
|
||||
let boost = if config.power_profiles.boost.no_turbo {
|
||||
"0"
|
||||
} else {
|
||||
"1"
|
||||
@@ -209,7 +209,7 @@ impl CtrlFanAndCPU {
|
||||
info!("AMD CPU Turbo: {:?}", boost);
|
||||
}
|
||||
FanLevel::Silent => {
|
||||
let boost = if config.mode_performance.silent.no_turbo {
|
||||
let boost = if config.power_profiles.silent.no_turbo {
|
||||
"0"
|
||||
} else {
|
||||
"1"
|
||||
|
||||
@@ -71,9 +71,9 @@ impl crate::Controller for CtrlKbdBacklight {
|
||||
async fn reload_from_config(&mut self, config: &mut Config) -> Result<(), Box<dyn Error>> {
|
||||
// set current mode (if any)
|
||||
if self.supported_modes.len() > 1 {
|
||||
if self.supported_modes.contains(&config.current_mode) {
|
||||
if self.supported_modes.contains(&config.kbd_backlight_mode) {
|
||||
let mode = config
|
||||
.get_led_mode_data(config.current_mode)
|
||||
.get_led_mode_data(config.kbd_backlight_mode)
|
||||
.ok_or(RogError::NotSupported)?
|
||||
.to_owned();
|
||||
self.write_mode(&mode).await?;
|
||||
@@ -81,19 +81,19 @@ impl crate::Controller for CtrlKbdBacklight {
|
||||
} else {
|
||||
warn!(
|
||||
"An unsupported mode was set: {}, reset to first mode available",
|
||||
<&str>::from(&<AuraModes>::from(config.current_mode))
|
||||
<&str>::from(&<AuraModes>::from(config.kbd_backlight_mode))
|
||||
);
|
||||
for (idx, mode) in config.builtin_modes.iter_mut().enumerate() {
|
||||
for (idx, mode) in config.kbd_backlight_modes.iter_mut().enumerate() {
|
||||
if !self.supported_modes.contains(&mode.into()) {
|
||||
config.builtin_modes.remove(idx);
|
||||
config.kbd_backlight_modes.remove(idx);
|
||||
config.write();
|
||||
break;
|
||||
}
|
||||
}
|
||||
config.current_mode = self.supported_modes[0];
|
||||
config.kbd_backlight_mode = self.supported_modes[0];
|
||||
// TODO: do a recursive call with a boxed dyn future later
|
||||
let mode = config
|
||||
.get_led_mode_data(config.current_mode)
|
||||
.get_led_mode_data(config.kbd_backlight_mode)
|
||||
.ok_or(RogError::NotSupported)?
|
||||
.to_owned();
|
||||
self.write_mode(&mode).await?;
|
||||
@@ -102,7 +102,7 @@ impl crate::Controller for CtrlKbdBacklight {
|
||||
}
|
||||
|
||||
// Reload brightness
|
||||
let bright = config.brightness;
|
||||
let bright = config.kbd_boot_brightness;
|
||||
let bytes = aura_brightness_bytes(bright);
|
||||
self.write_bytes(&bytes).await?;
|
||||
info!("Reloaded last used brightness");
|
||||
@@ -186,7 +186,7 @@ impl CtrlKbdBacklight {
|
||||
AuraModes::LedBrightness(n) => {
|
||||
let bytes: [u8; LED_MSG_LEN] = (&mode).into();
|
||||
self.write_bytes(&bytes).await?;
|
||||
config.brightness = n;
|
||||
config.kbd_boot_brightness = n;
|
||||
config.write();
|
||||
info!("LED brightness set to {:#?}", n);
|
||||
}
|
||||
@@ -201,7 +201,7 @@ impl CtrlKbdBacklight {
|
||||
_ => {
|
||||
let mode_num: u8 = u8::from(&mode);
|
||||
self.write_mode(&mode).await?;
|
||||
config.current_mode = mode_num;
|
||||
config.kbd_backlight_mode = mode_num;
|
||||
config.set_mode_data(mode);
|
||||
config.write();
|
||||
}
|
||||
|
||||
@@ -168,15 +168,15 @@ fn start_signal_task(
|
||||
) {
|
||||
tokio::spawn(async move {
|
||||
// Some small things we need to track, without passing all sorts of stuff around
|
||||
let mut last_fan_mode = config.lock().await.fan_mode;
|
||||
let mut last_fan_mode = config.lock().await.power_profile;
|
||||
let mut last_charge_limit = config.lock().await.bat_charge_limit;
|
||||
loop {
|
||||
// Use tokio sleep to not hold up other threads
|
||||
tokio::time::delay_for(std::time::Duration::from_millis(500)).await;
|
||||
|
||||
let config = config.lock().await;
|
||||
if config.fan_mode != last_fan_mode {
|
||||
last_fan_mode = config.fan_mode;
|
||||
if config.power_profile != last_fan_mode {
|
||||
last_fan_mode = config.power_profile;
|
||||
connection
|
||||
.send(
|
||||
fanmode_signal
|
||||
@@ -210,7 +210,7 @@ async fn send_boot_signals(
|
||||
|
||||
let config = config.lock().await;
|
||||
|
||||
if let Some(data) = config.get_led_mode_data(config.current_mode) {
|
||||
if let Some(data) = config.get_led_mode_data(config.kbd_backlight_mode) {
|
||||
connection
|
||||
.send(
|
||||
led_changed_signal
|
||||
@@ -224,7 +224,7 @@ async fn send_boot_signals(
|
||||
.send(
|
||||
fanmode_signal
|
||||
.msg(&DBUS_PATH.into(), &DBUS_IFACE.into())
|
||||
.append1(config.fan_mode),
|
||||
.append1(config.power_profile),
|
||||
)
|
||||
.unwrap_or_else(|_| 0);
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ fn get_keyboard_backlight(config: Arc<Mutex<Config>>) -> Method<MTSync, ()> {
|
||||
.method("GetKeyBacklight", (), {
|
||||
move |m| {
|
||||
if let Ok(lock) = config.try_lock() {
|
||||
for mode in &lock.builtin_modes {
|
||||
if lock.current_mode == <u8>::from(mode) {
|
||||
for mode in &lock.kbd_backlight_modes {
|
||||
if lock.kbd_backlight_mode == <u8>::from(mode) {
|
||||
let mode = serde_json::to_string(&mode).unwrap();
|
||||
let mret = m.msg.method_return().append1(mode);
|
||||
return Ok(vec![mret]);
|
||||
@@ -63,7 +63,7 @@ fn get_keyboard_backlight_modes(config: Arc<Mutex<Config>>) -> Method<MTSync, ()
|
||||
.method("GetKeyBacklightModes", (), {
|
||||
move |m| {
|
||||
if let Ok(lock) = config.try_lock() {
|
||||
let mode = serde_json::to_string(&lock.builtin_modes).unwrap();
|
||||
let mode = serde_json::to_string(&lock.kbd_backlight_modes).unwrap();
|
||||
let mret = m.msg.method_return().append1(mode);
|
||||
Ok(vec![mret])
|
||||
} else {
|
||||
@@ -124,7 +124,7 @@ fn get_fan_mode(config: Arc<Mutex<Config>>) -> Method<MTSync, ()> {
|
||||
.method("GetFanMode", (), {
|
||||
move |m| {
|
||||
if let Ok(lock) = config.try_lock() {
|
||||
let mret = m.msg.method_return().append1(lock.fan_mode);
|
||||
let mret = m.msg.method_return().append1(lock.power_profile);
|
||||
Ok(vec![mret])
|
||||
} else {
|
||||
Err(MethodErr::failed("Could not lock config for access"))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use log::{info, warn};
|
||||
use asus_nb::aura_modes::{
|
||||
AuraModes, BREATHING, COMET, FLASH, HIGHLIGHT, LASER, MULTISTATIC, PULSE, RAIN, RAINBOW, RGB,
|
||||
RIPPLE, SINGLE, STAR, STROBE,
|
||||
RIPPLE, STATIC, STAR, STROBE,
|
||||
};
|
||||
|
||||
static HELP_ADDRESS: &str = "https://gitlab.com/asus-linux/asus-nb-ctrl";
|
||||
@@ -17,7 +17,7 @@ pub fn match_laptop() -> LaptopBase {
|
||||
info!("Found GL753 or similar");
|
||||
return LaptopBase {
|
||||
usb_product: "1854".to_string(),
|
||||
supported_modes: vec![SINGLE, BREATHING, STROBE],
|
||||
supported_modes: vec![STATIC, BREATHING, STROBE],
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
@@ -54,12 +54,12 @@ fn select_1866_device(prod: String) -> LaptopBase {
|
||||
|| board_name.starts_with("G532")
|
||||
{
|
||||
laptop.supported_modes = vec![
|
||||
SINGLE, BREATHING, STROBE, RAINBOW, STAR, RAIN, HIGHLIGHT, LASER, RIPPLE, PULSE, COMET,
|
||||
STATIC, BREATHING, STROBE, RAINBOW, STAR, RAIN, HIGHLIGHT, LASER, RIPPLE, PULSE, COMET,
|
||||
FLASH, RGB,
|
||||
];
|
||||
} else if board_name.starts_with("G531") || board_name.starts_with("G731") {
|
||||
laptop.supported_modes = vec![
|
||||
SINGLE,
|
||||
STATIC,
|
||||
BREATHING,
|
||||
STROBE,
|
||||
RAINBOW,
|
||||
@@ -76,14 +76,14 @@ fn select_1866_device(prod: String) -> LaptopBase {
|
||||
];
|
||||
// RGB, limited effects, no zones
|
||||
} else if board_name.starts_with("G512LI") || board_name.starts_with("G712LI") {
|
||||
laptop.supported_modes = vec![SINGLE, BREATHING, STROBE, RAINBOW, PULSE];
|
||||
laptop.supported_modes = vec![STATIC, BREATHING, STROBE, RAINBOW, PULSE];
|
||||
// RGB, limited effects, 4-zone RGB
|
||||
} else if board_name.starts_with("GM501")
|
||||
|| board_name.starts_with("GX531")
|
||||
|| board_name.starts_with("G512")
|
||||
|| board_name.starts_with("G712")
|
||||
{
|
||||
laptop.supported_modes = vec![SINGLE, BREATHING, STROBE, RAINBOW, PULSE, MULTISTATIC];
|
||||
laptop.supported_modes = vec![STATIC, BREATHING, STROBE, RAINBOW, PULSE, MULTISTATIC];
|
||||
} else {
|
||||
warn!(
|
||||
"Unsupported laptop, please request support at {}",
|
||||
|
||||
@@ -3,7 +3,7 @@ use gumdrop::Options;
|
||||
use log::LevelFilter;
|
||||
use asus_nb::{
|
||||
cli_options::{LedBrightness, SetAuraBuiltin},
|
||||
core_dbus::AuraDbusWriter,
|
||||
core_dbus::AuraDbusClient,
|
||||
};
|
||||
use std::io::Write;
|
||||
|
||||
@@ -14,11 +14,11 @@ struct CLIStart {
|
||||
#[options(help = "show program version number")]
|
||||
version: bool,
|
||||
#[options(meta = "VAL", help = "<off, low, med, high>")]
|
||||
bright: Option<LedBrightness>,
|
||||
#[options(meta = "FAN", help = "<silent, normal, boost>")]
|
||||
fan_mode: Option<FanLevel>,
|
||||
kbd_bright: Option<LedBrightness>,
|
||||
#[options(meta = "PWR", help = "<silent, normal, boost>")]
|
||||
pwr_profile: Option<FanLevel>,
|
||||
#[options(meta = "CHRG", help = "<20-100>")]
|
||||
charge_limit: Option<u8>,
|
||||
chg_limit: Option<u8>,
|
||||
#[options(command)]
|
||||
command: Option<Command>,
|
||||
}
|
||||
@@ -52,21 +52,21 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Version: {}", daemon::VERSION);
|
||||
}
|
||||
|
||||
let writer = AuraDbusWriter::new()?;
|
||||
let writer = AuraDbusClient::new()?;
|
||||
|
||||
if let Some(Command::LedMode(mode)) = parsed.command {
|
||||
if let Some(command) = mode.command {
|
||||
writer.write_builtin_mode(&command.into())?
|
||||
}
|
||||
}
|
||||
if let Some(brightness) = parsed.bright {
|
||||
if let Some(brightness) = parsed.kbd_bright {
|
||||
writer.write_brightness(brightness.level())?;
|
||||
}
|
||||
if let Some(fan_level) = parsed.fan_mode {
|
||||
if let Some(fan_level) = parsed.pwr_profile {
|
||||
writer.write_fan_mode(fan_level.into())?;
|
||||
}
|
||||
if let Some(charge_limit) = parsed.charge_limit {
|
||||
writer.write_charge_limit(charge_limit)?;
|
||||
if let Some(chg_limit) = parsed.chg_limit {
|
||||
writer.write_charge_limit(chg_limit)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user