Improved display printing, added extra debug.
This commit is contained in:
parent
c13411065a
commit
e185b38222
|
|
@ -4,6 +4,7 @@ mod utils;
|
|||
pub mod structs;
|
||||
use chrono::{DateTime, Local, Timelike};
|
||||
use log::{debug};
|
||||
use sdl3::sys::pixels::SDL_ArrayOrder;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet}, fs::File, io::Error
|
||||
};
|
||||
|
|
@ -66,7 +67,6 @@ impl Gtfs {
|
|||
for (_id, stop_time) in self.stop_times.iter() {
|
||||
if trips.contains_key(&stop_time.trip_id) {
|
||||
let stop_timestamp = stop_time.departure_time.or(stop_time.arrival_time)?;
|
||||
debug!("Stop timestamp {} current timestamp {}", stop_timestamp, current_timestamp);
|
||||
let trip= &self.trips.get(&stop_time.trip_id).unwrap();
|
||||
if current_timestamp < stop_timestamp.into() {
|
||||
let arrival: Arrival = Arrival {
|
||||
|
|
@ -76,6 +76,7 @@ impl Gtfs {
|
|||
trip: &trip,
|
||||
departure_time: stop_timestamp.into()
|
||||
};
|
||||
debug!("Arrival to {:#?} for trip ID {:#?}.", arrival.trip.trip_headsign.as_ref().unwrap(), arrival.trip.id);
|
||||
arrivals.push(arrival);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ fn main() {
|
|||
// Create preferences structures from config
|
||||
let gtfs_prefs = gtfs::structs::Preferences {
|
||||
route_numbers: HashSet::from([String::from("15A"), String::from("F1"), String::from("F2"), String::from("F3")]),
|
||||
stop_codes: HashSet::from([String::from("1117")])
|
||||
stop_codes: HashSet::from([String::from("1114")])
|
||||
};
|
||||
|
||||
let screen_prefs = renderer::structs::Prefs {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
pub mod structs;
|
||||
use std::cmp::min;
|
||||
|
||||
use sdl3::{Sdl, pixels::Color, rect::Rect, ttf::FontStyle};
|
||||
use std::{cmp::min};
|
||||
use log::{error, warn};
|
||||
use sdl3::{Sdl, pixels::Color, rect::Rect};
|
||||
use structs::{Prefs, DisplayData};
|
||||
|
||||
use crate::renderer::structs::Screen;
|
||||
|
|
@ -11,6 +11,7 @@ const COLOR_LCD_AMBER : Color = Color::RGB(0xf4, 0xcb, 0x60);
|
|||
const COLOR_LCD_GREEN : Color = Color::RGB(0xb3, 0xff, 0x00);
|
||||
const COLOR_LCD_RED : Color = Color::RGB(0xff, 0x3a, 0x4a);
|
||||
const COLOR_BACKGROUND : Color = Color::RGB(0x0, 0x0, 0x0 );
|
||||
const COLOR_TEXT_BG : Color = Color::RGBA(0x0, 0x0, 0x0, 0x0);
|
||||
const TEXT_SIZE: f32 = 160.0; // Size of the font in pixels
|
||||
|
||||
// Offsets of each part within a line
|
||||
|
|
@ -45,8 +46,16 @@ impl Screen<'_> {
|
|||
pub fn update_information(&mut self, display_data: &DisplayData) {
|
||||
self.do_clear();
|
||||
|
||||
// TODO: Add header
|
||||
// Print status first
|
||||
if display_data.status.is_some() {
|
||||
// If the update has some information text, show it
|
||||
self.do_print_at(5, display_data.status.as_ref().unwrap(), 0);
|
||||
} else {
|
||||
// Display date and time otherwise
|
||||
self.do_print_at(5, &format!("TODO: DATE/TIME GOES HERE").to_string(), 0);
|
||||
}
|
||||
|
||||
// Then data lines from the bottom up
|
||||
let num_arrivals: i32 = min(LINE_COUNT, display_data.lines.len() as i32);
|
||||
for index in 0..num_arrivals {
|
||||
let line: u32 = ((num_arrivals - 1) - index) as u32;
|
||||
|
|
@ -62,10 +71,6 @@ impl Screen<'_> {
|
|||
self.color = due_color;
|
||||
self.do_print_at(line, &due_text, XOFFSEET_TIME_LEFT);
|
||||
};
|
||||
|
||||
if display_data.status.is_some() {
|
||||
self.do_print_at(5, display_data.status.as_ref().unwrap(), 0);
|
||||
}
|
||||
self.do_update();
|
||||
}
|
||||
|
||||
|
|
@ -76,14 +81,31 @@ impl Screen<'_> {
|
|||
}
|
||||
|
||||
|
||||
fn do_print_at(&mut self, line: u32, text: &str, left: u32) -> u32 {
|
||||
let rendered_text = self.font.render(text).lcd(self.color, COLOR_BACKGROUND).unwrap();
|
||||
fn do_print_at(&mut self, line: u32, text: &str, left: u32) {
|
||||
if text.len() == 0 {
|
||||
warn!("do_print_at called with a 0-length string");
|
||||
return;
|
||||
}
|
||||
|
||||
let render_result = self.font.render(text).lcd(self.color, COLOR_BACKGROUND);
|
||||
|
||||
if render_result.is_err() {
|
||||
error!("Error rendering text \"{}\": {:#?}", text, render_result.err());
|
||||
return;
|
||||
}
|
||||
|
||||
let rendered_text = render_result.unwrap();
|
||||
let texture_creator = self.canvas.texture_creator();
|
||||
let texture = rendered_text.as_texture(&texture_creator).unwrap();
|
||||
let _= self.canvas.copy(&texture,
|
||||
let texture = rendered_text.as_texture(&texture_creator);
|
||||
|
||||
if texture.is_err() {
|
||||
error!("Error creating texture from rendered text: {:#?}", texture.err());
|
||||
return;
|
||||
}
|
||||
|
||||
let _= self.canvas.copy(&texture.unwrap(),
|
||||
Rect::new(0, 0, rendered_text.width(), rendered_text.height()),
|
||||
Rect::new(left.try_into().unwrap(), (line * (rendered_text.height() - INTER_LINE_OVERLAP)).try_into().unwrap(), rendered_text.width(), rendered_text.height()));
|
||||
return left + rendered_text.width();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue