Switch display to black between 23h30 and 7h30
This commit is contained in:
parent
39aa6d7986
commit
eb08a883f9
@ -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" }
|
||||
|
||||
31
src/main.rs
31
src/main.rs
@ -31,12 +31,18 @@ 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())?;
|
||||
show_mouse(false);
|
||||
let screen_dim = Dimensions::new(screen_width() as u32, screen_height() as u32);
|
||||
let mut provider = ImageProvider::new(screen_dim, &settings.photo_path);
|
||||
let mode = Mode::Displayed;
|
||||
provider.load_next_image()?;
|
||||
let mut time = Instant::now();
|
||||
|
||||
@ -45,12 +51,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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user