Implement 'set_color' for corsair lighting pro
[temp2RGB.git] / src / tests.rs
1 use std::collections::HashMap;
2
3 use wmi::{COMLibrary, Variant, WMIConnection};
4
5 use crate::{
6 a770, asus_aura_usb, corsair_lighting_pro, corsair_vengeance, cpu_temperature, machine,
7 rgb::RGB, winring0, wrapper_winring0,
8 };
9
10 pub fn tests() {
11 println!("Running some tests...");
12
13 winring0::init();
14
15 test_asus_aura_usb(asus_aura_usb::Motherboard::AsusCrosshairVIIIHero);
16 // test_corsair_lighting_pro();
17 // list_usb_devices();
18 // test_roccat();
19 // test_wmi();
20 // test_corsair();
21 // test_a770();
22 // test_read_temperature_cpu();
23 // test_read_temperature_a770()
24 // test_read_temperature_3080();
25
26 winring0::deinit();
27
28 println!("Press any key to continue...");
29 std::io::stdin().read_line(&mut String::new()).unwrap();
30 }
31
32 fn test_wmi() {
33 let com_con = COMLibrary::new().unwrap();
34 let wmi_con = WMIConnection::new(com_con.into()).unwrap();
35
36 //let results: Vec<HashMap<String, Variant>> = wmi_con.raw_query("SELECT * FROM Win32_PnPSignedDriver WHERE Description LIKE '%SMBUS%' OR Description LIKE '%SM BUS%'").unwrap();
37 //let results: Vec<HashMap<String, Variant>> = wmi_con.raw_query("SELECT * FROM Win32_PnPSignedDriver WHERE Description LIKE 'Intel(R) NF I2C Host Controller'").unwrap();
38 let results: Vec<HashMap<String, Variant>> = wmi_con
39 .raw_query("SELECT * FROM Win32_PnPSignedDriver")
40 .unwrap();
41 //let results: Vec<HashMap<String, Variant>> = wmi_con.raw_query("SELECT * FROM Win32_PnPAllocatedResource").unwrap();
42
43 for os in results {
44 println!("-------------------");
45 println!("{:#?}", os);
46 }
47 }
48
49 fn list_usb_devices() {
50 let api = hidapi::HidApi::new().unwrap();
51 for device in api.device_list() {
52 println!("{:?}", device);
53 println!("name: {}", device.product_string().unwrap());
54 println!("interface number: {}", device.interface_number());
55 println!("page: {}", device.usage_page());
56 println!("usage: {}", device.usage());
57 println!("----");
58 }
59 }
60
61 // fn test_roccat() {
62 // let api = hidapi::HidApi::new().unwrap();
63 // let roccat_device = roccat::get_device(&api);
64
65 // let manufacturer = roccat_device.get_manufacturer_string().unwrap();
66 // dbg!(manufacturer);
67
68 // let product = roccat_device.get_product_string().unwrap();
69 // dbg!(product);
70
71 // let serial = roccat_device.get_serial_number_string().unwrap();
72 // dbg!(serial);
73
74 // roccat::init(&roccat_device);
75 // roccat::set_color(
76 // &roccat_device,
77 // &RGB {
78 // red: 0,
79 // green: 255,
80 // blue: 40,
81 // },
82 // );
83 // }
84
85 fn test_asus_aura_usb(motherboard: asus_aura_usb::Motherboard) {
86 let api = hidapi::HidApi::new().unwrap();
87
88 let device = asus_aura_usb::Device::new(&api, motherboard);
89
90 println!("Firmware: {}", device.get_firmware_string());
91
92 let configuration = device.get_configuration_table();
93 println!("Configuration:");
94 for i in 0..60 {
95 print!("{:02X} ", configuration[i]);
96 if (i + 1) % 6 == 0 {
97 println!("");
98 }
99 }
100 println!("Number of addressable header: {}", configuration[0x02]);
101 println!("Number of leds: {}", configuration[0x1B]);
102 println!("Number of RGB headers: {}", configuration[0x1D]);
103
104 device.set_color(&RGB {
105 red: 0,
106 green: 0,
107 blue: 255,
108 });
109
110 device.save_current_color();
111 }
112
113 fn test_corsair_lighting_pro() {
114 let api = hidapi::HidApi::new().unwrap();
115 let device = corsair_lighting_pro::Device::new(
116 &api,
117 &RGB {
118 red: 0,
119 green: 255,
120 blue: 0,
121 },
122 );
123
124 for i in 0..=255 {
125 if i % 10 == 0 || i == 255 || i == 0 {
126 device.set_color(&RGB {
127 red: i as u8,
128 green: 255u8 - i as u8,
129 blue: 0,
130 });
131 std::thread::sleep(std::time::Duration::from_millis(200));
132 }
133 }
134 }
135
136 fn test_corsair() {
137 let corsair_controllers = [
138 corsair_vengeance::Controller::new(0x19),
139 corsair_vengeance::Controller::new(0x1B),
140 ];
141
142 for controller in corsair_controllers {
143 controller.set_color(&RGB {
144 red: 0,
145 green: 0,
146 blue: 255,
147 });
148 }
149 }
150
151 fn test_a770() {
152 // a770::set_rgb(255, 0, 0);
153 let mut a770 = a770::A770::new();
154 a770.set_color(255, 0, 0);
155 }
156
157 const F17H_M01H_THM_TCON_CUR_TMP: u32 = 0x00059800;
158 const F17H_TEMP_OFFSET_FLAG: u32 = 0x80000;
159 const FAMILY_17H_PCI_CONTROL_REGISTER: u32 = 0x60;
160
161 fn test_read_temperature_cpu() {
162 println!("temp cpu: {}", cpu_temperature::read())
163 }
164
165 fn test_read_temperature_a770() {
166 let jiji: &dyn machine::Machine = &machine::MachineJiji::new();
167 println!("temp gpu: {}", jiji.get_gpu_tmp());
168 }
169
170 fn test_read_temperature_3080() {
171 nvapi::initialize().expect("Unable to initialize nvapi (Nvidia API)");
172 // if let Ok(gpus) = {
173 // for gpu in gpus {
174 // let thermal = gpu.thermal_settings(None).unwrap()[0];
175 // println!("{:?}", thermal.current_temperature.0)
176 // }
177 // }
178 let gpus = nvapi::PhysicalGpu::enumerate().unwrap();
179 let gpu = &gpus[0];
180 let sensor = gpu.thermal_settings(None).unwrap()[0];
181 println!("{:?}", sensor.current_temperature.0);
182 nvapi::unload().unwrap();
183 }