X-Git-Url: https://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=src%2Fmachine.rs;h=1d7bb2e0a08184f656066b659ce453141d760c4f;hb=HEAD;hp=ac60e7208f9ef5f083acd66b1942fc8d82ec2c00;hpb=0c50e4418792d9f5b78ef1c96d66514058beec26;p=temp2RGB.git diff --git a/src/machine.rs b/src/machine.rs deleted file mode 100644 index ac60e72..0000000 --- a/src/machine.rs +++ /dev/null @@ -1,176 +0,0 @@ -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); - fn get_gpu_tmp(&self) -> f32; - fn get_cpu_tmp(&self) -> f32; -} - -pub struct MachineJiji { - ram: Vec, - b650e_device: asus_aura_usb::Device, - // a770: a770::A770, - // gpu_devices: intel_arc::Devices, - gpus: Vec, -} - -impl MachineJiji { - pub fn new() -> anyhow::Result { - let api = hidapi::HidApi::new().unwrap(); - 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() }, - gpus: nvapi::PhysicalGpu::enumerate()?, - }) - } -} - -impl Machine for MachineJiji { - fn set_color(&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); - // } - } - - fn get_gpu_tmp(&self) -> 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 { - cpu_temperature::read() - } -} - -// 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(); - } -} - -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() - } -}