Added wifi info to display and made display show error after 10 soft error

This commit is contained in:
zenonet
2025-10-13 16:20:04 +02:00
parent 582c62b865
commit b61fd153ca

View File

@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::num::NonZeroU16; use std::num::NonZeroU16;
use std::{borrow::Cow}; use std::{borrow::Cow};
use std::str::FromStr; use std::str::FromStr;
@@ -10,7 +9,6 @@ use embedded_graphics::{
text::{Text}, text::{Text},
Drawable, Drawable,
}; };
use embedded_layout::layout::linear::ElementSpacing;
use epd_waveshare::{color::Color, epd7in5_v2::Epd7in5, prelude::WaveshareDisplay}; use epd_waveshare::{color::Color, epd7in5_v2::Epd7in5, prelude::WaveshareDisplay};
use esp_idf_hal::modem::Modem; use esp_idf_hal::modem::Modem;
use esp_idf_hal::{ use esp_idf_hal::{
@@ -26,7 +24,7 @@ use esp_idf_svc::{
nvs::EspDefaultNvsPartition, nvs::EspDefaultNvsPartition,
wifi::Configuration, wifi::Configuration,
}; };
use esp_idf_sys::{esp_deep_sleep, StaticSemaphore_t}; use esp_idf_sys::esp_deep_sleep;
use u8g2_fonts::U8g2TextStyle; use u8g2_fonts::U8g2TextStyle;
use untis::{Date, Lesson, LessonCode}; use untis::{Date, Lesson, LessonCode};
use embedded_layout::{layout::linear::{spacing::DistributeFill, FixedMargin, LinearLayout}, prelude::*}; 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); 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 // Quadratic falloff maxing out at 1 hours intervals
let sleep_time = u32::min((fail_count as u32).pow(2u32) * 4, 3600); let sleep_time = u32::min((fail_count as u32).pow(2u32) * 4, 3600);
println!("Going to sleep for {} seconds", sleep_time); 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(); let next_wakeup_time = calculate_next_wakeuptime(now).context(format!("Failed to calculate next wakeup time for time {now}")).unwrap();
// Render the layout // 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 // Actually push changes to the display
let mut epd7in5 = Epd7in5::new(&mut spi, busy, dc, rst, &mut delay, None).unwrap(); 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") 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<FixedOffset>, next_wakeup_time: DateTime<FixedOffset>){ fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable: &Timetable, now: DateTime<FixedOffset>, next_wakeup_time: DateTime<FixedOffset>, wifi_details: &str){
let display_area = display.bounding_box(); let display_area = display.bounding_box();
// let text_style = MonoTextStyle::new(&embedded_graphics::mono_font::ascii::FONT_10X20, Color::White); // 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)) .with_spacing(FixedMargin(18))
.arrange(); .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_alignment(horizontal::Center)
.with_spacing(DistributeFill(display_area.size.height-10)) .with_spacing(DistributeFill(display_area.size.height-10))
.arrange() .arrange()