Compare commits

...

10 Commits

Author SHA1 Message Date
empirephoenix
47f5507f4f
Merge pull request #3 from lysogeny/master
Fix kerning issues in station names by increasing font size and shortening strings where necessary.
2023-10-13 20:08:04 +02:00
empirephoenix
6744004387
Merge branch 'master' into master 2023-10-13 20:07:28 +02:00
Ollo
e42b08bcf3 Update StraBa every 50 seconds 2023-10-04 20:43:08 +02:00
Ollo
5923bc830e Added returncode for main function 2023-10-04 20:41:29 +02:00
Ada
b963abc80b Merge branch 'master' of https://github.com/C3MA/LED-Board 2023-09-28 22:09:43 +02:00
Ada
e07413f594 Fix kerning issues by changing font. Shorten names when necessary. 2023-09-28 22:08:54 +02:00
empirephoenix
870cd0ad0a
Merge pull request #2 from lysogeny/master
Fix misaligned text elements in second line
2023-09-26 22:08:06 +02:00
Ada
04aab61ab7 Shift weather back to original location 2023-09-24 23:03:02 +02:00
Ada
46f7eb4f8a Fix misaligned text elements in second line 2023-09-24 22:29:24 +02:00
Ollo
860815313b Handle unused variable 2023-09-23 15:42:18 +02:00
2 changed files with 47 additions and 33 deletions

View File

@ -1,8 +1,8 @@
use std::{time::Duration, fmt::format}; use std::{time::Duration, fmt::format};
use str;
use bit::BitIndex; use bit::BitIndex;
use chrono_tz::Europe::Berlin; use chrono_tz::Europe::Berlin;
use chrono::{DateTime, NaiveDateTime, Utc, Timelike}; use chrono::{DateTime, NaiveDateTime, Utc, Timelike};
use chrono::prelude::*;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use openweathermap::forecast::Weather; use openweathermap::forecast::Weather;
use substring::Substring; use substring::Substring;
@ -10,7 +10,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, 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, pixelcolor::BinaryColor,
prelude::*, prelude::*,
text::Text, text::Text,
@ -19,6 +19,7 @@ use embedded_graphics::{
use std::net::UdpSocket; use std::net::UdpSocket;
use std::{env, thread}; use std::{env, thread};
use std::io; use std::io;
use std::process::ExitCode;
use openweathermap::forecast::Forecast; use openweathermap::forecast::Forecast;
use straba::NextDeparture; use straba::NextDeparture;
@ -242,6 +243,43 @@ fn render_clock(display: &mut UdpDisplay){
.unwrap(); .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, fn send_package(ipaddress: String,
data: &Option<Result<Forecast, String>>, data: &Option<Result<Forecast, String>>,
straba_res: &NextDeparture) { straba_res: &NextDeparture) {
@ -259,35 +297,9 @@ fn send_package(ipaddress: String,
} }
if straba_res.failure == false { if straba_res.failure == false {
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On); render_strab(&mut display, straba_res);
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); render_clock(&mut display);
@ -336,14 +348,14 @@ fn check_connection(ipaddress: String) -> bool {
return device_online; return device_online;
} }
fn main() { fn main() -> ExitCode {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
match args.len() { match args.len() {
// no arguments passed // no arguments passed
1 => { 1 => {
// show a help message // show a help message
help(); help();
return ExitCode::SUCCESS;
} }
// one argument passed // one argument passed
2 => { 2 => {
@ -353,7 +365,7 @@ fn main() {
let mut device_online = check_connection(ip.to_string()); let mut device_online = check_connection(ip.to_string());
if !device_online { if !device_online {
println!("{} not online", ip); println!("{} not online", ip);
return return ExitCode::FAILURE;
} }
let receiver = openweathermap::init_forecast("Mannheim", 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()); device_online = check_connection(ip.to_string());
// request once a minute new data // request once a minute new data
if device_online == true { if device_online == true {
@ -409,6 +421,7 @@ fn main() {
_ => { _ => {
// show a help message // show a help message
help(); help();
return ExitCode::SUCCESS;
} }
} }
} }

View File

@ -22,6 +22,7 @@ MainWindow::~MainWindow()
} }
void MainWindow::drawImage(QImage *target) { void MainWindow::drawImage(QImage *target) {
(void)target; /* handle unused variable ;-) */
this->mScene=new QGraphicsScene() ; this->mScene=new QGraphicsScene() ;
QGraphicsView *graphicsView = new QGraphicsView(); QGraphicsView *graphicsView = new QGraphicsView();
graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);