Move tests in a separate module
[temp2RGB.git] / src / tests.rs
1 use std::collections::HashMap;
2
3 use wmi::{COMLibrary, Variant, WMIConnection};
4
5 use crate::{a770, corsair_vengeance, rgb::RGB, sensors_jiji, AsusAuraUSB};
6
7 pub fn tests() {
8 println!("Running some tests...");
9
10 test_asus_aura_usb(AsusAuraUSB::Motherboard::AsusCrosshairVIIIHero);
11 // list_usb_devices();
12 // test_roccat();
13 // test_wmi();
14 // test_corsair();
15 // test_a770();
16 // test_read_temp();
17
18 println!("Press any key to continue...");
19 std::io::stdin().read_line(&mut String::new()).unwrap();
20 }
21
22 fn test_wmi() {
23 let com_con = COMLibrary::new().unwrap();
24 let wmi_con = WMIConnection::new(com_con.into()).unwrap();
25
26 //let results: Vec<HashMap<String, Variant>> = wmi_con.raw_query("SELECT * FROM Win32_PnPSignedDriver WHERE Description LIKE '%SMBUS%' OR Description LIKE '%SM BUS%'").unwrap();
27 //let results: Vec<HashMap<String, Variant>> = wmi_con.raw_query("SELECT * FROM Win32_PnPSignedDriver WHERE Description LIKE 'Intel(R) NF I2C Host Controller'").unwrap();
28 let results: Vec<HashMap<String, Variant>> = wmi_con
29 .raw_query("SELECT * FROM Win32_PnPSignedDriver")
30 .unwrap();
31 //let results: Vec<HashMap<String, Variant>> = wmi_con.raw_query("SELECT * FROM Win32_PnPAllocatedResource").unwrap();
32
33 for os in results {
34 println!("-------------------");
35 println!("{:#?}", os);
36 }
37 }
38
39 fn list_usb_devices() {
40 let api = hidapi::HidApi::new().unwrap();
41 for device in api.device_list() {
42 println!("{:?}", device);
43 println!("name: {}", device.product_string().unwrap());
44 println!("interface number: {}", device.interface_number());
45 println!("page: {}", device.usage_page());
46 println!("usage: {}", device.usage());
47 println!("----");
48 }
49 }
50
51 // fn test_roccat() {
52 // let api = hidapi::HidApi::new().unwrap();
53 // let roccat_device = roccat::get_device(&api);
54
55 // let manufacturer = roccat_device.get_manufacturer_string().unwrap();
56 // dbg!(manufacturer);
57
58 // let product = roccat_device.get_product_string().unwrap();
59 // dbg!(product);
60
61 // let serial = roccat_device.get_serial_number_string().unwrap();
62 // dbg!(serial);
63
64 // roccat::init(&roccat_device);
65 // roccat::set_color(
66 // &roccat_device,
67 // &RGB {
68 // red: 0,
69 // green: 255,
70 // blue: 40,
71 // },
72 // );
73 // }
74
75 fn test_asus_aura_usb(motherboard: AsusAuraUSB::Motherboard) {
76 let api = hidapi::HidApi::new().unwrap();
77
78 let device = AsusAuraUSB::Device::new(&api, motherboard);
79
80 println!("Firmware: {}", device.get_firmware_string());
81
82 let configuration = device.get_configuration_table();
83 println!("Configuration:");
84 for i in 0..60 {
85 print!("{:02X} ", configuration[i]);
86 if (i + 1) % 6 == 0 {
87 println!("");
88 }
89 }
90 println!("Number of addressable header: {}", configuration[0x02]);
91 println!("Number of leds: {}", configuration[0x1B]);
92 println!("Number of RGB headers: {}", configuration[0x1D]);
93
94 // Only once, at start.
95 device.set_fixed_mode();
96
97 device.set_color(&RGB {
98 red: 0,
99 green: 0,
100 blue: 255,
101 });
102
103 device.save_current_color();
104 }
105
106 fn test_corsair() {
107 let corsair_controllers = [
108 corsair_vengeance::Controller::new(0x19),
109 corsair_vengeance::Controller::new(0x1B),
110 ];
111 for controller in corsair_controllers {
112 controller.set_color(&RGB {
113 red: 0,
114 green: 0,
115 blue: 255,
116 });
117 }
118 }
119
120 fn test_a770() {
121 // a770::set_rgb(255, 0, 0);
122 let mut a770 = a770::A770::new();
123 a770.set_color(255, 0, 0);
124 }
125
126 fn test_read_temp() {
127 let sensors = sensors_jiji::Sensors::new();
128 println!("temp cpu: {}", sensors.read_cpu_temp());
129 println!("temp gpu: {}", sensors.read_gpu_temp());
130 }