5e57005adc210f0e034c41dc149d80f768fbadf4
[temp2RGB.git] / src / sensors_jiji.rs
1 use crate::{intel_arc, winring0};
2
3 const OLS_TYPE: u32 = 40000;
4
5 const F17H_M01H_THM_TCON_CUR_TMP: u32 = 0x00059800;
6 const F17H_TEMP_OFFSET_FLAG: u32 = 0x80000;
7 const FAMILY_17H_PCI_CONTROL_REGISTER: u32 = 0x60;
8
9 pub struct Sensors {
10 gpu_devices: intel_arc::Devices,
11 }
12
13 impl Sensors {
14 pub fn new() -> Self {
15 unsafe {
16 Sensors {
17 gpu_devices: intel_arc::GetDevices(),
18 }
19 }
20 }
21
22 pub fn read_cpu_temp(&self) -> f32 {
23 unsafe {
24 winring0::WritePciConfigDwordEx(
25 0x00,
26 FAMILY_17H_PCI_CONTROL_REGISTER,
27 F17H_M01H_THM_TCON_CUR_TMP,
28 );
29
30 let output: &mut u32 = &mut 0;
31 let ok =
32 winring0::ReadPciConfigDwordEx(0x00, FAMILY_17H_PCI_CONTROL_REGISTER + 4, output);
33 let offset_flag = *output & F17H_TEMP_OFFSET_FLAG != 0;
34 let mut temperature = ((*output >> 21) * 125) as f32 * 0.001;
35 if offset_flag {
36 temperature -= 49.;
37 }
38
39 // dbg!(ok);
40 // dbg!(temperature);
41
42 temperature
43 }
44 }
45
46 pub fn read_gpu_temp(&self) -> f32 {
47 unsafe { intel_arc::GetTemperature(self.gpu_devices, 0) as f32 }
48 }
49 }
50
51 impl Drop for Sensors {
52 fn drop(&mut self) {
53 unsafe {
54 intel_arc::FreeDevices(self.gpu_devices);
55 }
56 }
57 }