From fb9fb3f161e875c0ff5d6fbfe86d5fc40c37a363 Mon Sep 17 00:00:00 2001 From: Ilya Zlobintsev Date: Thu, 12 Nov 2020 14:30:08 +0200 Subject: [PATCH] Updated GUI for multi-GPU support --- daemon/src/hw_mon.rs | 9 ++++----- gui/src/main.rs | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/daemon/src/hw_mon.rs b/daemon/src/hw_mon.rs index 456460e..cd4a51d 100644 --- a/daemon/src/hw_mon.rs +++ b/daemon/src/hw_mon.rs @@ -68,11 +68,10 @@ impl HWMon { .parse::() .unwrap() }*/ - fs::read_to_string(self.hwmon_path.join("fan1_input")) - .expect("Couldn't read fan speed") - .trim() - .parse::() - .unwrap() + match fs::read_to_string(self.hwmon_path.join("fan1_input")) { + Ok(a) => a.trim().parse::().unwrap(), + _ => 0, + } } pub fn get_mem_freq(&self) -> i32 { diff --git a/gui/src/main.rs b/gui/src/main.rs index 699b9eb..7062044 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -9,7 +9,7 @@ use gtk::{Adjustment, Button, ButtonsType, ComboBoxText, DialogFlags, Frame, Lab use gtk::{Builder, MessageDialog, TextBuffer, Window}; use pango::EllipsizeMode; -use std::{collections::BTreeMap, env::args, sync::{Arc, Mutex, RwLock}, thread, time::Duration}; +use std::{collections::BTreeMap, env::args, sync::{Arc, RwLock}, thread, time::Duration}; fn build_ui(application: >k::Application) { let glade_src = include_str!("main_window.glade"); @@ -86,25 +86,54 @@ fn build_ui(application: >k::Application) { cell.set_property("ellipsize", &EllipsizeMode::End).unwrap(); } - let current_gpu_id = Arc::new(Mutex::new(0u32)); + let current_gpu_id = Arc::new(RwLock::new(0u32)); let cur_id = current_gpu_id.clone(); let build = builder.clone(); + + let fan_curv_frm = fan_curve_frame.clone(); + let auto_fan_ctrl_swtch = automatic_fan_control_switch.clone(); + let b = apply_button.clone(); + gpu_select_comboboxtext.connect_changed(move |combobox| { - let mut current_gpu_id = cur_id.lock().unwrap(); + let mut current_gpu_id = cur_id.write().unwrap(); *current_gpu_id = combobox.get_active_id().unwrap().parse::().expect("invalid id"); println!("Set current gpu id to {}", current_gpu_id); let gpu_info = d.get_gpu_info(*current_gpu_id).unwrap(); set_info(&build, &gpu_info); + + let fan_control = d.get_fan_control(*current_gpu_id); + + match fan_control { + Ok(ref fan_control) => { + if fan_control.enabled { + println!("Automatic fan control disabled!"); + auto_fan_ctrl_swtch.set_active(false); + fan_curv_frm.set_visible(true); + } else { + println!("Automatic fan control enabled"); + auto_fan_ctrl_swtch.set_active(true); + fan_curv_frm.set_visible(false); + } + }, + Err(_) => { + auto_fan_ctrl_swtch.set_sensitive(false); + auto_fan_ctrl_swtch.set_tooltip_text(Some("Unavailable")); + + fan_curv_frm.set_visible(false); + } + } + + b.set_sensitive(false); + }); //gpu_select_comboboxtext.set_active_id(Some(¤t_gpu_id.to_string())); gpu_select_comboboxtext.set_active(Some(0)); - let current_gpu_id = *current_gpu_id.clone().lock().unwrap(); if unpriviliged { automatic_fan_control_switch.set_sensitive(false); @@ -114,7 +143,9 @@ fn build_ui(application: >k::Application) { let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); + let cur_gpu_id = current_gpu_id.clone(); thread::spawn(move || loop { + let current_gpu_id = *cur_gpu_id.clone().read().unwrap(); println!("Getting stats for {}", current_gpu_id); let gpu_stats = d.get_gpu_stats(current_gpu_id).unwrap(); @@ -146,7 +177,7 @@ fn build_ui(application: >k::Application) { glib::Continue(true) }); - let fan_control = d.get_fan_control(current_gpu_id); + let fan_control = d.get_fan_control(*current_gpu_id.read().unwrap()); match fan_control { Ok(ref fan_control) => { @@ -212,6 +243,8 @@ fn build_ui(application: >k::Application) { } apply_button.connect_clicked(move |b| { + let current_gpu_id = *current_gpu_id.read().unwrap(); + let curve = curve.read().unwrap().clone(); println!("setting curve to {:?}", curve); d.set_fan_curve(current_gpu_id, curve).unwrap();