diff --git a/src/main.rs b/src/main.rs index 3f0a720..136b6ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::num::NonZeroU16; use std::{borrow::Cow}; use std::str::FromStr; @@ -10,7 +9,6 @@ use embedded_graphics::{ text::{Text}, Drawable, }; -use embedded_layout::layout::linear::ElementSpacing; use epd_waveshare::{color::Color, epd7in5_v2::Epd7in5, prelude::WaveshareDisplay}; use esp_idf_hal::modem::Modem; use esp_idf_hal::{ @@ -26,7 +24,7 @@ use esp_idf_svc::{ nvs::EspDefaultNvsPartition, wifi::Configuration, }; -use esp_idf_sys::{esp_deep_sleep, StaticSemaphore_t}; +use esp_idf_sys::esp_deep_sleep; use u8g2_fonts::U8g2TextStyle; use untis::{Date, Lesson, LessonCode}; use embedded_layout::{layout::linear::{spacing::DistributeFill, FixedMargin, LinearLayout}, prelude::*}; @@ -163,6 +161,10 @@ fn main() -> anyhow::Result<()> { println!("Failed to fetch timetable for the {}th time. Error: {}", fail_count, e); + if fail_count > 10{ + panic!("10 failed attempts. Last error:\n{}\nBacktrace:\n{}", e, e.backtrace()); + } + // Quadratic falloff maxing out at 1 hours intervals let sleep_time = u32::min((fail_count as u32).pow(2u32) * 4, 3600); println!("Going to sleep for {} seconds", sleep_time); @@ -182,7 +184,7 @@ fn main() -> anyhow::Result<()> { let next_wakeup_time = calculate_next_wakeuptime(now).context(format!("Failed to calculate next wakeup time for time {now}")).unwrap(); // Render the layout - draw_layout(&mut display, &tt, now, next_wakeup_time); + draw_layout(&mut display, &tt, now, next_wakeup_time, include_str!("../wifi-creds.txt").split('\n').next().unwrap()); // Actually push changes to the display let mut epd7in5 = Epd7in5::new(&mut spi, busy, dc, rst, &mut delay, None).unwrap(); @@ -296,7 +298,7 @@ fn is_lesson_cancelled(l: &Lesson) -> bool{ l.code == LessonCode::Cancelled || l.subst_text.as_ref().is_some_and(|s| s == "Aufgaben") } -fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable: &Timetable, now: DateTime, next_wakeup_time: DateTime){ +fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable: &Timetable, now: DateTime, next_wakeup_time: DateTime, wifi_details: &str){ let display_area = display.bounding_box(); // let text_style = MonoTextStyle::new(&embedded_graphics::mono_font::ascii::FONT_10X20, Color::White); @@ -366,9 +368,17 @@ fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable: .with_spacing(FixedMargin(18)) .arrange(); - let subtext = LinearLayout::vertical(Chain::new(time_text).append(Text::new(&next_wakeup_time_str, Point::zero(), &text_style_small))).with_alignment(horizontal::Center).with_spacing(FixedMargin(2)).arrange(); + let subtext = LinearLayout::vertical(Chain::new(time_text).append(Text::new(&next_wakeup_time_str, Point::zero(), &text_style_small))).with_alignment(horizontal::Right).with_spacing(FixedMargin(2)).arrange(); - LinearLayout::vertical(Chain::new(time_table_grid).append(subtext)) + let bottom_bar = LinearLayout::horizontal(Chain::new( + Text::new(wifi_details, Point::zero(), &text_style_small) + ).append( + subtext + ) + ).with_alignment(vertical::Bottom) + .with_spacing(DistributeFill(display_area.size.width)) + .arrange(); + LinearLayout::vertical(Chain::new(time_table_grid).append(bottom_bar)) .with_alignment(horizontal::Center) .with_spacing(DistributeFill(display_area.size.height-10)) .arrange()