use crate::config::VisualizerConfig; use crate::dsn::dsn_request; use crate::dsn::models::{Signal, SignalType, Station, Target}; use matrix::Display; use reqwest::blocking::Client; use rpi_led_matrix::{LedColor, LedMatrix, LedMatrixOptions, LedRuntimeOptions}; use std::sync::mpsc; use std::time::Duration; mod config; mod dsn; mod matrix; fn dsn_thread(config: VisualizerConfig, tx: mpsc::Sender>) { let client = Client::new(); let sleep_duration = Duration::from_secs(config.polling_rate); loop { match dsn_request(&client, &config.dsn_address) { Ok(stations) => { if tx.send(stations).is_err() { break; } } Err(e) => { println!("Unable to fetch DSN status: {}", e) } } std::thread::sleep(sleep_duration); } } fn main() { let (tx, rx) = mpsc::channel::>(); let config = VisualizerConfig::new("config.toml").unwrap(); let sleep_duration = Duration::from_millis(1); let mut x = 0; let mut display = Display::new(64, 64); std::thread::spawn(move || dsn_thread(config, tx)); loop { let mut blu = 0; let mut red = 255; let stations = rx.recv_timeout(sleep_duration); if let Ok(stations) = stations { for station in stations { for dish in station.dishes { for target in dish.target { let up_signal = dish.up_signal.iter().find(|s| { s.spacecraft_id == Some(target.id) && SignalType::Data == s.signal_type }); let down_signal = dish.down_signal.iter().find(|s| { s.spacecraft_id == Some(target.id) && SignalType::Data == s.signal_type }); if up_signal.is_some() || down_signal.is_some() { let color = config.spacecraft.iter().find(|spacecraft| spacecraft.spacecraft_id == target.id) display.update_status( LedColor { red: red, green: 0, blue: blu, }, target, up_signal.cloned(), down_signal.cloned(), ); blu += 20; red -= 20; } } } } } display.refresh_display(); } }