From 933ac7f9bfa7572ad8ee4ec153bfa9d819f5e1b4 Mon Sep 17 00:00:00 2001 From: Felix Suchert Date: Mon, 29 May 2023 15:02:00 +0200 Subject: [PATCH] Get simulator to work, adjust Pi version --- src/bin/inky.rs | 15 ++++++++------- src/bin/simulator.rs | 13 ++++++++++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/bin/inky.rs b/src/bin/inky.rs index 2ecacf6..78d6090 100644 --- a/src/bin/inky.rs +++ b/src/bin/inky.rs @@ -88,21 +88,22 @@ fn main() -> Result<(), std::io::Error> { let display = Display::new(controller, config); let mut display = GraphicDisplay::new(display, &mut black_buffer, &mut red_buffer); - // Main loop. Displays CPU temperature, uname, and uptime every minute with a red Raspberry Pi - // header. + let mut state = ApplicationState::default(); + let one_minute = Duration::from_secs(60); + + // Main loop. updates the screen after a fixed time interval with the next screen loop { display.reset(&mut delay).expect("error resetting display"); - println!("Reset and initialised"); - let one_minute = Duration::from_secs(60); - display.clear(Color::White); - println!("Clear"); - inky_ticker::populate(&mut display); + inky_ticker::populate(&mut display, &mut state); display.update(&mut delay).expect("error updating display"); println!("Update..."); + // select next screen already + state.advance_screen(); + println!("Finished - going to sleep"); display.deep_sleep()?; diff --git a/src/bin/simulator.rs b/src/bin/simulator.rs index 4334038..adc0a53 100644 --- a/src/bin/simulator.rs +++ b/src/bin/simulator.rs @@ -1,5 +1,5 @@ use embedded_graphics::prelude::*; -use embedded_graphics_simulator::{OutputSettings, SimulatorDisplay, Window}; +use embedded_graphics_simulator::{OutputSettings, SimulatorDisplay, SimulatorEvent, Window}; use ssd1675::Color; use inky_ticker::ApplicationState; @@ -13,9 +13,10 @@ fn main() -> Result<(), core::convert::Infallible> { let mut state = ApplicationState::default(); // switch between states every few minutes - let minute = std::time::Duration::from_secs(60); + let minute = std::time::Duration::from_secs(20); + println!("Screen will alter every {} seconds", minute.as_secs()); - loop { + 'running: loop { display.clear(Color::White).expect("failed to clear screen"); println!("Populating screen"); @@ -29,6 +30,12 @@ fn main() -> Result<(), core::convert::Infallible> { println!("Going to sleep"); state.advance_screen(); + + if window.events().any(|e| e == SimulatorEvent::Quit) { + break 'running; + } std::thread::sleep(minute); } + + Ok(()) }