Switch display to black between 23h30 and 7h30
This commit is contained in:
parent
39aa6d7986
commit
87cbbdf30f
@ -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" }
|
||||
|
||||
30
src/main.rs
30
src/main.rs
@ -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::Displayed
|
||||
} else {
|
||||
Mode::Black
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user