Implement 'set_color' for corsair lighting pro
[temp2RGB.git] / src / machine.rs
1 use crate::{
2 a770, asus_aura_usb, corsair_lighting_pro, corsair_vengeance, cpu_temperature, intel_arc, rgb,
3 };
4
5 pub trait Machine {
6 fn set_color(&mut self, color: &rgb::RGB);
7 fn get_gpu_tmp(&self) -> f32;
8 fn get_cpu_tmp(&self) -> f32;
9 }
10
11 pub struct MachineJiji {
12 ram: Vec<corsair_vengeance::Controller>,
13 b650e_device: asus_aura_usb::Device,
14 a770: a770::A770,
15 gpu_devices: intel_arc::Devices,
16 }
17
18 impl MachineJiji {
19 pub fn new() -> Self {
20 let api = hidapi::HidApi::new().unwrap();
21 MachineJiji {
22 ram: vec![
23 corsair_vengeance::Controller::new(0x19),
24 corsair_vengeance::Controller::new(0x1B),
25 ],
26 b650e_device: asus_aura_usb::Device::new(&api, asus_aura_usb::Motherboard::Asus650e),
27 a770: a770::A770::new(),
28 gpu_devices: unsafe { intel_arc::GetDevices() },
29 }
30 }
31 }
32
33 impl Machine for MachineJiji {
34 fn set_color(&mut self, color: &rgb::RGB) {
35 for controller in &self.ram {
36 controller.set_color(&color);
37 }
38 self.b650e_device.set_color(&color);
39 self.a770.set_color(color.red, color.green, color.blue);
40 }
41
42 fn get_gpu_tmp(&self) -> f32 {
43 unsafe { intel_arc::GetTemperature(self.gpu_devices, 0) as f32 }
44 }
45
46 fn get_cpu_tmp(&self) -> f32 {
47 cpu_temperature::read()
48 }
49 }
50
51 impl Drop for MachineJiji {
52 fn drop(&mut self) {
53 unsafe {
54 intel_arc::FreeDevices(self.gpu_devices);
55 }
56 }
57 }
58
59 pub struct MachineLyssMetal {
60 crosshair_device: asus_aura_usb::Device,
61 corsair_lignting_pro: corsair_lighting_pro::Device,
62 gpus: Vec<nvapi::PhysicalGpu>,
63 }
64
65 impl MachineLyssMetal {
66 pub fn new() -> Self {
67 let api = hidapi::HidApi::new().unwrap();
68
69 nvapi::initialize().expect("Unable to initialize nvapi (Nvidia API)");
70
71 MachineLyssMetal {
72 crosshair_device: asus_aura_usb::Device::new(
73 &api,
74 asus_aura_usb::Motherboard::AsusCrosshairVIIIHero,
75 ),
76 corsair_lignting_pro: corsair_lighting_pro::Device::new(
77 &api,
78 &rgb::RGB {
79 red: 0,
80 green: 255,
81 blue: 40,
82 },
83 ),
84 gpus: nvapi::PhysicalGpu::enumerate().unwrap(),
85 }
86 }
87 }
88
89 impl Machine for MachineLyssMetal {
90 fn set_color(&mut self, color: &rgb::RGB) {
91 self.crosshair_device.set_color(&color);
92 self.corsair_lignting_pro.set_color(&color);
93 }
94
95 fn get_gpu_tmp(&self) -> f32 {
96 self.gpus[0].thermal_settings(None).unwrap()[0]
97 .current_temperature
98 .0 as f32
99 }
100
101 fn get_cpu_tmp(&self) -> f32 {
102 cpu_temperature::read()
103 }
104 }