X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=src%2Fmain_loop.rs;h=a11c36b6f608b77762dd66a3d5fa2dccd86d5445;hb=HEAD;hp=6e7dd7483b367b4bcb784839e94845707e82a6fc;hpb=bec02443ba73a7d138fb1a16684995ceb8bfc065;p=temp2RGB.git diff --git a/src/main_loop.rs b/src/main_loop.rs index 6e7dd74..a11c36b 100644 --- a/src/main_loop.rs +++ b/src/main_loop.rs @@ -17,13 +17,34 @@ pub fn main_loop(completed: Arc) { panic!("Polling frequency must be a multiple of RGB refresh frequency"); } - init_winring0(); + winring0::init(); let sleep = timer::Sleep::new(); - let settings = settings::Settings::read(consts::FILE_CONF).expect("Cannot load settings"); + + let file_conf_path = if cfg!(debug_assertions) { + String::from(consts::FILE_CONF) + } else { + String::from( + dirs::config_dir() + .unwrap() + .join(consts::SERVICE_NAME) + .join(consts::FILE_CONF) + .to_str() + .unwrap(), + ) + }; + + let settings = settings::Settings::read(&file_conf_path).expect("Cannot load settings"); println!("Settings: {settings:?}"); - let machine: &mut dyn machine::Machine = &mut machine::MachineJiji::new(); + let mut machine: Box = match settings.machine_name { + settings::MachineName::Jiji => { + Box::new(machine::MachineJiji::new().expect("Unable to create MachineJiji")) + } + settings::MachineName::LyssMetal => { + Box::new(machine::MachineLyssMetal::new().expect("Unable to create MachineLyssMetal")) + } + }; let mut kernel = [0f32; consts::KERNEL_SIZE_SAMPLES]; let mut current_pos = 0usize; @@ -56,14 +77,28 @@ pub fn main_loop(completed: Arc) { 1f32, ); // Between 0 (cold) and 1 (hot). - let color = - rgb::linear_interpolation(settings.cold_color, settings.hot_color, normalized_temp); + let color_1 = + rgb::linear_interpolation(settings.cold_color_1, settings.hot_color_1, normalized_temp); + + let color_2 = match (settings.cold_color_2, settings.hot_color_2) { + (Some(cold_color), Some(hot_color)) => Some(rgb::linear_interpolation( + cold_color, + hot_color, + normalized_temp, + )), + _ => None, + }; // println!("normalized_temp: {normalized_temp}"); if tick % (consts::FREQ_TEMP_POLLING / consts::FREQ_REFRESHING_RGB) as i64 == 0 { - println!("Update RGB: {color:?}, temp: {mean_temp}"); - machine.set_color(&color); + println!("Update RGB: {color_1:?}/{color_2:?}, temp: {mean_temp}"); + machine.set_color_1(&color_1); + if color_2.is_some() { + machine.set_color_2(&color_2.unwrap()); + } else { + machine.set_color_2(&color_1); + } } let elapsed = time::Instant::now() - time_beginning_loop; @@ -77,20 +112,5 @@ pub fn main_loop(completed: Arc) { // println!("Press any key to continue..."); // std::io::stdin().read_line(&mut String::new()).unwrap(); - unsafe { - winring0::DeinitializeOls(); - } -} - -fn init_winring0() { - unsafe { - let ols_ok = winring0::InitializeOls() != 0; - if !ols_ok { - panic!("Unable to initalize WingRing0"); - } - let dll_status = winring0::GetDllStatus(); - if dll_status != 0 { - panic!("WingRing0 DLL status error: {}", dll_status); - } - } + winring0::deinit(); }