Switch display to black between 23h30 and 7h30

This commit is contained in:
Jean-Loup Beaussart 2025-03-23 00:45:40 +01:00
parent 39aa6d7986
commit 14d83d8dfd
No known key found for this signature in database
GPG Key ID: 582B3C35EAFE46F8
2 changed files with 27 additions and 4 deletions

View File

@ -43,6 +43,7 @@ lto = "thin"
[dependencies]
anyhow = "1.0.97"
chrono = "0.4.40"
config = "0.15.11"
image = "0.25.5"
macroquad = { version = "0.4.14" }

View File

@ -31,6 +31,11 @@ fn display_image_centered(texture: &Texture2D) {
);
}
enum Mode {
Black,
Displayed,
}
#[macroquad::main(window_conf)]
async fn main() -> anyhow::Result<()> {
let settings = settings::Settings::new("settings.yml".into())?;
@ -45,12 +50,29 @@ async fn main() -> anyhow::Result<()> {
break;
}
display_frame(&provider)?;
let now = chrono::Local::now().time();
let midnight = chrono::NaiveTime::from_hms_opt(23, 30, 0).unwrap();
let seven_am = chrono::NaiveTime::from_hms_opt(7, 30, 0).unwrap();
if time.elapsed() > settings.duration {
provider.load_next_image()?;
time = Instant::now();
let mode = if now >= midnight && now < seven_am {
Mode::Black
} else {
Mode::Displayed
};
match mode {
Mode::Black => {
clear_background(BLACK);
}
Mode::Displayed => {
display_frame(&provider)?;
if time.elapsed() > settings.duration {
provider.load_next_image()?;
time = Instant::now();
}
}
}
thread::sleep(Duration::from_millis(250));
next_frame().await;
}