Compare commits

..

No commits in common. "47f5507f4f33189ff2254cfc8b9b5cf7f574e329" and "122b6e58b391fdc8a8f7f02450604cd5d2239391" have entirely different histories.

2 changed files with 33 additions and 47 deletions

View File

@ -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, iso_8859_1::FONT_4X6, MonoTextStyle},
mono_font::{iso_8859_1::FONT_6X10, iso_8859_1::FONT_5X8, MonoTextStyle},
pixelcolor::BinaryColor,
prelude::*,
text::Text,
@ -19,7 +19,6 @@ 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;
@ -243,43 +242,6 @@ 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) {
@ -297,9 +259,35 @@ fn send_package(ipaddress: String,
}
if straba_res.failure == false {
render_strab(&mut display, straba_res);
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_clock(&mut display);
@ -348,14 +336,14 @@ fn check_connection(ipaddress: String) -> bool {
return device_online;
}
fn main() -> ExitCode {
fn main() {
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 => {
@ -365,7 +353,7 @@ fn main() -> ExitCode {
let mut device_online = check_connection(ip.to_string());
if !device_online {
println!("{} not online", ip);
return ExitCode::FAILURE;
return
}
let receiver = openweathermap::init_forecast("Mannheim",
@ -401,7 +389,7 @@ fn main() -> ExitCode {
}
}
if (straba_res.request_time + 50) < seconds as i64 {
if (straba_res.request_time + 60) < seconds as i64 {
device_online = check_connection(ip.to_string());
// request once a minute new data
if device_online == true {
@ -421,7 +409,6 @@ fn main() -> ExitCode {
_ => {
// show a help message
help();
return ExitCode::SUCCESS;
}
}
}

View File

@ -22,7 +22,6 @@ 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);