Made timetable display full names of subjects and changed layout
This commit is contained in:
50
src/main.rs
50
src/main.rs
@@ -1,9 +1,10 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use chrono::{DateTime, Datelike, Days, FixedOffset, NaiveTime, TimeDelta, Timelike, Weekday};
|
use chrono::{DateTime, Datelike, Days, FixedOffset, NaiveTime, TimeDelta, Weekday};
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
prelude::{Dimensions, Point},
|
prelude::{Dimensions, Point},
|
||||||
text::{Text},
|
text::{Text},
|
||||||
@@ -24,9 +25,9 @@ use esp_idf_svc::{
|
|||||||
nvs::EspDefaultNvsPartition,
|
nvs::EspDefaultNvsPartition,
|
||||||
wifi::Configuration,
|
wifi::Configuration,
|
||||||
};
|
};
|
||||||
use esp_idf_sys::esp_deep_sleep;
|
use esp_idf_sys::{esp_deep_sleep, StaticSemaphore_t};
|
||||||
use u8g2_fonts::U8g2TextStyle;
|
use u8g2_fonts::U8g2TextStyle;
|
||||||
use untis::{Date, Lesson};
|
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::*};
|
||||||
|
|
||||||
type Timetable = [[Option<Lesson>;8]; 5];
|
type Timetable = [[Option<Lesson>;8]; 5];
|
||||||
@@ -124,8 +125,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let error_message = String::from_utf8_lossy(&error);
|
let error_message = String::from_utf8_lossy(&error);
|
||||||
let error_message = match &error_message{
|
let error_message = match &error_message{
|
||||||
Cow::Borrowed(c) => *c,
|
Cow::Borrowed(C) => *C,
|
||||||
Cow::Owned(c) => &c
|
Cow::Owned(C) => &C
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
@@ -150,7 +151,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
let fail_count: u16 = unsafe {
|
let fail_count: u16 = unsafe {
|
||||||
let new_val = match FETCHING_FAIL_COUNT{
|
let new_val = match FETCHING_FAIL_COUNT{
|
||||||
Some(c) => c.saturating_add(1),
|
Some(C) => C.saturating_add(1),
|
||||||
None => {
|
None => {
|
||||||
NonZeroU16::new_unchecked(1)
|
NonZeroU16::new_unchecked(1)
|
||||||
}
|
}
|
||||||
@@ -198,6 +199,29 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn get_full_subject_name(shortname: &str) -> Option<&'static str>{
|
||||||
|
if shortname.len() < 2{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let shortname = shortname.to_lowercase();
|
||||||
|
Some(match shortname[..2].as_ref() {
|
||||||
|
"in" => "Informatik",
|
||||||
|
"en" => "Englisch",
|
||||||
|
"de" => "Deutsch",
|
||||||
|
"ds" => "Theater",
|
||||||
|
"ph" => "Physik",
|
||||||
|
"ma" => "Mathematik",
|
||||||
|
"ch" => "Chemie",
|
||||||
|
"ge" => "Geschichte",
|
||||||
|
"sp" => "Sport",
|
||||||
|
_ => {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn calculate_next_wakeuptime(now: DateTime<FixedOffset>) -> Option<DateTime<FixedOffset>>{
|
fn calculate_next_wakeuptime(now: DateTime<FixedOffset>) -> Option<DateTime<FixedOffset>>{
|
||||||
|
|
||||||
if now.weekday().num_days_from_monday() > 4 || (now.weekday() == Weekday::Fri && now.time() > NaiveTime::from_hms_opt(15, 15, 0)?){
|
if now.weekday().num_days_from_monday() > 4 || (now.weekday() == Weekday::Fri && now.time() > NaiveTime::from_hms_opt(15, 15, 0)?){
|
||||||
@@ -270,11 +294,13 @@ fn fetch_data(modem: Modem) -> anyhow::Result<(Box<Timetable>, DateTime<FixedOff
|
|||||||
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>){
|
||||||
let display_area = display.bounding_box();
|
let display_area = display.bounding_box();
|
||||||
|
|
||||||
let margin = FixedMargin(10);
|
let margin = FixedMargin(15);
|
||||||
// let text_style = MonoTextStyle::new(&embedded_graphics::mono_font::ascii::FONT_10X20, Color::White);
|
|
||||||
let text_style = U8g2TextStyle::new(u8g2_fonts::fonts::u8g2_font_inr21_mf, Color::White);
|
|
||||||
|
|
||||||
let mut inverted_text_style = U8g2TextStyle::new(u8g2_fonts::fonts::u8g2_font_inr21_mf, Color::Black);
|
|
||||||
|
// let text_style = MonoTextStyle::new(&embedded_graphics::mono_font::ascii::FONT_10X20, Color::White);
|
||||||
|
let text_style = U8g2TextStyle::new(u8g2_fonts::fonts::u8g2_font_profont22_mr, Color::White);
|
||||||
|
|
||||||
|
let mut inverted_text_style = U8g2TextStyle::new(u8g2_fonts::fonts::u8g2_font_profont22_mr, Color::Black);
|
||||||
inverted_text_style.background_color = Some(Color::White);
|
inverted_text_style.background_color = Some(Color::White);
|
||||||
|
|
||||||
let text_style_small = U8g2TextStyle::new(u8g2_fonts::fonts::u8g2_font_7x14_mr, Color::White);
|
let text_style_small = U8g2TextStyle::new(u8g2_fonts::fonts::u8g2_font_7x14_mr, Color::White);
|
||||||
@@ -290,13 +316,13 @@ fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable:
|
|||||||
Some(l.subjects.first().unwrap().name.as_str())
|
Some(l.subjects.first().unwrap().name.as_str())
|
||||||
}else{
|
}else{
|
||||||
None
|
None
|
||||||
};
|
}.and_then(get_full_subject_name);
|
||||||
let text_style = if period as u8 == current_period && day_index as u32 == day_of_week{
|
let text_style = if period as u8 == current_period && day_index as u32 == day_of_week{
|
||||||
&inverted_text_style
|
&inverted_text_style
|
||||||
}else{
|
}else{
|
||||||
&text_style
|
&text_style
|
||||||
};
|
};
|
||||||
|
//LinearLayout::horizontal(Chain::new(Text::new()))
|
||||||
Text::new(s.unwrap_or_else(|| &empty_str), Point::zero(), text_style)
|
Text::new(s.unwrap_or_else(|| &empty_str), Point::zero(), text_style)
|
||||||
}).collect::<Vec<_>>()).collect::<Vec<_>>();
|
}).collect::<Vec<_>>()).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user