Compare commits
10 Commits
122b6e58b3
...
47f5507f4f
Author | SHA1 | Date | |
---|---|---|---|
|
47f5507f4f | ||
|
6744004387 | ||
|
e42b08bcf3 | ||
|
5923bc830e | ||
|
b963abc80b | ||
|
e07413f594 | ||
|
870cd0ad0a | ||
|
04aab61ab7 | ||
|
46f7eb4f8a | ||
|
860815313b |
@ -1,8 +1,8 @@
|
||||
use std::{time::Duration, fmt::format};
|
||||
use str;
|
||||
use bit::BitIndex;
|
||||
use chrono_tz::Europe::Berlin;
|
||||
use chrono::{DateTime, NaiveDateTime, Utc, Timelike};
|
||||
use chrono::prelude::*;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use openweathermap::forecast::Weather;
|
||||
use substring::Substring;
|
||||
@ -10,7 +10,7 @@ use tinybmp::Bmp;
|
||||
use core::time;
|
||||
use embedded_graphics::{
|
||||
image::Image,
|
||||
mono_font::{iso_8859_1::FONT_6X10, iso_8859_1::FONT_5X8, MonoTextStyle},
|
||||
mono_font::{iso_8859_1::FONT_6X10, iso_8859_1::FONT_5X8, iso_8859_1::FONT_4X6, MonoTextStyle},
|
||||
pixelcolor::BinaryColor,
|
||||
prelude::*,
|
||||
text::Text,
|
||||
@ -19,6 +19,7 @@ use embedded_graphics::{
|
||||
use std::net::UdpSocket;
|
||||
use std::{env, thread};
|
||||
use std::io;
|
||||
use std::process::ExitCode;
|
||||
|
||||
use openweathermap::forecast::Forecast;
|
||||
use straba::NextDeparture;
|
||||
@ -242,6 +243,43 @@ fn render_clock(display: &mut UdpDisplay){
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn render_strab_partial(display: &mut UdpDisplay, station: &String, diff: i64, height: i32) {
|
||||
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
|
||||
let mut diff_str = format!("{}min", (diff / 60));
|
||||
if diff < 60 {
|
||||
diff_str = String::from("sofort");
|
||||
}
|
||||
let station_short: String;
|
||||
if str::len(&station) > 13 {
|
||||
station_short = station
|
||||
.replace("Straße", "Str")
|
||||
.replace("straße", "str")
|
||||
.replace("Platz", "Pl")
|
||||
.replace("platz", "pl")
|
||||
.replace("Hauptbahnhof", "Hbf")
|
||||
.replace("Bahnhof", "Bf");
|
||||
} else {
|
||||
station_short = station.to_string();
|
||||
}
|
||||
let station_clip: String;
|
||||
if str::len(&station_short) > 13 {
|
||||
station_clip = station_short[0..12].to_string();
|
||||
} else {
|
||||
station_clip = station_short.to_string();
|
||||
}
|
||||
Text::new(&station_clip, Point::new(1, height), text_style)
|
||||
.draw(display)
|
||||
.unwrap();
|
||||
Text::new(&diff_str, Point::new(80, height), text_style)
|
||||
.draw(display)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn render_strab(display: &mut UdpDisplay, straba_res: &NextDeparture) {
|
||||
render_strab_partial(display, &straba_res.outbound_station, straba_res.outbound_diff, 15);
|
||||
render_strab_partial(display, &straba_res.inbound_station, straba_res.inbound_diff, 25);
|
||||
}
|
||||
|
||||
fn send_package(ipaddress: String,
|
||||
data: &Option<Result<Forecast, String>>,
|
||||
straba_res: &NextDeparture) {
|
||||
@ -259,35 +297,9 @@ fn send_package(ipaddress: String,
|
||||
}
|
||||
|
||||
if straba_res.failure == false {
|
||||
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
|
||||
let text_style_station = MonoTextStyle::new(&FONT_5X8, BinaryColor::On);
|
||||
let mut outbound = format!("{}min", (straba_res.outbound_diff / 60));
|
||||
if straba_res.outbound_diff < 60 {
|
||||
outbound = String::from("sofort");
|
||||
}
|
||||
Text::new(&straba_res.outbound_station, Point::new(1, 15), text_style_station)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
Text::new(&outbound, Point::new(80, 15), text_style)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
let mut inbound = format!("{}min", (straba_res.inbound_diff / 60));
|
||||
if straba_res.inbound_diff < 60 {
|
||||
inbound = String::from("sofort");
|
||||
}
|
||||
|
||||
|
||||
Text::new(&straba_res.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)
|
||||
.unwrap();
|
||||
render_strab(&mut display, straba_res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
render_clock(&mut display);
|
||||
|
||||
|
||||
@ -336,14 +348,14 @@ fn check_connection(ipaddress: String) -> bool {
|
||||
return device_online;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main() -> ExitCode {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
match args.len() {
|
||||
// no arguments passed
|
||||
1 => {
|
||||
// show a help message
|
||||
help();
|
||||
return ExitCode::SUCCESS;
|
||||
}
|
||||
// one argument passed
|
||||
2 => {
|
||||
@ -353,7 +365,7 @@ fn main() {
|
||||
let mut device_online = check_connection(ip.to_string());
|
||||
if !device_online {
|
||||
println!("{} not online", ip);
|
||||
return
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
|
||||
let receiver = openweathermap::init_forecast("Mannheim",
|
||||
@ -389,7 +401,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
if (straba_res.request_time + 60) < seconds as i64 {
|
||||
if (straba_res.request_time + 50) < seconds as i64 {
|
||||
device_online = check_connection(ip.to_string());
|
||||
// request once a minute new data
|
||||
if device_online == true {
|
||||
@ -409,6 +421,7 @@ fn main() {
|
||||
_ => {
|
||||
// show a help message
|
||||
help();
|
||||
return ExitCode::SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ MainWindow::~MainWindow()
|
||||
}
|
||||
|
||||
void MainWindow::drawImage(QImage *target) {
|
||||
(void)target; /* handle unused variable ;-) */
|
||||
this->mScene=new QGraphicsScene() ;
|
||||
QGraphicsView *graphicsView = new QGraphicsView();
|
||||
graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||
|
Loading…
Reference in New Issue
Block a user