From 36607ac971734c48ed73dff089705ea598cb32ab Mon Sep 17 00:00:00 2001 From: WombatFromHell Date: Wed, 1 Jan 2025 16:18:38 -0700 Subject: [PATCH] Fixed ControlState and assigning speeds under Hyprland --- src/commands.rs | 28 +++++++++++++--------------- src/config.rs | 2 +- src/main.rs | 2 +- src/thermalmanager.rs | 6 +++--- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index d35b890..4c63236 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -2,37 +2,35 @@ use std::process::{Command, Stdio}; pub fn get_gpu_temp() -> u64 { let output = Command::new("nvidia-smi") - .args(&["--query-gpu=temperature.gpu", "--format=csv,noheader"]) + .args(["--query-gpu=temperature.gpu", "--format=csv,noheader"]) .output() .expect("Failed to execute nvidia-smi"); let temp_str = String::from_utf8_lossy(&output.stdout); - temp_str - .trim() - .parse::() - .unwrap_or(0 as u64) - .clamp(0, 200) + temp_str.trim().parse::().unwrap_or(0).clamp(0, 200) } pub fn get_fan_speed() -> u64 { let output = Command::new("nvidia-smi") - .args(&["--query-gpu=fan.speed", "--format=csv,noheader"]) + .args(["--query-gpu=fan.speed", "--format=csv,noheader"]) .output() .expect("Failed to execute nvidia-smi"); let _speed_str = String::from_utf8_lossy(&output.stdout); let speed_str = _speed_str.trim().replace(" %", ""); - speed_str.parse::().unwrap_or(0 as u64).clamp(0, 100) + speed_str.parse::().unwrap_or(0).clamp(0, 100) } pub fn set_fan_control(mode: u8) -> Result<(), Box> { let output = Command::new("sudo") - .args(&[ + .args([ "nvidia-settings", + "-c", + "0", "-a", - format!("*:1[gpu:0]/GPUFanControlState={}", mode).as_str(), + format!("GPUFanControlState={}", mode).as_str(), ]) .stdin(Stdio::piped()) .stdout(Stdio::piped()) @@ -52,14 +50,14 @@ pub fn set_fan_control(mode: u8) -> Result<(), Box> { pub fn set_fan_speed(speed: u64) -> Result<(), Box> { let output = Command::new("sudo") - .args(&[ + .args([ "nvidia-settings", + "-c", + "0", "-a", - "*:1[gpu:0]/GPUFanControlState=1", + "GPUFanControlState=1", "-a", - &format!("*:1[fan-0]/GPUTargetFanSpeed={}", speed), - "-a", - &format!("*:1[fan-1]/GPUTargetFanSpeed={}", speed), + &format!("GPUTargetFanSpeed={}", speed), ]) .stdin(Stdio::piped()) .stdout(Stdio::piped()) diff --git a/src/config.rs b/src/config.rs index c675a53..665978c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -69,7 +69,7 @@ impl Config { let home_dir = env::var("HOME").map_err(|_| ConfigError::MissingHomeDir)?; let xdg_config_path = format!("{}/.config/veridian-controller.toml", home_dir); - let file_path = custom_path.or_else(|| Some(xdg_config_path)); + let file_path = custom_path.or(Some(xdg_config_path)); let file_path = file_path.ok_or(ConfigError::MissingConfigFile)?; diff --git a/src/main.rs b/src/main.rs index a876bd0..f7c15b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,7 +92,7 @@ fn main() -> Result<(), Box> { } }); - let _ = thermal_thread.join().unwrap_or_else(|err| { + thermal_thread.join().unwrap_or_else(|err| { eprintln!("Error in thread: {:?}", err); }); diff --git a/src/thermalmanager.rs b/src/thermalmanager.rs index 82ddef0..2c0cf0e 100644 --- a/src/thermalmanager.rs +++ b/src/thermalmanager.rs @@ -27,7 +27,7 @@ impl<'a> ThermalManager<'a> { last_adjustment_time: None, last_temp_time: None, current_fan_speed: 0, - target_fan_speed: config.fan_speed_floor as u64, + target_fan_speed: config.fan_speed_floor, smooth_mode: if config.smooth_mode { "~" } else { "" }, } } @@ -35,7 +35,7 @@ impl<'a> ThermalManager<'a> { pub fn update_temperature(&mut self) { self.current_temp = commands::get_gpu_temp(); self.last_temp_time = Some(Instant::now()); - self.current_fan_speed = commands::get_fan_speed() as u64; + self.current_fan_speed = commands::get_fan_speed(); self.samples.push_back(self.current_temp); if self.samples.len() > self.config.sampling_window_size { self.samples.pop_front(); @@ -57,7 +57,7 @@ impl<'a> ThermalManager<'a> { // rearrange into descending order _temps .into_iter() - .zip(_speeds.into_iter()) + .zip(_speeds) .rev() .collect::>() }