X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=src%2Fmachine.rs;h=ac60e7208f9ef5f083acd66b1942fc8d82ec2c00;hb=0c50e4418792d9f5b78ef1c96d66514058beec26;hp=6bb3bfc43fae06ce1a4d2432d413a44df6a24a3c;hpb=df85fed256d816770034fd4290cf2d3d22e43975;p=temp2RGB.git diff --git a/src/machine.rs b/src/machine.rs index 6bb3bfc..ac60e72 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1,4 +1,15 @@ -use crate::{a770, asus_aura_usb, corsair_vengeance, cpu_temperature, intel_arc, rgb}; +use log::error; +use nvapi::sys::i2c; + +use crate::{ + /*a770,*/ asus_aura_usb, corsair_lighting_pro, corsair_vengeance, cpu_temperature, + intel_arc, rgb, +}; + +const RGB_FUSION2_GPU_REG_COLOR: u8 = 0x40; +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); @@ -9,24 +20,24 @@ pub trait Machine { pub struct MachineJiji { ram: Vec, b650e_device: asus_aura_usb::Device, - a770: a770::A770, - gpu_devices: intel_arc::Devices, + // a770: a770::A770, + // gpu_devices: intel_arc::Devices, + gpus: Vec, } impl MachineJiji { - pub fn new() -> Self { + pub fn new() -> anyhow::Result { let api = hidapi::HidApi::new().unwrap(); - let machine = MachineJiji { + Ok(MachineJiji { ram: vec![ corsair_vengeance::Controller::new(0x19), corsair_vengeance::Controller::new(0x1B), ], - 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 + b650e_device: asus_aura_usb::Device::new(&api, asus_aura_usb::Motherboard::Asus650e)?, + // a770: a770::A770::new()?, + // gpu_devices: unsafe { intel_arc::GetDevices() }, + gpus: nvapi::PhysicalGpu::enumerate()?, + }) } } @@ -36,11 +47,16 @@ impl Machine for MachineJiji { controller.set_color(&color); } self.b650e_device.set_color(&color); - self.a770.set_color(color.red, color.green, color.blue); + // if let Err(error) = self.a770.set_color(color.red, color.green, color.blue) { + // error!("Unable to set color: {:?}", error); + // } } fn get_gpu_tmp(&self) -> f32 { - unsafe { intel_arc::GetTemperature(self.gpu_devices, 0) as f32 } + // unsafe { intel_arc::GetTemperature(self.gpu_devices, 0) as f32 } + self.gpus[0].thermal_settings(None).unwrap()[0] + .current_temperature + .0 as f32 } fn get_cpu_tmp(&self) -> f32 { @@ -48,12 +64,113 @@ impl Machine for MachineJiji { } } -impl Drop for MachineJiji { - fn drop(&mut self) { - unsafe { - intel_arc::FreeDevices(self.gpu_devices); - } +// impl Drop for MachineJiji { +// fn drop(&mut self) { +// unsafe { +// intel_arc::FreeDevices(self.gpu_devices); +// } +// } +// } + +pub struct MachineLyssMetal { + crosshair_device: asus_aura_usb::Device, + corsair_lignting_pro: corsair_lighting_pro::Device, + gpus: Vec, +} + +impl MachineLyssMetal { + pub fn new() -> anyhow::Result { + let api = hidapi::HidApi::new()?; + + nvapi::initialize().expect("Unable to initialize nvapi (Nvidia API)"); + + let machine = 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()?, + }; + + // machine.set_mode_3080ti(); + Ok(machine) + } + + // Doesn't work: "Error: NotSupported". + // From OpenRGB, see the following files: + // * Controllers\GigabyteRGBFusion2GPUController\GigabyteRGBFusion2GPUControllerDetect.cpp + // * Controllers\GigabyteRGBFusion2GPUController\RGBController_GigabyteRGBFusion2GPU.cpp + // * Controllers\GigabyteRGBFusion2GPUController\GigabyteRGBFusion2GPUController.cpp + // * i2c_smbus\i2c_smbus_nvapi.cpp + // Implementation of nvapi-rs: https://github.com/arcnmx/nvapi-rs/blob/master/src/gpu.rs#L645 + pub fn test_i2c(&self) { + // Test from 'GigabyteRGBFusion2GPUControllerDetect.cpp' + let data = [0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + self.gpus[0] + .i2c_write( + 0, + Some(1), + false, + GIGABYTE_RTX3080TI_VISION_OC_ADDR, + &[], + &data, + i2c::I2cSpeed::Default, + ) + .expect("Error"); + } + + fn set_mode_3080ti(&self) { + let data = [ + RGB_FUSION2_GPU_REG_MODE, + 0x01, // Mode (1: static). + 0x00, // Speed. + 0x63, // Brightness max. + 0x00, // Mistery flag. + 0x01, // Zone. + 0x00, + 0x00, + ]; + self.gpus[0] + .i2c_write( + 0, + Some(1), + false, + GIGABYTE_RTX3080TI_VISION_OC_ADDR, + &[], + &data, + i2c::I2cSpeed::Default, + ) + .expect("Error"); + } + + fn set_color_3080ti(&self, color: &rgb::RGB) { + // TODO. + self.test_i2c(); } } -struct MachineLyssMetal {} +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); + // self.set_color_3080ti(&color); // TODO. + } + + 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() + } +}