From 33c2878ed986e34855c804dbf9eae4e861c03118 Mon Sep 17 00:00:00 2001 From: zenonet Date: Fri, 12 Sep 2025 16:40:26 +0200 Subject: [PATCH] Made a minimal layout showing all subjects in one day --- Cargo.toml | 1 + src/main.rs | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 31afd6a..ca6fcec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ anyhow = "1.0.99" embedded-svc = "0.28.1" untis = {path = "../untis-test/untis-rs"} chrono = "0.4.41" +embedded-layout = "0.4.2" # --- Optional Embassy Integration --- # esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] } diff --git a/src/main.rs b/src/main.rs index 72fe2c5..c5ec5aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ use std::str::FromStr; use chrono::{Datelike, Days, NaiveTime}; use embedded_graphics::{ - mono_font::MonoTextStyleBuilder, - prelude::Point, + mono_font::{MonoTextStyle, MonoTextStyleBuilder}, + prelude::{Dimensions, Point}, text::{Baseline, Text, TextStyleBuilder}, Drawable, }; @@ -22,7 +22,11 @@ use esp_idf_svc::{ nvs::EspDefaultNvsPartition, wifi::Configuration, }; +use esp_idf_sys::time; use untis::{Date, Lesson}; +use embedded_layout::{layout::linear::LinearLayout, prelude::*}; + +type Timetable = [[Option;8]; 5]; fn main() -> anyhow::Result<()> { @@ -111,7 +115,8 @@ fn main() -> anyhow::Result<()> { let tt = fetch_timetable(httpconnection); - draw_text(&mut display, &tt[3][5].clone().unwrap().subjects.first().as_ref().unwrap().name, 5, 5); + draw_layout(&mut display, &tt); + //draw_text(&mut display, &tt[3][5].clone().unwrap().subjects.first().as_ref().unwrap().name, 5, 5); epd7in5.update_and_display_frame(&mut spi, &*display.buffer(), &mut delay)?; epd7in5.sleep(&mut spi, &mut delay)?; log::info!("Completed"); @@ -131,7 +136,34 @@ fn draw_text(display: &mut epd_waveshare::epd7in5_v2::Display7in5, text: &str, x let _ = Text::with_text_style(text, Point::new(x, y), style, text_style).draw(display); } -type Timetable = [[Option;8]; 5]; +fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable: &Timetable){ + let display_area = display.bounding_box(); + + let text_style = MonoTextStyle::new(&embedded_graphics::mono_font::ascii::FONT_6X9, Color::White); + + let empty_str = String::new(); + + let mut texts = timetable[0].iter().map(|l| { + if let Some(l) = l{ + Some(l.subjects.first().unwrap().name.as_str()) + }else{ + None + } + }).map(|s|{ + Text::new(s.unwrap_or_else(|| &empty_str), Point::zero(), text_style) + }).collect::>(); + + let vg = Views::new(&mut texts); + + LinearLayout::vertical(vg) + .with_alignment(horizontal::Center) + .arrange() + .align_to(&display_area, horizontal::Center, vertical::Center) + .draw(display) + .unwrap(); +} + + fn transform_lessons(lessons: Vec) -> Box{ let lookup: [NaiveTime; 8] = [