Compare commits
No commits in common. "b3f251e4ccc79acb6cc52947690114dab64c9a3c" and "1ecf31b6fa8b3fcf359db6a390e69ef33c1da2fa" have entirely different histories.
b3f251e4cc
...
1ecf31b6fa
|
|
@ -1,8 +0,0 @@
|
|||
[build]
|
||||
default-target = "aarch64-unknown-linux-gnu" # use this target if none is explicitly provided
|
||||
pre-build = [ # additional commands to run prior to building the package
|
||||
"dpkg --add-architecture $CROSS_DEB_ARCH",
|
||||
"apt update",
|
||||
"apt --assume-yes install apt-utils:$CROSS_DEB_ARCH",
|
||||
"apt --assume-yes install libsdl3-dev:$CROSS_DEB_ARCH"
|
||||
]
|
||||
|
|
@ -15,7 +15,7 @@ use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences}};
|
|||
|
||||
impl Gtfs {
|
||||
|
||||
pub fn get_next_arrivals_for(&self, target_datetime: &DateTime<Local>) -> Vec<Arrival<'_>> {
|
||||
pub fn get_next_arrivals_for(&self, target_datetime: &DateTime<Local>) -> Box<Vec<Arrival<'_>>> {
|
||||
let naive_target = target_datetime.naive_local();
|
||||
let target_date = naive_target.date();
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ impl Gtfs {
|
|||
}
|
||||
debug!("Found {} arrivals", arrivals.len());
|
||||
|
||||
return arrivals;
|
||||
return Box::from(arrivals);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
25
src/main.rs
25
src/main.rs
|
|
@ -1,10 +1,10 @@
|
|||
mod gtfs;
|
||||
mod renderer;
|
||||
use std::{collections::{HashSet, btree_map::Entry}, ops::Add, process, thread::Builder, time::SystemTime};
|
||||
use std::{collections::HashSet, ops::Add, process, thread::Builder, time::SystemTime};
|
||||
use chrono::{DateTime, Duration, Local, NaiveTime};
|
||||
use log::{Metadata, Record, debug, error, info};
|
||||
use sdl3::event::Event;
|
||||
use crate::{gtfs::structs::{Arrival, Gtfs}, renderer::structs::{DisplayData, DisplayEntry, Screen}};
|
||||
use crate::{gtfs::structs::{Arrival, Gtfs}, renderer::structs::Screen};
|
||||
|
||||
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
||||
const NUM_ARRIVALS: usize = 4;
|
||||
|
|
@ -15,10 +15,10 @@ struct RefreshDataEvent {
|
|||
}
|
||||
|
||||
|
||||
fn refresh_schedule<'a>(gtfs: &'a Gtfs, screen: &'a Screen<'a>) -> Vec<Arrival<'a>> {
|
||||
fn refresh_schedule(gtfs: &Gtfs) -> Box<Vec<Arrival<'_>>> {
|
||||
let current_timestamp = SystemTime::now();
|
||||
let datetime: DateTime<Local> = current_timestamp.clone().into();
|
||||
let mut next_arrivals: Vec<Arrival<'_>> = gtfs.get_next_arrivals_for(&datetime);
|
||||
let mut next_arrivals: Box<Vec<Arrival<'_>>> = gtfs.get_next_arrivals_for(&datetime);
|
||||
|
||||
if next_arrivals.len() < NUM_ARRIVALS {
|
||||
// If we don't have enough entries today, look for arrivals tomorrow.
|
||||
|
|
@ -29,21 +29,6 @@ fn refresh_schedule<'a>(gtfs: &'a Gtfs, screen: &'a Screen<'a>) -> Vec<Arrival<'
|
|||
}
|
||||
|
||||
next_arrivals.sort();
|
||||
|
||||
// Create the DisplayData structure to render the information to screen
|
||||
let current_time = Local::now().time();
|
||||
let display_data: DisplayData = DisplayData {
|
||||
lines: Vec::<DisplayEntry<'_>>::from(next_arrivals.iter().map(|arrival| {
|
||||
DisplayEntry {
|
||||
destination: &String::from("Foo"),
|
||||
route: &arrival.route.short_name.or(arrival.route.long_name).unwrap(),
|
||||
due_in: (arrival.departure_time - current_time).num_minutes().try_into().unwrap()
|
||||
}
|
||||
}).collect()),
|
||||
status: None
|
||||
};
|
||||
|
||||
screen.update_information(&display_data);
|
||||
return next_arrivals;
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +112,7 @@ fn main() {
|
|||
let refresh_data = event.as_user_event_type::<RefreshDataEvent>();
|
||||
if refresh_data.is_some() {
|
||||
debug!("Received user event: {:#?}", refresh_data.unwrap());
|
||||
let _data: Vec<Arrival<'_>> = refresh_schedule(>fs, &screen);
|
||||
let _data: Box<Vec<Arrival<'_>>> = refresh_schedule(>fs);
|
||||
debug!("-------------------------------- Refresh done.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,94 +1,32 @@
|
|||
|
||||
pub mod structs;
|
||||
use std::cmp::min;
|
||||
|
||||
use sdl3::{Sdl, pixels::Color, rect::Rect};
|
||||
use structs::{Prefs, DisplayData};
|
||||
use structs::{Prefs};
|
||||
|
||||
use crate::renderer::structs::Screen;
|
||||
|
||||
const LINE_COUNT: i32 = 6;
|
||||
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 = pygame.Color(0, 0, 0)
|
||||
const UPDATE_INTERVAL_SECONDS: u32 = 62;
|
||||
const TEXT_SIZE: u32 = 160; // Size of the font in pixels
|
||||
|
||||
// Offsets of each part within a line
|
||||
const XOFFSET_ROUTE: u32 = 24;
|
||||
const XOFFSET_DESTINATION: u32 = 300;
|
||||
const XOFFSEET_TIME_LEFT: u32 = 1606;
|
||||
const INTER_LINE_SPACE: i32 = -15;
|
||||
|
||||
|
||||
impl Screen<'_> {
|
||||
|
||||
pub fn get_context(&self) -> &Sdl {
|
||||
return &self.context;
|
||||
}
|
||||
|
||||
fn color_for(&self, due_in: i32) -> Color {
|
||||
if due_in > 15 { return COLOR_LCD_GREEN };
|
||||
if due_in > 10 { return COLOR_LCD_AMBER };
|
||||
return COLOR_LCD_RED;
|
||||
}
|
||||
|
||||
|
||||
pub fn update_information(&mut self, display_data: &DisplayData) {
|
||||
self.do_clear();
|
||||
let num_arrivals: i32 = min(if display_data.status.is_some() {LINE_COUNT - 1} else {LINE_COUNT}, display_data.lines.len().try_into().unwrap());
|
||||
for line in 0..num_arrivals {
|
||||
// Compose a line of text with all the information
|
||||
let entry = display_data.lines.get(line as usize).unwrap();
|
||||
let line: u32 = line.try_into().unwrap();
|
||||
let due_in_mins = (entry.due_in / 60) as i32;
|
||||
let arrival_color: Color = self.color_for(due_in_mins);
|
||||
|
||||
self.do_print_at(line, entry.route, XOFFSET_ROUTE);
|
||||
self.do_print_at(line, entry.destination, XOFFSET_DESTINATION);
|
||||
self.do_print_at(line, &due_in_mins.to_string(), XOFFSEET_TIME_LEFT);
|
||||
};
|
||||
|
||||
if display_data.status.is_none() {
|
||||
self.do_print_at(5, display_data.status.as_ref().unwrap(), 0);
|
||||
}
|
||||
self.do_update();
|
||||
}
|
||||
|
||||
|
||||
pub fn print(&mut self, line: u32, text: &str) {
|
||||
self.do_print_at(line, text, 0);
|
||||
self.do_update();
|
||||
}
|
||||
|
||||
|
||||
fn do_print_at(&mut self, line: u32, text: &str, left: u32) -> u32 {
|
||||
let rendered_text = self.font.render(text).solid(Color::RED).unwrap();
|
||||
let texture_creator = self.canvas.texture_creator();
|
||||
let texture = rendered_text.as_texture(&texture_creator).unwrap();
|
||||
self.canvas.copy(&texture,
|
||||
let _ = self.canvas.copy(&texture,
|
||||
Rect::new(0, 0, rendered_text.width(), rendered_text.height()),
|
||||
Rect::new(left.try_into().unwrap(), (line * rendered_text.height()).try_into().unwrap(), rendered_text.width(), rendered_text.height()));
|
||||
return left + rendered_text.width();
|
||||
}
|
||||
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.do_clear();
|
||||
self.do_update();
|
||||
}
|
||||
|
||||
|
||||
fn do_update (&mut self) {
|
||||
Rect::new(0, (line * rendered_text.height()).try_into().unwrap(), rendered_text.width(), rendered_text.height()));
|
||||
self.canvas.present();
|
||||
}
|
||||
|
||||
|
||||
fn do_clear(&mut self) {
|
||||
pub fn clear(&mut self) {
|
||||
self.canvas.set_draw_color(Color::BLACK);
|
||||
self.canvas.clear();
|
||||
self.canvas.present();
|
||||
}
|
||||
|
||||
/// Initialize video, allocate buffers and load fonts
|
||||
|
|
|
|||
|
|
@ -12,15 +12,3 @@ pub struct Prefs {
|
|||
pub screen_width: u32,
|
||||
pub screen_height: u32,
|
||||
}
|
||||
|
||||
|
||||
pub struct DisplayEntry<'a> {
|
||||
pub route: &'a String,
|
||||
pub destination: &'a String,
|
||||
pub due_in: i32,
|
||||
}
|
||||
|
||||
pub struct DisplayData<'a> {
|
||||
pub lines: Vec<DisplayEntry<'a>>,
|
||||
pub status: Option<String>
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue