Implement 'set_color' for corsair lighting pro
[temp2RGB.git] / src / machine.rs
index 6bb3bfc..9436f49 100644 (file)
@@ -1,4 +1,6 @@
-use crate::{a770, asus_aura_usb, corsair_vengeance, cpu_temperature, intel_arc, rgb};
+use crate::{
+    a770, asus_aura_usb, corsair_lighting_pro, corsair_vengeance, cpu_temperature, intel_arc, rgb,
+};
 
 pub trait Machine {
     fn set_color(&mut self, color: &rgb::RGB);
@@ -16,7 +18,7 @@ pub struct MachineJiji {
 impl MachineJiji {
     pub fn new() -> Self {
         let api = hidapi::HidApi::new().unwrap();
-        let machine = MachineJiji {
+        MachineJiji {
             ram: vec![
                 corsair_vengeance::Controller::new(0x19),
                 corsair_vengeance::Controller::new(0x1B),
@@ -24,9 +26,7 @@ impl MachineJiji {
             b650e_device: asus_aura_usb::Device::new(&api, asus_aura_usb::Motherboard::Asus650e),
             a770: a770::A770::new(),
             gpu_devices: unsafe { intel_arc::GetDevices() },
-        };
-        machine.b650e_device.set_fixed_mode();
-        machine
+        }
     }
 }
 
@@ -56,4 +56,49 @@ impl Drop for MachineJiji {
     }
 }
 
-struct MachineLyssMetal {}
+pub struct MachineLyssMetal {
+    crosshair_device: asus_aura_usb::Device,
+    corsair_lignting_pro: corsair_lighting_pro::Device,
+    gpus: Vec<nvapi::PhysicalGpu>,
+}
+
+impl MachineLyssMetal {
+    pub fn new() -> Self {
+        let api = hidapi::HidApi::new().unwrap();
+
+        nvapi::initialize().expect("Unable to initialize nvapi (Nvidia API)");
+
+        MachineLyssMetal {
+            crosshair_device: asus_aura_usb::Device::new(
+                &api,
+                asus_aura_usb::Motherboard::AsusCrosshairVIIIHero,
+            ),
+            corsair_lignting_pro: corsair_lighting_pro::Device::new(
+                &api,
+                &rgb::RGB {
+                    red: 0,
+                    green: 255,
+                    blue: 40,
+                },
+            ),
+            gpus: nvapi::PhysicalGpu::enumerate().unwrap(),
+        }
+    }
+}
+
+impl Machine for MachineLyssMetal {
+    fn set_color(&mut self, color: &rgb::RGB) {
+        self.crosshair_device.set_color(&color);
+        self.corsair_lignting_pro.set_color(&color);
+    }
+
+    fn get_gpu_tmp(&self) -> f32 {
+        self.gpus[0].thermal_settings(None).unwrap()[0]
+            .current_temperature
+            .0 as f32
+    }
+
+    fn get_cpu_tmp(&self) -> f32 {
+        cpu_temperature::read()
+    }
+}