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()),