5c41bb9452f0fab780fc0c1c434db72ad71c551c
3 atomic
::{AtomicBool
, Ordering
},
6 time
::{self, Duration
},
9 use crate::{consts
, machine
, rgb
, settings
, timer
, winring0
};
11 pub fn main_loop(completed
: Arc
<AtomicBool
>) {
12 if consts
::FREQ_REFRESHING_RGB
> consts
::FREQ_TEMP_POLLING
{
13 panic!("Polling frequency must be greater or equal than RGB refresh frequency");
16 if consts
::FREQ_TEMP_POLLING
% consts
::FREQ_REFRESHING_RGB
!= 0 {
17 panic!("Polling frequency must be a multiple of RGB refresh frequency");
22 let sleep
= timer
::Sleep
::new();
23 let settings
= settings
::Settings
::read(consts
::FILE_CONF
).expect("Cannot load settings");
24 println!("Settings: {settings:?}");
26 let mut machine
: &mut dyn machine
::Machine
= &mut machine
::MachineJiji
::new();
28 let mut kernel
= [0f32; consts
::KERNEL_SIZE_SAMPLES
];
29 let mut current_pos
= 0usize
;
32 let period
= Duration
::from_micros(1_000_000u64 / consts
::FREQ_TEMP_POLLING
as u64);
35 if completed
.load(Ordering
::Relaxed
) {
38 let time_beginning_loop
= time
::Instant
::now();
40 let temp
= (machine
.get_cpu_tmp() + machine
.get_gpu_tmp()) / 2f32;
41 kernel
[current_pos
] = temp
;
42 current_pos
= (current_pos
+ 1) % consts
::KERNEL_SIZE_SAMPLES
;
48 s
/ kernel
.len() as f32
51 let normalized_temp
= num
::clamp(
52 (mean_temp
- settings
.cold_temperature
)
53 / (settings
.hot_temperature
- settings
.cold_temperature
),
56 ); // Between 0 (cold) and 1 (hot).
59 rgb
::linear_interpolation(settings
.cold_color
, settings
.hot_color
, normalized_temp
);
61 // println!("normalized_temp: {normalized_temp}");
63 if tick
% (consts
::FREQ_TEMP_POLLING
/ consts
::FREQ_REFRESHING_RGB
) as i64 == 0 {
64 println!("Update RGB: {color:?}, temp: {mean_temp}");
65 machine
.set_color(&color
);
68 let elapsed
= time
::Instant
::now() - time_beginning_loop
;
70 let to_wait
= period
- elapsed
;
76 // println!("Press any key to continue...");
77 // std::io::stdin().read_line(&mut String::new()).unwrap();
80 winring0
::DeinitializeOls();
86 let ols_ok
= winring0
::InitializeOls() != 0;
88 panic!("Unable to initalize WingRing0");
90 let dll_status
= winring0
::GetDllStatus();
92 panic!("WingRing0 DLL status error: {}", dll_status
);