From c73ba50cafb67c5d7ae09b323966b7e0dcaa2e97 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 3 Oct 2023 15:43:23 +0200 Subject: [PATCH] Hook up two more buttons --- src/bin/main_loop.rs | 27 ++++++++++++++++++--------- src/lib.rs | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/bin/main_loop.rs b/src/bin/main_loop.rs index 0314e68..0bd7ea2 100644 --- a/src/bin/main_loop.rs +++ b/src/bin/main_loop.rs @@ -1,5 +1,4 @@ use std::{ - fmt::Debug, thread::sleep_ms, time::{Duration, Instant}, }; @@ -12,19 +11,23 @@ use embedded_graphics::{ text::Text, Drawable, }; -use gpiocdev::line::{Bias, EdgeDetection}; +use gpiocdev::line::{Bias, EdgeDetection, Value}; use raspi_oled::FrameOutput; use rppal::{ - gpio::Gpio, + gpio::{Gpio, OutputPin}, hal::Delay, spi::{Bus, Mode, SlaveSelect, Spi}, }; +use ssd1351::display::display::Ssd1351; use time::OffsetDateTime; use time_tz::{timezones::db::europe::BERLIN, OffsetDateTimeExt}; static STAR: &'static [u8] = include_bytes!("../star.raw"); static RPI: &'static [u8] = include_bytes!("../rpi.raw"); +static BLACK: Rgb565 = Rgb565::new(0, 0, 0); +static TIME_COLOR: Rgb565 = Rgb565::new(0b01_111, 0b011_111, 0b01_111); + fn main() { if rppal::system::DeviceInfo::new().is_ok() { rpi_main(); @@ -208,7 +211,7 @@ fn rpi_main() { // Init SPI let spii = SPIInterfaceNoCS::new(spi, dc); - let mut disp = ssd1351::display::display::Ssd1351::new(spii); + let mut disp = Ssd1351::new(spii); // Reset & init disp.reset(&mut rst, &mut Delay).unwrap(); @@ -217,14 +220,18 @@ fn rpi_main() { main_loop(disp); } -fn main_loop>(mut disp: D) -where - D::Error: Debug, -{ +fn main_loop(mut disp: Ssd1351>) { + disp.clear(BLACK).unwrap(); let mut last_min = 0xff; let mut last_button = Instant::now(); let mut menu = vec![]; + let _high_outputs = gpiocdev::Request::builder() + .on_chip("/dev/gpiochip0") + .with_lines(&[23, 24]) + .as_output(Value::Active) + .request() + .unwrap(); let lines = gpiocdev::Request::builder() .on_chip("/dev/gpiochip0") .with_line(19) @@ -261,6 +268,7 @@ where println!("unknown offset: {}", e.offset); }, } + println!("menu: {menu:?}"); } // clean up stale menu selection if !menu.is_empty() && Instant::now().duration_since(last_button).as_secs() >= 10 { @@ -275,6 +283,7 @@ where if let Err(e) = loop_iter(&mut disp) { println!("error: {:?}", e); } + let _ = disp.flush(); // ignore bus write errors, they are harmless } } @@ -287,7 +296,7 @@ fn loop_iter>(disp: &mut D) -> Result<(), D::Error fn display_clock>(disp: &mut D, time: &OffsetDateTime) -> Result<(), D::Error> { let text_style_clock = MonoTextStyleBuilder::new() .font(&FONT_10X20) - .text_color(Rgb565::new(0xff, 0xff, 0xff)) + .text_color(TIME_COLOR) .build(); let hour = time.hour(); let minute = time.minute(); diff --git a/src/lib.rs b/src/lib.rs index 531adb3..f30d441 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -161,7 +161,7 @@ impl From for SensorError { } pub fn am2302_reading() -> Result<(u16, u16), SensorError> { - let mut out = gpiocdev::Request::builder() + let out = gpiocdev::Request::builder() .on_chip("/dev/gpiochip0") .with_line(26) .as_output(Value::Active)