Rip out the GUI, run forever, log to terminal.

This commit is contained in:
mattbk
2026-09-07 10:40:40 -05:00
parent 05fe57bf24
commit 88f39df488
+188 -94
View File
@@ -47,7 +47,7 @@ impl Default for MyApp {
// =====================================================================
// Satellite Map Drawing Method
// =====================================================================
impl MyApp {
// impl MyApp {
// fn draw_satellite_map(&self, ui: &mut egui::Ui, sats: &[Satellite]) {
// Plot::new("satellite_map")
// .width(300.0)
@@ -78,97 +78,101 @@ impl MyApp {
// }
// });
// }
}
// }
// =====================================================================
// Main App UI
// =====================================================================
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let mut state = self.state.lock().unwrap();
// impl eframe::App for MyApp {
// fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
// let mut state = self.state.lock().unwrap();
// Main panel
// egui::CentralPanel::default().show(ctx, |ui| {
// ui.heading("Select COM Port");
// // Main panel
// // egui::CentralPanel::default().show(ctx, |ui| {
// // ui.heading("Select COM Port");
// let ports = state.ports.clone();
// // let ports = state.ports.clone();
// egui::ComboBox::from_label("COM Port")
// .selected_text(state.selected_port.as_deref().unwrap_or("Select a Port"))
// .show_ui(ui, |cb| {
// for port in ports {
// cb.selectable_value(
// &mut state.selected_port,
// Some(port.clone()),
// port,
// );
// // egui::ComboBox::from_label("COM Port")
// // .selected_text(state.selected_port.as_deref().unwrap_or("Select a Port"))
// // .show_ui(ui, |cb| {
// // for port in ports {
// // cb.selectable_value(
// // &mut state.selected_port,
// // Some(port.clone()),
// // port,
// // );
// // }
// // });
// // if ui.button("Start Reading").clicked() && !state.is_reading {
// // if let Some(port_name) = state.selected_port.clone() {
// // let state_clone = Arc::clone(&self.state);
// // Harcode port for dev
// let port_name = "/dev/tty.usbmodem1301";
// // Thread for GPS streaming
// thread::spawn(move || {
// let port = serialport::new(port_name, 9600)
// .timeout(Duration::from_millis(1000))
// .open();
// if let Ok(mut serial) = port {
// let mut buf = [0u8; 1024];
// loop {
// match serial.read(&mut buf) {
// Ok(n) => {
// let data = String::from_utf8_lossy(&buf[..n]);
// // let mut satellites = Vec::new();
// for line in data.lines() {
// println!("{}", line.to_string());
// // 🔵 Append NMEA line to log
// // {
// // let mut st = state_clone.lock().unwrap();
// // st.nmea_log.push(line.to_string());
// // // Keep log trimmed
// // if st.nmea_log.len() > 500 {
// // st.nmea_log.remove(0);
// // }
// // }
// // Parse GSV
// // if line.starts_with("$GPGSV") {
// //let fields: Vec<&str> = line.split(',').collect();
// //let mut i = 4;
// // while i + 3 < fields.len() {
// // satellites.push(Satellite {
// // id: fields[i].to_string(),
// // latitude: fields[i + 1].parse().unwrap_or(0.0),
// // longitude: fields[i + 2].parse().unwrap_or(0.0),
// // strength: fields[i + 3].parse().unwrap_or(0),
// // });
// // i += 4;
// // }
// // }
// }
// // Update satellites
// //let mut st = state_clone.lock().unwrap();
// // st.satellites = satellites;
// }
// Err(_) => break,
// }
// thread::sleep(Duration::from_millis(200));
// }
// }
// });
// if ui.button("Start Reading").clicked() && !state.is_reading {
// if let Some(port_name) = state.selected_port.clone() {
let state_clone = Arc::clone(&self.state);
let port_name = "/dev/tty.usbmodem1301";
// Thread for GPS streaming
thread::spawn(move || {
let port = serialport::new(port_name, 9600)
.timeout(Duration::from_millis(1000))
.open();
if let Ok(mut serial) = port {
let mut buf = [0u8; 1024];
loop {
match serial.read(&mut buf) {
Ok(n) => {
let data = String::from_utf8_lossy(&buf[..n]);
// let mut satellites = Vec::new();
for line in data.lines() {
// 🔵 Append NMEA line to log
{
let mut st = state_clone.lock().unwrap();
st.nmea_log.push(line.to_string());
// Keep log trimmed
if st.nmea_log.len() > 500 {
st.nmea_log.remove(0);
}
}
// Parse GSV
if line.starts_with("$GPGSV") {
//let fields: Vec<&str> = line.split(',').collect();
//let mut i = 4;
// while i + 3 < fields.len() {
// satellites.push(Satellite {
// id: fields[i].to_string(),
// latitude: fields[i + 1].parse().unwrap_or(0.0),
// longitude: fields[i + 2].parse().unwrap_or(0.0),
// strength: fields[i + 3].parse().unwrap_or(0),
// });
// i += 4;
// }
}
}
// Update satellites
//let mut st = state_clone.lock().unwrap();
// st.satellites = satellites;
}
Err(_) => break,
}
thread::sleep(Duration::from_millis(200));
}
}
});
state.is_reading = true;
// state.is_reading = true;
// }
// }
@@ -207,9 +211,10 @@ impl eframe::App for MyApp {
// });
// Write to console
for line in &state.nmea_log {
println!("{line}");
}
// for line in &state.nmea_log {
// println!("{line}");
// }
// =====================================================================
// Mini floating sky map
@@ -219,18 +224,107 @@ impl eframe::App for MyApp {
// .show(ctx, |ui| {
// self.draw_satellite_map(ui, &state.satellites);
// });
}
}
// }
// }
// =====================================================================
// Run
// =====================================================================
fn main() -> eframe::Result<()> {
let options = eframe::NativeOptions::default();
fn main() {
// let options = eframe::NativeOptions::default();
while 1 == 1 {
// Main panel
// egui::CentralPanel::default().show(ctx, |ui| {
// ui.heading("Select COM Port");
// let ports = state.ports.clone();
// egui::ComboBox::from_label("COM Port")
// .selected_text(state.selected_port.as_deref().unwrap_or("Select a Port"))
// .show_ui(ui, |cb| {
// for port in ports {
// cb.selectable_value(
// &mut state.selected_port,
// Some(port.clone()),
// port,
// );
// }
// });
// if ui.button("Start Reading").clicked() && !state.is_reading {
// if let Some(port_name) = state.selected_port.clone() {
// let state_clone = Arc::clone(&self.state);
// Harcode port for dev
let port_name = "/dev/tty.usbmodem1301";
// Thread for GPS streaming
thread::spawn(move || {
let port = serialport::new(port_name, 9600)
.timeout(Duration::from_millis(1000))
.open();
if let Ok(mut serial) = port {
let mut buf = [0u8; 1024];
loop {
match serial.read(&mut buf) {
Ok(n) => {
let data = String::from_utf8_lossy(&buf[..n]);
// let mut satellites = Vec::new();
for line in data.lines() {
println!("{}", line.to_string());
// 🔵 Append NMEA line to log
// {
// let mut st = state_clone.lock().unwrap();
// st.nmea_log.push(line.to_string());
// // Keep log trimmed
// if st.nmea_log.len() > 500 {
// st.nmea_log.remove(0);
// }
// }
// Parse GSV
// if line.starts_with("$GPGSV") {
//let fields: Vec<&str> = line.split(',').collect();
//let mut i = 4;
// while i + 3 < fields.len() {
// satellites.push(Satellite {
// id: fields[i].to_string(),
// latitude: fields[i + 1].parse().unwrap_or(0.0),
// longitude: fields[i + 2].parse().unwrap_or(0.0),
// strength: fields[i + 3].parse().unwrap_or(0),
// });
// i += 4;
// }
// }
}
// Update satellites
//let mut st = state_clone.lock().unwrap();
// st.satellites = satellites;
}
Err(_) => break,
}
thread::sleep(Duration::from_millis(200));
}
}
});
// eframe::run_native(
// "NMEA GPS Viewer",
// options,
// Box::new(|_cc| Box::new(MyApp::default())),
// )
}
eframe::run_native(
"NMEA GPS Viewer",
options,
Box::new(|_cc| Box::new(MyApp::default())),
)
}