From ca73b6545a9978c727f6ef81e4d793393b4e1d9e Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 4 Oct 2023 12:42:30 +0200 Subject: [PATCH] Fix main loop delay --- Cargo.lock | 26 +++++++++++++------------- Cargo.toml | 6 +++--- default.nix | 4 ++-- src/bin/main_loop.rs | 7 +++++-- src/lib.rs | 5 +++++ 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f7cf89..f61ae00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1011,9 +1011,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.3" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memmap2" @@ -1552,9 +1552,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.5" +version = "1.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" +checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" dependencies = [ "aho-corasick", "memchr", @@ -1564,9 +1564,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" +checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" dependencies = [ "aho-corasick", "memchr", @@ -1838,7 +1838,7 @@ dependencies = [ [[package]] name = "ssd1351" version = "0.3.0" -source = "git+https://github.com/FliegendeWurst/ssd1351-rust#9192fde637a2cc672e27ed1dc324f82e6bb65f72" +source = "git+https://github.com/FliegendeWurst/ssd1351-rust?rev=ce3194474355f4433ffe2a63484f263071a0d54e#ce3194474355f4433ffe2a63484f263071a0d54e" dependencies = [ "chrono", "display-interface", @@ -1898,18 +1898,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", @@ -2084,9 +2084,9 @@ dependencies = [ [[package]] name = "ureq" -version = "2.7.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b11c96ac7ee530603dcdf68ed1557050f374ce55a5a07193ebf8cbc9f8927e9" +checksum = "f5ccd538d4a604753ebc2f17cd9946e89b77bf87f6a8e2309667c6f2e87855e3" dependencies = [ "base64", "log", diff --git a/Cargo.toml b/Cargo.toml index 8db60f3..11484c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,12 +14,12 @@ libc = "0.2.98" rusqlite = "0.27.0" time = { version = "0.3.9", features = ["parsing"] } time-tz = "1.0.1" -image = "0.24.1" +image = { version = "0.24.1", optional = true } serde_json = "1.0.79" serde_derive = "1.0.136" serde = "1.0.136" rppal = { version = "0.13.1", features = ["hal"] } -ssd1351 = { git = "https://github.com/FliegendeWurst/ssd1351-rust" } +ssd1351 = { git = "https://github.com/FliegendeWurst/ssd1351-rust", rev = "ce3194474355f4433ffe2a63484f263071a0d54e" } display-interface-spi = "0.4.1" ureq = { version = "2.4.0", default-features = false } winit = { version = "0.28.7", optional = true } @@ -29,7 +29,7 @@ gpiocdev = "0.6.0" #gpio-am2302-rs = { git = "https://github.com/FliegendeWurst/gpio-am2302-rs" } [features] -pc = ["winit", "softbuffer"] +pc = ["winit", "softbuffer", "image"] default = [ "pc" ] [profile.release] diff --git a/default.nix b/default.nix index 30a41b2..2757dde 100644 --- a/default.nix +++ b/default.nix @@ -9,7 +9,7 @@ rustPlatform.buildRustPackage { cargoLock = { lockFile = ./Cargo.lock; outputHashes = { - "ssd1351-0.3.0" = "sha256-K6QCU9qPEuU7Ur8W6fTdi4JWk8NsVz3mLfV0afpfdBA="; + "ssd1351-0.3.0" = "sha256-D0gnYbZfSsG/K8BN5N8pmMGtGcqWt7/0gN3UXLRsOlc="; # "gpio-am2302-rs-1.1.0" = "sha256-tyA/R80LtWIXoVEoxHhkmzy0IsMdMH1Oi3FTQ56XjyQ="; }; }; @@ -25,7 +25,7 @@ rustPlatform.buildRustPackage { meta = with lib; { description = "OLED display of clock/calendar/temperature"; homepage = "https://github.com/FliegendeWurst/raspi-oled"; - license = licenses.mit; + license = licenses.gpl3; maintainers = with maintainers; [ fliegendewurst ]; }; } diff --git a/src/bin/main_loop.rs b/src/bin/main_loop.rs index 0a17181..3c12659 100644 --- a/src/bin/main_loop.rs +++ b/src/bin/main_loop.rs @@ -1,5 +1,6 @@ use std::{ cell::RefCell, + thread, time::{Duration, Instant}, }; @@ -8,7 +9,6 @@ use display_interface_spi::SPIInterfaceNoCS; use embedded_graphics::{pixelcolor::Rgb565, prelude::DrawTarget, Drawable}; use gpiocdev::line::{Bias, EdgeDetection, Value}; use rand_xoshiro::{rand_core::SeedableRng, Xoroshiro128StarStar}; -use raspi_oled::FrameOutput; use rppal::{ gpio::{Gpio, OutputPin}, hal::Delay, @@ -100,6 +100,7 @@ fn pc_main() { }; use crate::screensaver::{Screensaver, DUOLINGO}; + use raspi_oled::FrameOutput; let event_loop = EventLoop::new(); let window = WindowBuilder::new() @@ -317,6 +318,7 @@ fn main_loop(mut disp: Oled) { }, 6 => { menu.push(2); + ctx.do_action(Action::Screensaver("rpi")); }, 5 => { menu.push(3); @@ -325,7 +327,7 @@ fn main_loop(mut disp: Oled) { println!("unknown offset: {}", e.offset); }, } - println!("menu: {menu:?}"); + //println!("menu: {menu:?}"); } // clean up stale menu selection if !menu.is_empty() && Instant::now().duration_since(last_button).as_secs() >= 10 { @@ -336,5 +338,6 @@ fn main_loop(mut disp: Oled) { if dirty { let _ = disp.flush(); // ignore bus write errors, they are harmless } + thread::sleep(Duration::from_millis(1000)); } } diff --git a/src/lib.rs b/src/lib.rs index f30d441..6289c23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,12 +9,15 @@ use embedded_graphics::{ prelude::{OriginDimensions, RgbColor, Size}, }; use gpiocdev::line::{Bias, EdgeDetection, EdgeKind, Value}; +#[cfg(feature = "pc")] use image::{ImageBuffer, Rgb}; +#[cfg(feature = "pc")] pub struct FrameOutput { pub buffer: ImageBuffer, Vec>, } +#[cfg(feature = "pc")] impl FrameOutput { pub fn new(width: u32, height: u32) -> Self { FrameOutput { @@ -23,6 +26,7 @@ impl FrameOutput { } } +#[cfg(feature = "pc")] impl DrawTarget for FrameOutput { type Color = Rgb565; @@ -49,6 +53,7 @@ impl DrawTarget for FrameOutput { } } +#[cfg(feature = "pc")] impl OriginDimensions for FrameOutput { fn size(&self) -> Size { Size::new(self.buffer.width(), self.buffer.height())