diff --git a/src/app.rs b/src/app.rs index 412b636..ae40f3e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -686,7 +686,10 @@ impl App { // app.bode_plot.lock().unwrap().update_magnitudes(MeasurementPointSet::Eighteen, magnitudes); // app.bode_plot.lock().unwrap().update_phases(MeasurementPointSet::Eighteen, phases); - + + // Wait for the hardware state to update, before starting the measurement, to ensure the UI reflects the correct state + std::thread::sleep(std::time::Duration::from_millis(10)); + // Start measurement by default on the active tab app.toggle_start_stop(); app } @@ -863,6 +866,25 @@ impl eframe::App for App { }); }); }); + + // Show connection status in the bottom panel, green if connected + if self.app_state_rx.borrow().tcp_connected { + let frame = egui::Frame::default().fill(Color32::DARK_GREEN); + + egui::TopBottomPanel::bottom("bottom_panel") + .frame(frame) + .show(ctx, |ui| { + ui.with_layout( + egui::Layout::centered_and_justified(egui::Direction::LeftToRight), + |ui| { + ui.label( + RichText::new("TCP interface active") + .color(Color32::WHITE), + ); + }, + ); + }); + } }); egui::CentralPanel::default().show(ctx, |ui| { diff --git a/src/bin/main_gui.rs b/src/bin/main_gui.rs index 10b266d..fd2794d 100644 --- a/src/bin/main_gui.rs +++ b/src/bin/main_gui.rs @@ -85,7 +85,7 @@ async fn main() { let mut native_options = NativeOptions::default(); native_options.viewport.inner_size = Some(Vec2::new(850.0, 600.0)); let _ = eframe::run_native( - "Impedance Visualizer [egui + tokio] - Hubald Verzijl - 2025", + "Bio-Z Visualizer [egui + tokio] - Hubald Verzijl - 2026", native_options, Box::new(|_cc| Ok(Box::new(app))), ); diff --git a/src/control.rs b/src/control.rs index 3840316..2caac43 100644 --- a/src/control.rs +++ b/src/control.rs @@ -88,7 +88,10 @@ pub async fn app_control_loop(mut app_control_rx: mpsc::Receiver info!("Stopping impedance hardware..."); if let Err(e) = hardware_control_tx.try_send(StartStopSignal::Stop) { info!("Failed to send stop command: {:?}", e); + } } + ControlCommand::TcpConnected(connected) => { + state.tcp_connected = connected; } } diff --git a/src/state.rs b/src/state.rs index a2ff5ba..bf98533 100644 --- a/src/state.rs +++ b/src/state.rs @@ -46,6 +46,7 @@ pub enum ControlCommand { ChangeActiveTab(TabActive), Start(Mode), Stop, + TcpConnected(bool), } #[derive(Clone, Copy, Debug)] @@ -107,6 +108,7 @@ pub struct AppState { pub electrode_settings: ElectrodeSettings, pub sweep_points: SweepPoints, pub tab_active: TabActive, + pub tcp_connected: bool, } impl Default for AppState { @@ -119,6 +121,7 @@ impl Default for AppState { electrode_settings: ElectrodeSettings::new(), sweep_points: SweepPoints::Eighteen, tab_active: TabActive::Single, + tcp_connected: false, } } } diff --git a/src/tcp.rs b/src/tcp.rs index c4248b8..92e5285 100644 --- a/src/tcp.rs +++ b/src/tcp.rs @@ -10,6 +10,7 @@ pub async fn tcp_command_server(app_control_tx: Sender) { loop { let (socket, addr) = listener.accept().await.unwrap(); + app_control_tx.try_send(ControlCommand::TcpConnected(true)).unwrap(); println!("Client connected: {:?}", addr); let tx = app_control_tx.clone(); @@ -42,6 +43,7 @@ pub async fn tcp_command_server(app_control_tx: Sender) { } println!("Client disconnected: {:?}", addr); + tx.try_send(ControlCommand::TcpConnected(false)).unwrap(); }); } }