feat: print current temp and gamma
This commit is contained in:
parent
4f4f8fe26c
commit
42f3eb66d0
1 changed files with 37 additions and 2 deletions
39
src/main.rs
39
src/main.rs
|
@ -63,13 +63,48 @@ async fn socket_server(disabled: Arc<AtomicBool>, notify: Arc<Notify>) {
|
||||||
notify.notify_one();
|
notify.notify_one();
|
||||||
}
|
}
|
||||||
"status" => {
|
"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!(
|
println!(
|
||||||
"dimming is {}",
|
"dimming is {} — temp: {}K, gamma: {}%",
|
||||||
if disabled.load(Ordering::SeqCst) {
|
if disabled.load(Ordering::SeqCst) {
|
||||||
"disabled"
|
"disabled"
|
||||||
} else {
|
} else {
|
||||||
"enabled"
|
"enabled"
|
||||||
}
|
},
|
||||||
|
cur_temp,
|
||||||
|
cur_gamma
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => eprintln!("unknown command: {}", line.trim()),
|
_ => eprintln!("unknown command: {}", line.trim()),
|
||||||
|
|
Loading…
Reference in a new issue