First set of changes to use config file instead of hard-coded settings.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
use crate::{gtfs, renderer};
|
||||
use std::collections::HashSet;
|
||||
extern crate serde_derive;
|
||||
extern crate serde_yaml;
|
||||
|
||||
struct Error {
|
||||
message: String
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct Config {
|
||||
#[serde(rename = "gtfs")]
|
||||
pub gtfs_prefs: gtfs::structs::Preferences,
|
||||
|
||||
#[serde(rename = "screen")]
|
||||
pub screen_prefs: renderer::structs::Prefs,
|
||||
}
|
||||
|
||||
|
||||
pub fn load_config(config_name: String) -> Result<Config, Error> {
|
||||
return Err(Error { message: String::from("Foo") });
|
||||
}
|
||||
+19
-1
@@ -1,11 +1,29 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use gtfs_structures::{Agency, Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop};
|
||||
|
||||
// This is to store the preferences for the GTFS(-R) side of the code.
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Preferences {
|
||||
#[serde(rename = "routes")]
|
||||
pub route_numbers: HashSet<String>,
|
||||
|
||||
#[serde(rename = "stops")]
|
||||
pub stop_codes: HashSet<String>,
|
||||
|
||||
#[serde(rename = "data-folder")]
|
||||
pub data_folder: String,
|
||||
|
||||
#[serde(rename = "gtfs-url")]
|
||||
pub gtfs_url: String,
|
||||
|
||||
#[serde(rename = "realtime-url")]
|
||||
pub realtime_url: String,
|
||||
|
||||
#[serde(rename = "realtime-api-key")]
|
||||
pub realtime_api_key: String,
|
||||
|
||||
#[serde(rename = "refresh-seconds")]
|
||||
pub refresh_seconds: u32,
|
||||
}
|
||||
|
||||
|
||||
|
||||
+11
-12
@@ -1,10 +1,11 @@
|
||||
mod gtfs;
|
||||
mod renderer;
|
||||
use std::{collections::HashSet, ops::Add, process, thread::Builder, time::SystemTime};
|
||||
mod config;
|
||||
use std::{ops::Add, process, thread::Builder, time::SystemTime};
|
||||
use chrono::{DateTime, Duration, Local, NaiveTime};
|
||||
use log::{Metadata, Record, error, info};
|
||||
use sdl3::event::Event;
|
||||
use crate::{gtfs::structs::{Arrival, Gtfs}, renderer::structs::{DisplayData, DisplayEntry, Screen}};
|
||||
use crate::{config::load_config, gtfs::structs::{Arrival, Gtfs}, renderer::structs::{DisplayData, DisplayEntry, Screen}};
|
||||
|
||||
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
||||
const NUM_ARRIVALS: usize = 4;
|
||||
@@ -80,17 +81,15 @@ fn main() {
|
||||
}
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
|
||||
// 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("1114")])
|
||||
};
|
||||
|
||||
let screen_prefs = renderer::structs::Prefs {
|
||||
font_path: String::from("resources/jd_lcd_rounded/jd-lcd-rounded.ttf"),
|
||||
screen_width: 1920,
|
||||
screen_height: 720,
|
||||
};
|
||||
let config_result = load_config(String::from("resources/dublinbus.yaml"));
|
||||
if config_result.is_err() {
|
||||
error!("Error loading the config file: {:#?}", config_result.err());
|
||||
process::exit(-1);
|
||||
}
|
||||
// Create preferences structures from config
|
||||
let gtfs_prefs = config_result.unwrap().gtfs_prefs;
|
||||
let screen_prefs = config_result.unwrap().screen_prefs;
|
||||
|
||||
// Init GTFS static info
|
||||
info!("Loading GTFS data...");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use sdl3::{Sdl, pixels::Color, render::Canvas, ttf::Font, video::Window};
|
||||
|
||||
extern crate serde;
|
||||
extern crate serde_derive;
|
||||
|
||||
pub struct Screen<'a> {
|
||||
pub(crate) canvas: Box<Canvas<Window>>,
|
||||
@@ -8,9 +9,16 @@ pub struct Screen<'a> {
|
||||
pub(crate) context: Box<Sdl>
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Prefs {
|
||||
|
||||
#[serde(rename = "font-path")]
|
||||
pub font_path: String,
|
||||
|
||||
#[serde(rename = "width")]
|
||||
pub screen_width: u32,
|
||||
|
||||
#[serde(rename = "height")]
|
||||
pub screen_height: u32,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user