Rip out all GUI except skeleton.

This commit is contained in:
mattbk
2026-09-06 22:29:24 -05:00
parent 4c09f72471
commit 05fe57bf24
+114 -107
View File
@@ -1,24 +1,24 @@
use eframe::egui; use eframe::egui;
use serialport::available_ports; //use serialport::available_ports;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use egui_plot::{Plot, PlotPoints, Points, Text, Line}; // use egui_plot::{Plot, PlotPoints, Points, Text, Line};
#[derive(Default, Clone)] #[derive(Default, Clone)]
struct Satellite { // struct Satellite {
id: String, // id: String,
latitude: f64, // latitude: f64,
longitude: f64, // longitude: f64,
strength: u8, // strength: u8,
} // }
#[derive(Default)] //#[derive(Default)]
struct AppState { struct AppState {
ports: Vec<String>, //ports: Vec<String>,
selected_port: Option<String>, //selected_port: Option<String>,
satellites: Vec<Satellite>, //satellites: Vec<Satellite>,
is_reading: bool, is_reading: bool,
// 🔵 NEW: live NMEA data buffer // 🔵 NEW: live NMEA data buffer
@@ -31,13 +31,13 @@ pub struct MyApp {
impl Default for MyApp { impl Default for MyApp {
fn default() -> Self { fn default() -> Self {
let ports = available_ports() // let ports = available_ports()
.map(|ps| ps.into_iter().map(|p| p.port_name).collect()) // .map(|ps| ps.into_iter().map(|p| p.port_name).collect())
.unwrap_or_default(); // .unwrap_or_default();
Self { Self {
state: Arc::new(Mutex::new(AppState { state: Arc::new(Mutex::new(AppState {
ports, //ports,
..Default::default() ..Default::default()
})), })),
} }
@@ -48,36 +48,36 @@ impl Default for MyApp {
// Satellite Map Drawing Method // Satellite Map Drawing Method
// ===================================================================== // =====================================================================
impl MyApp { impl MyApp {
fn draw_satellite_map(&self, ui: &mut egui::Ui, sats: &[Satellite]) { // fn draw_satellite_map(&self, ui: &mut egui::Ui, sats: &[Satellite]) {
Plot::new("satellite_map") // Plot::new("satellite_map")
.width(300.0) // .width(300.0)
.height(300.0) // .height(300.0)
.view_aspect(1.0) // .view_aspect(1.0)
.show(ui, |plot_ui| { // .show(ui, |plot_ui| {
// Draw outline circle // // Draw outline circle
let circle: PlotPoints = (0..360) // let circle: PlotPoints = (0..360)
.map(|deg| { // .map(|deg| {
let rad = (deg as f64).to_radians(); // let rad = (deg as f64).to_radians();
[rad.cos(), rad.sin()] // [rad.cos(), rad.sin()]
}) // })
.collect::<Vec<_>>() // .collect::<Vec<_>>()
.into(); // .into();
plot_ui.line(Line::new(circle)); // plot_ui.line(Line::new(circle));
// Draw satellites // // Draw satellites
for sat in sats { // for sat in sats {
let az = sat.longitude.to_radians(); // let az = sat.longitude.to_radians();
let el = sat.latitude.to_radians(); // let el = sat.latitude.to_radians();
let x = el.cos() * az.cos(); // let x = el.cos() * az.cos();
let y = el.cos() * az.sin(); // let y = el.cos() * az.sin();
plot_ui.points(Points::new(vec![[x, y]]).radius(3.0)); // plot_ui.points(Points::new(vec![[x, y]]).radius(3.0));
plot_ui.text(Text::new([x, y].into(), sat.id.clone())); // plot_ui.text(Text::new([x, y].into(), sat.id.clone()));
} // }
}); // });
} // }
} }
// ===================================================================== // =====================================================================
@@ -88,26 +88,28 @@ impl eframe::App for MyApp {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
// Main panel // Main panel
egui::CentralPanel::default().show(ctx, |ui| { // egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("Select COM Port"); // ui.heading("Select COM Port");
let ports = state.ports.clone(); // let ports = state.ports.clone();
egui::ComboBox::from_label("COM Port") // egui::ComboBox::from_label("COM Port")
.selected_text(state.selected_port.as_deref().unwrap_or("Select a Port")) // .selected_text(state.selected_port.as_deref().unwrap_or("Select a Port"))
.show_ui(ui, |cb| { // .show_ui(ui, |cb| {
for port in ports { // for port in ports {
cb.selectable_value( // cb.selectable_value(
&mut state.selected_port, // &mut state.selected_port,
Some(port.clone()), // Some(port.clone()),
port, // port,
); // );
} // }
}); // });
if ui.button("Start Reading").clicked() && !state.is_reading { // if ui.button("Start Reading").clicked() && !state.is_reading {
if let Some(port_name) = state.selected_port.clone() { // if let Some(port_name) = state.selected_port.clone() {
let state_clone = Arc::clone(&self.state); let state_clone = Arc::clone(&self.state);
let port_name = "/dev/tty.usbmodem1301";
// Thread for GPS streaming // Thread for GPS streaming
thread::spawn(move || { thread::spawn(move || {
@@ -122,7 +124,7 @@ impl eframe::App for MyApp {
match serial.read(&mut buf) { match serial.read(&mut buf) {
Ok(n) => { Ok(n) => {
let data = String::from_utf8_lossy(&buf[..n]); let data = String::from_utf8_lossy(&buf[..n]);
let mut satellites = Vec::new(); // let mut satellites = Vec::new();
for line in data.lines() { for line in data.lines() {
@@ -139,24 +141,24 @@ impl eframe::App for MyApp {
// Parse GSV // Parse GSV
if line.starts_with("$GPGSV") { if line.starts_with("$GPGSV") {
let fields: Vec<&str> = line.split(',').collect(); //let fields: Vec<&str> = line.split(',').collect();
let mut i = 4; //let mut i = 4;
while i + 3 < fields.len() { // while i + 3 < fields.len() {
satellites.push(Satellite { // satellites.push(Satellite {
id: fields[i].to_string(), // id: fields[i].to_string(),
latitude: fields[i + 1].parse().unwrap_or(0.0), // latitude: fields[i + 1].parse().unwrap_or(0.0),
longitude: fields[i + 2].parse().unwrap_or(0.0), // longitude: fields[i + 2].parse().unwrap_or(0.0),
strength: fields[i + 3].parse().unwrap_or(0), // strength: fields[i + 3].parse().unwrap_or(0),
}); // });
i += 4; // i += 4;
} // }
} }
} }
// Update satellites // Update satellites
let mut st = state_clone.lock().unwrap(); //let mut st = state_clone.lock().unwrap();
st.satellites = satellites; // st.satellites = satellites;
} }
Err(_) => break, Err(_) => break,
} }
@@ -167,51 +169,56 @@ impl eframe::App for MyApp {
}); });
state.is_reading = true; state.is_reading = true;
} // }
} // }
ui.separator(); // ui.separator();
ui.heading("Satellites"); // ui.heading("Satellites");
egui::ScrollArea::vertical().show(ui, |ui| { // egui::ScrollArea::vertical().show(ui, |ui| {
for sat in &state.satellites { // for sat in &state.satellites {
ui.horizontal(|ui| { // ui.horizontal(|ui| {
ui.label(format!("ID: {}", sat.id)); // ui.label(format!("ID: {}", sat.id));
ui.label(format!("Elv: {:.2}", sat.latitude)); // ui.label(format!("Elv: {:.2}", sat.latitude));
ui.label(format!("Azm: {:.2}", sat.longitude)); // ui.label(format!("Azm: {:.2}", sat.longitude));
ui.label(format!("Strength: {}", sat.strength)); // ui.label(format!("Strength: {}", sat.strength));
}); // });
} // }
}); // });
}); // });
// ===================================================================== // =====================================================================
// NEW: Live GPS Stream Window // NEW: Live GPS Stream Window
// ===================================================================== // =====================================================================
egui::Window::new("GPS Stream") // egui::Window::new("GPS Stream")
.default_width(400.0) // .default_width(400.0)
.default_height(300.0) // .default_height(300.0)
.resizable(true) // .resizable(true)
.show(ctx, |ui| { // .show(ctx, |ui| {
ui.label("Live NMEA Data:"); // ui.label("Live NMEA Data:");
egui::ScrollArea::vertical() // egui::ScrollArea::vertical()
.stick_to_bottom(true) // .stick_to_bottom(true)
.show(ui, |ui| { // .show(ui, |ui| {
for line in &state.nmea_log { // for line in &state.nmea_log {
ui.monospace(line); // ui.monospace(line);
} // }
}); // });
}); // });
// Write to console
for line in &state.nmea_log {
println!("{line}");
}
// ===================================================================== // =====================================================================
// Mini floating sky map // Mini floating sky map
// ===================================================================== // =====================================================================
egui::Area::new("mini_sky_map".into()) // egui::Area::new("mini_sky_map".into())
.anchor(egui::Align2::RIGHT_TOP, [-10.0, 10.0]) // .anchor(egui::Align2::RIGHT_TOP, [-10.0, 10.0])
.show(ctx, |ui| { // .show(ctx, |ui| {
self.draw_satellite_map(ui, &state.satellites); // self.draw_satellite_map(ui, &state.satellites);
}); // });
} }
} }