Display next departure, decrease station text size

This commit is contained in:
Ollo 2023-09-16 13:36:17 +02:00
parent 60139da2bf
commit 69191e77b3
2 changed files with 37 additions and 20 deletions

View File

@ -8,7 +8,7 @@ use tinybmp::Bmp;
use core::time; use core::time;
use embedded_graphics::{ use embedded_graphics::{
image::Image, image::Image,
mono_font::{iso_8859_1::FONT_6X10, MonoTextStyle}, mono_font::{iso_8859_1::FONT_6X10, iso_8859_1::FONT_5X8, MonoTextStyle},
pixelcolor::BinaryColor, pixelcolor::BinaryColor,
prelude::*, prelude::*,
primitives::PrimitiveStyle, primitives::PrimitiveStyle,
@ -242,12 +242,28 @@ fn send_package(ipaddress: String,
if strabaRes.failure == false { if strabaRes.failure == false {
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On); let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
let outbound = &format!("{}: {}min", strabaRes.outbound_station, (strabaRes.outbound_diff / 60)); let text_style_station = MonoTextStyle::new(&FONT_5X8, BinaryColor::On);
Text::new(outbound, Point::new(0, 15), text_style) let mut outbound = format!("+{}min", (strabaRes.outbound_diff / 60));
if (strabaRes.outbound_diff < 60) {
outbound = String::from("sofort");
}
Text::new(&strabaRes.outbound_station, Point::new(1, 15), text_style_station)
.draw(&mut display) .draw(&mut display)
.unwrap(); .unwrap();
let inbound = &format!("{}: {}min", strabaRes.inbound_station, (strabaRes.inbound_diff / 60)); Text::new(&outbound, Point::new(80, 15), text_style)
Text::new(inbound, Point::new(0, 30), text_style) .draw(&mut display)
.unwrap();
let mut inbound = format!("+{}min", (strabaRes.inbound_diff / 60));
if (strabaRes.inbound_diff < 60) {
inbound = String::from("sofort");
}
Text::new(&strabaRes.inbound_station, Point::new(1, 25), text_style_station)
.draw(&mut display)
.unwrap();
Text::new(&inbound, Point::new(80, 24), text_style)
.draw(&mut display) .draw(&mut display)
.unwrap(); .unwrap();
} }

View File

@ -74,6 +74,7 @@ pub struct IsoStringDateTime {
// Return value // Return value
pub struct NextDeparture { pub struct NextDeparture {
pub request_time: i64,
pub outbound_station: String, pub outbound_station: String,
pub outbound_diff: i64, pub outbound_diff: i64,
pub inbound_station: String, pub inbound_station: String,
@ -82,23 +83,21 @@ pub struct NextDeparture {
} }
pub fn fetch_data() -> NextDeparture { pub fn fetch_data() -> NextDeparture {
let mut returnValue = NextDeparture {
failure : false,
outbound_station : String::from(""),
outbound_diff : -10000,
inbound_station : String::from(""),
inbound_diff : -10000,
};
let st_now = SystemTime::now(); let st_now = SystemTime::now();
let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs(); let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs();
let url = &format!("{}?datetime={}", STATION_URL, seconds); let url = &format!("{}?datetime={}", STATION_URL, seconds);
let result = reqwest::blocking::get(url); let result = reqwest::blocking::get(url);
/*let cur_time = readTime( DateTime::<Utc>::default() );
println!("Next results after {:?}", cur_time);
return Some("Debug"); let mut returnValue = NextDeparture {
*/ failure : false,
outbound_station : String::from(""),
outbound_diff : 10000,
inbound_station : String::from(""),
inbound_diff : 10000,
request_time : seconds as i64,
};
println!("Start Straba Crawler"); println!("Start Straba Crawler");
if result.is_err() { if result.is_err() {
@ -130,20 +129,22 @@ pub fn fetch_data() -> NextDeparture {
for el in (json.graphQL.response.journeys.elements) { for el in (json.graphQL.response.journeys.elements) {
println!("Line {:}", el.line.lineGroup.label); println!("Line {:}", el.line.lineGroup.label);
for stop in el.stops { for stop in el.stops {
if stop.realtimeDeparture.isoString.is_some() { // use only valid data
if stop.realtimeDeparture.isoString.is_some() &&
stop.destinationLabel != "" {
let txt_departure = stop.realtimeDeparture.isoString.unwrap(); let txt_departure = stop.realtimeDeparture.isoString.unwrap();
let next_departure = DateTime::parse_from_rfc3339(&txt_departure).unwrap(); let next_departure = DateTime::parse_from_rfc3339(&txt_departure).unwrap();
let diff = next_departure.timestamp() - (seconds as i64); let diff = next_departure.timestamp() - (seconds as i64);
println!("To {:} {:}", stop.destinationLabel, txt_departure); println!("To {:} {:} (in {:} seconds)", stop.destinationLabel, txt_departure, diff );
if returnValue.outbound_station == "" { if returnValue.outbound_station == "" {
if stop.destinationLabel.contains("Rheinau") { if stop.destinationLabel.contains("Rheinau") && (diff < returnValue.outbound_diff) {
returnValue.outbound_station = stop.destinationLabel; returnValue.outbound_station = stop.destinationLabel;
returnValue.outbound_diff = diff; returnValue.outbound_diff = diff;
} else if stop.destinationLabel.contains("Hochschule") || } else if stop.destinationLabel.contains("Hochschule") ||
stop.destinationLabel.contains("Hauptbahnhof") || stop.destinationLabel.contains("Hauptbahnhof") ||
stop.destinationLabel.contains("nau") { // Schönau stop.destinationLabel.contains("nau") { // Schönau
if returnValue.inbound_station == "" { if returnValue.inbound_station == "" && (diff < returnValue.inbound_diff) {
returnValue.inbound_station = stop.destinationLabel; returnValue.inbound_station = stop.destinationLabel;
returnValue.inbound_diff = diff; returnValue.inbound_diff = diff;
} }