Made a minimal layout showing all subjects in one day
This commit is contained in:
@@ -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"] }
|
||||
|
||||
40
src/main.rs
40
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<Lesson>;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<Lesson>;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::<Vec<_>>();
|
||||
|
||||
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<Lesson>) -> Box<Timetable>{
|
||||
let lookup: [NaiveTime; 8] = [
|
||||
|
||||
Reference in New Issue
Block a user