-use crate::{a770, corsair_vengeance, rgb, sensors_jiji, winring0, AsusAuraUSB};
+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);
pub struct MachineJiji {
ram: Vec<corsair_vengeance::Controller>,
- b650e_device: AsusAuraUSB::Device,
+ b650e_device: asus_aura_usb::Device,
a770: a770::A770,
- sensors: sensors_jiji::Sensors,
+ gpu_devices: intel_arc::Devices,
}
impl MachineJiji {
- pub fn new() -> Self {
+ pub fn new() -> anyhow::Result<Self> {
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: AsusAuraUSB::Device::new(&api, AsusAuraUSB::Motherboard::Asus650e),
- a770: a770::A770::new(),
- sensors: sensors_jiji::Sensors::new(),
- };
- 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() },
+ })
}
}
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 {
- self.sensors.read_gpu_temp()
+ unsafe { intel_arc::GetTemperature(self.gpu_devices, 0) as f32 }
}
fn get_cpu_tmp(&self) -> f32 {
- self.sensors.read_cpu_temp()
+ 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<nvapi::PhysicalGpu>,
+}
+
+impl MachineLyssMetal {
+ pub fn new() -> anyhow::Result<Self> {
+ 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()
+ }
+}