Add a color (2 colors can be now defined for a machine). master
authorGreg Burri <greg.burri@gmail.com>
Tue, 30 Apr 2024 19:01:36 +0000 (21:01 +0200)
committerGreg Burri <greg.burri@gmail.com>
Tue, 30 Apr 2024 19:01:36 +0000 (21:01 +0200)
src/machine.rs
src/main.rs
src/main_loop.rs
src/rgb.rs
src/settings.rs

index 1012c00..1d7bb2e 100644 (file)
@@ -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
index 014c61d..a0443f7 100644 (file)
@@ -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);
 
index bc2f6ee..a11c36b 100644 (file)
@@ -20,7 +20,21 @@ pub fn main_loop(completed: Arc<AtomicBool>) {
     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<dyn machine::Machine> = match settings.machine_name {
@@ -63,14 +77,28 @@ pub fn main_loop(completed: Arc<AtomicBool>) {
             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;
index de1161a..a6217c7 100644 (file)
@@ -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,
index 9939178..511cb8c 100644 (file)
@@ -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<RGB>,
+    pub hot_color_2: Option<RGB>,
     // 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.,
         }