From: Greg Burri Date: Tue, 30 Apr 2024 19:01:36 +0000 (+0200) Subject: Add a color (2 colors can be now defined for a machine). X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=62ba2376ce60a89fe33d917f2dcd24a61f876dc5;p=temp2RGB.git Add a color (2 colors can be now defined for a machine). --- diff --git a/src/machine.rs b/src/machine.rs index 1012c00..1d7bb2e 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -12,7 +12,12 @@ const RGB_FUSION2_GPU_REG_MODE: u8 = 0x88; const GIGABYTE_RTX3080TI_VISION_OC_ADDR: u8 = 0x63; pub trait Machine { - fn set_color(&mut self, color: &rgb::RGB); + fn set_color(&mut self, color: &rgb::RGB) { + self.set_color_1(&color); + self.set_color_2(&color); + } + fn set_color_1(&mut self, color: &rgb::RGB); + fn set_color_2(&mut self, color: &rgb::RGB); fn get_gpu_tmp(&self) -> f32; fn get_cpu_tmp(&self) -> f32; } @@ -42,16 +47,15 @@ impl MachineJiji { } impl Machine for MachineJiji { - fn set_color(&mut self, color: &rgb::RGB) { + fn set_color_1(&mut self, color: &rgb::RGB) { for controller in &self.ram { controller.set_color(&color); } - self.b650e_device.set_color(&color); - // if let Err(error) = self.a770.set_color(color.red, color.green, color.blue) { - // error!("Unable to set color: {:?}", error); - // } + self.b650e_device.set_color(&color).unwrap(); } + fn set_color_2(&mut self, color: &rgb::RGB) {} // No color 2. + fn get_gpu_tmp(&self) -> f32 { // unsafe { intel_arc::GetTemperature(self.gpu_devices, 0) as f32 } self.gpus[0].thermal_settings(None).unwrap()[0] @@ -160,13 +164,16 @@ impl MachineLyssMetal { } impl Machine for MachineLyssMetal { - fn set_color(&mut self, color: &rgb::RGB) { + fn set_color_1(&mut self, color: &rgb::RGB) { self.crosshair_device.set_color(&color).unwrap(); self.corsair_lignting_pro.set_color(&color); - self.lian_li_sl_infinity.set_color(&color); // self.set_color_3080ti(&color); // TODO. } + fn set_color_2(&mut self, color: &rgb::RGB) { + self.lian_li_sl_infinity.set_color(&color); + } + fn get_gpu_tmp(&self) -> f32 { self.gpus[0].thermal_settings(None).unwrap()[0] .current_temperature diff --git a/src/main.rs b/src/main.rs index 014c61d..a0443f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,6 +53,8 @@ mod settings; mod tests; mod timer; +// Important: when starting as a service, the directory where the log and config files +// are put is 'C:\Windows\System32\config\systemprofile\AppData\Roaming\Temp2RGB'. fn main() -> Result<()> { let is_debug = cfg!(debug_assertions); diff --git a/src/main_loop.rs b/src/main_loop.rs index bc2f6ee..a11c36b 100644 --- a/src/main_loop.rs +++ b/src/main_loop.rs @@ -20,7 +20,21 @@ pub fn main_loop(completed: Arc) { winring0::init(); let sleep = timer::Sleep::new(); - let settings = settings::Settings::read(consts::FILE_CONF).expect("Cannot load settings"); + + let file_conf_path = if cfg!(debug_assertions) { + String::from(consts::FILE_CONF) + } else { + String::from( + dirs::config_dir() + .unwrap() + .join(consts::SERVICE_NAME) + .join(consts::FILE_CONF) + .to_str() + .unwrap(), + ) + }; + + let settings = settings::Settings::read(&file_conf_path).expect("Cannot load settings"); println!("Settings: {settings:?}"); let mut machine: Box = match settings.machine_name { @@ -63,14 +77,28 @@ pub fn main_loop(completed: Arc) { 1f32, ); // Between 0 (cold) and 1 (hot). - let color = - rgb::linear_interpolation(settings.cold_color, settings.hot_color, normalized_temp); + let color_1 = + rgb::linear_interpolation(settings.cold_color_1, settings.hot_color_1, normalized_temp); + + let color_2 = match (settings.cold_color_2, settings.hot_color_2) { + (Some(cold_color), Some(hot_color)) => Some(rgb::linear_interpolation( + cold_color, + hot_color, + normalized_temp, + )), + _ => None, + }; // println!("normalized_temp: {normalized_temp}"); if tick % (consts::FREQ_TEMP_POLLING / consts::FREQ_REFRESHING_RGB) as i64 == 0 { - println!("Update RGB: {color:?}, temp: {mean_temp}"); - machine.set_color(&color); + println!("Update RGB: {color_1:?}/{color_2:?}, temp: {mean_temp}"); + machine.set_color_1(&color_1); + if color_2.is_some() { + machine.set_color_2(&color_2.unwrap()); + } else { + machine.set_color_2(&color_1); + } } let elapsed = time::Instant::now() - time_beginning_loop; diff --git a/src/rgb.rs b/src/rgb.rs index de1161a..a6217c7 100644 --- a/src/rgb.rs +++ b/src/rgb.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Copy, Clone, Debug, Deserialize, Serialize)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] pub struct RGB { pub red: u8, pub green: u8, diff --git a/src/settings.rs b/src/settings.rs index 9939178..511cb8c 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -17,8 +17,10 @@ pub enum MachineName { #[derive(Debug, Deserialize, Serialize)] pub struct Settings { pub machine_name: MachineName, - pub cold_color: RGB, - pub hot_color: RGB, + pub cold_color_1: RGB, + pub hot_color_1: RGB, + pub cold_color_2: Option, + pub hot_color_2: Option, // Average temperature between CPU and GPU. pub cold_temperature: f32, pub hot_temperature: f32, @@ -30,16 +32,18 @@ impl Settings { fn default() -> Self { Settings { machine_name: MachineName::Jiji, - cold_color: RGB { + cold_color_1: RGB { red: 0, green: 255, blue: 40, }, - hot_color: RGB { + hot_color_1: RGB { red: 255, green: 0, blue: 0, }, + cold_color_2: None, + hot_color_2: None, cold_temperature: 55., hot_temperature: 75., }