feat: print current temp and gamma

This commit is contained in:
Vladimir Rubin 2025-04-23 22:12:33 +03:00
parent 4f4f8fe26c
commit 42f3eb66d0
Signed by: vavakado
GPG key ID: CAB744727F36B524

View file

@ -63,13 +63,48 @@ async fn socket_server(disabled: Arc<AtomicBool>, notify: Arc<Notify>) {
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()),