Remove A770 for MachineJiji
[temp2RGB.git] / src / machine.rs
1 use log::error;
2 use nvapi::sys::i2c;
3
4 use crate::{
5 /*a770,*/ asus_aura_usb, corsair_lighting_pro, corsair_vengeance, cpu_temperature,
6 intel_arc, rgb,
7 };
8
9 const RGB_FUSION2_GPU_REG_COLOR: u8 = 0x40;
10 const RGB_FUSION2_GPU_REG_MODE: u8 = 0x88;
11
12 const GIGABYTE_RTX3080TI_VISION_OC_ADDR: u8 = 0x63;
13
14 pub trait Machine {
15 fn set_color(&mut self, color: &rgb::RGB);
16 fn get_gpu_tmp(&self) -> f32;
17 fn get_cpu_tmp(&self) -> f32;
18 }
19
20 pub struct MachineJiji {
21 ram: Vec<corsair_vengeance::Controller>,
22 b650e_device: asus_aura_usb::Device,
23 // a770: a770::A770,
24 // gpu_devices: intel_arc::Devices,
25 gpus: Vec<nvapi::PhysicalGpu>,
26 }
27
28 impl MachineJiji {
29 pub fn new() -> anyhow::Result<Self> {
30 let api = hidapi::HidApi::new().unwrap();
31 Ok(MachineJiji {
32 ram: vec![
33 corsair_vengeance::Controller::new(0x19),
34 corsair_vengeance::Controller::new(0x1B),
35 ],
36 b650e_device: asus_aura_usb::Device::new(&api, asus_aura_usb::Motherboard::Asus650e)?,
37 // a770: a770::A770::new()?,
38 // gpu_devices: unsafe { intel_arc::GetDevices() },
39 gpus: nvapi::PhysicalGpu::enumerate()?,
40 })
41 }
42 }
43
44 impl Machine for MachineJiji {
45 fn set_color(&mut self, color: &rgb::RGB) {
46 for controller in &self.ram {
47 controller.set_color(&color);
48 }
49 self.b650e_device.set_color(&color);
50 // if let Err(error) = self.a770.set_color(color.red, color.green, color.blue) {
51 // error!("Unable to set color: {:?}", error);
52 // }
53 }
54
55 fn get_gpu_tmp(&self) -> f32 {
56 // unsafe { intel_arc::GetTemperature(self.gpu_devices, 0) as f32 }
57 self.gpus[0].thermal_settings(None).unwrap()[0]
58 .current_temperature
59 .0 as f32
60 }
61
62 fn get_cpu_tmp(&self) -> f32 {
63 cpu_temperature::read()
64 }
65 }
66
67 // impl Drop for MachineJiji {
68 // fn drop(&mut self) {
69 // unsafe {
70 // intel_arc::FreeDevices(self.gpu_devices);
71 // }
72 // }
73 // }
74
75 pub struct MachineLyssMetal {
76 crosshair_device: asus_aura_usb::Device,
77 corsair_lignting_pro: corsair_lighting_pro::Device,
78 gpus: Vec<nvapi::PhysicalGpu>,
79 }
80
81 impl MachineLyssMetal {
82 pub fn new() -> anyhow::Result<Self> {
83 let api = hidapi::HidApi::new()?;
84
85 nvapi::initialize().expect("Unable to initialize nvapi (Nvidia API)");
86
87 let machine = MachineLyssMetal {
88 crosshair_device: asus_aura_usb::Device::new(
89 &api,
90 asus_aura_usb::Motherboard::AsusCrosshairVIIIHero,
91 )?,
92 corsair_lignting_pro: corsair_lighting_pro::Device::new(
93 &api,
94 &rgb::RGB {
95 red: 0,
96 green: 255,
97 blue: 40,
98 },
99 ),
100 gpus: nvapi::PhysicalGpu::enumerate()?,
101 };
102
103 // machine.set_mode_3080ti();
104 Ok(machine)
105 }
106
107 // Doesn't work: "Error: NotSupported".
108 // From OpenRGB, see the following files:
109 // * Controllers\GigabyteRGBFusion2GPUController\GigabyteRGBFusion2GPUControllerDetect.cpp
110 // * Controllers\GigabyteRGBFusion2GPUController\RGBController_GigabyteRGBFusion2GPU.cpp
111 // * Controllers\GigabyteRGBFusion2GPUController\GigabyteRGBFusion2GPUController.cpp
112 // * i2c_smbus\i2c_smbus_nvapi.cpp
113 // Implementation of nvapi-rs: https://github.com/arcnmx/nvapi-rs/blob/master/src/gpu.rs#L645
114 pub fn test_i2c(&self) {
115 // Test from 'GigabyteRGBFusion2GPUControllerDetect.cpp'
116 let data = [0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
117 self.gpus[0]
118 .i2c_write(
119 0,
120 Some(1),
121 false,
122 GIGABYTE_RTX3080TI_VISION_OC_ADDR,
123 &[],
124 &data,
125 i2c::I2cSpeed::Default,
126 )
127 .expect("Error");
128 }
129
130 fn set_mode_3080ti(&self) {
131 let data = [
132 RGB_FUSION2_GPU_REG_MODE,
133 0x01, // Mode (1: static).
134 0x00, // Speed.
135 0x63, // Brightness max.
136 0x00, // Mistery flag.
137 0x01, // Zone.
138 0x00,
139 0x00,
140 ];
141 self.gpus[0]
142 .i2c_write(
143 0,
144 Some(1),
145 false,
146 GIGABYTE_RTX3080TI_VISION_OC_ADDR,
147 &[],
148 &data,
149 i2c::I2cSpeed::Default,
150 )
151 .expect("Error");
152 }
153
154 fn set_color_3080ti(&self, color: &rgb::RGB) {
155 // TODO.
156 self.test_i2c();
157 }
158 }
159
160 impl Machine for MachineLyssMetal {
161 fn set_color(&mut self, color: &rgb::RGB) {
162 self.crosshair_device.set_color(&color);
163 self.corsair_lignting_pro.set_color(&color);
164 // self.set_color_3080ti(&color); // TODO.
165 }
166
167 fn get_gpu_tmp(&self) -> f32 {
168 self.gpus[0].thermal_settings(None).unwrap()[0]
169 .current_temperature
170 .0 as f32
171 }
172
173 fn get_cpu_tmp(&self) -> f32 {
174 cpu_temperature::read()
175 }
176 }