From 42f3eb66d0968696c2d5c03eb91367554e1b4db3 Mon Sep 17 00:00:00 2001 From: Vladimir Rubin Date: Wed, 23 Apr 2025 22:12:33 +0300 Subject: [PATCH] feat: print current temp and gamma --- src/main.rs | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index af1e74b..d7e3a80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,13 +63,48 @@ async fn socket_server(disabled: Arc, notify: Arc) { notify.notify_one(); } "status" => { + // compute current temp/gamma + let now = Local::now(); + let time_in_hours = now.hour() as f64 + now.minute() as f64 / 60.0; + + let (cur_temp, cur_gamma) = if (time_in_hours >= SUNSET_START as f64) + && (time_in_hours <= SUNSET_END as f64) + { + let factor = ((time_in_hours - SUNSET_START as f64) + / (SUNSET_END - SUNSET_START) as f64) + .clamp(0.0, 1.0); + ( + interpolate(TEMP_DAY, TEMP_NIGHT, factor), + interpolate(GAMMA_DAY, GAMMA_NIGHT, factor), + ) + } else if (time_in_hours >= SUNRISE_START as f64) + && (time_in_hours <= SUNRISE_END as f64) + { + let factor = 1.0 + - ((time_in_hours - SUNRISE_START as f64) + / (SUNRISE_END - SUNRISE_START) as f64) + .clamp(0.0, 1.0); + ( + interpolate(TEMP_DAY, TEMP_NIGHT, factor), + interpolate(GAMMA_DAY, GAMMA_NIGHT, factor), + ) + } else if time_in_hours > SUNSET_END as f64 + || time_in_hours < SUNRISE_START as f64 + { + (TEMP_NIGHT, GAMMA_NIGHT) + } else { + (TEMP_DAY, GAMMA_DAY) + }; + println!( - "dimming is {}", + "dimming is {} — temp: {}K, gamma: {}%", if disabled.load(Ordering::SeqCst) { "disabled" } else { "enabled" - } + }, + cur_temp, + cur_gamma ); } _ => eprintln!("unknown command: {}", line.trim()),