Show TCP connected status.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-05-03 17:07:08 +02:00
parent 51a2c28c55
commit d5027f9aa8
5 changed files with 32 additions and 2 deletions

View File

@@ -686,7 +686,10 @@ impl App {
// app.bode_plot.lock().unwrap().update_magnitudes(MeasurementPointSet::Eighteen, magnitudes); // app.bode_plot.lock().unwrap().update_magnitudes(MeasurementPointSet::Eighteen, magnitudes);
// app.bode_plot.lock().unwrap().update_phases(MeasurementPointSet::Eighteen, phases); // 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.toggle_start_stop();
app 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| { egui::CentralPanel::default().show(ctx, |ui| {

View File

@@ -85,7 +85,7 @@ async fn main() {
let mut native_options = NativeOptions::default(); let mut native_options = NativeOptions::default();
native_options.viewport.inner_size = Some(Vec2::new(850.0, 600.0)); native_options.viewport.inner_size = Some(Vec2::new(850.0, 600.0));
let _ = eframe::run_native( let _ = eframe::run_native(
"Impedance Visualizer [egui + tokio] - Hubald Verzijl - 2025", "Bio-Z Visualizer [egui + tokio] - Hubald Verzijl - 2026",
native_options, native_options,
Box::new(|_cc| Ok(Box::new(app))), Box::new(|_cc| Ok(Box::new(app))),
); );

View File

@@ -88,7 +88,10 @@ pub async fn app_control_loop(mut app_control_rx: mpsc::Receiver<ControlCommand>
info!("Stopping impedance hardware..."); info!("Stopping impedance hardware...");
if let Err(e) = hardware_control_tx.try_send(StartStopSignal::Stop) { if let Err(e) = hardware_control_tx.try_send(StartStopSignal::Stop) {
info!("Failed to send stop command: {:?}", e); info!("Failed to send stop command: {:?}", e);
}
} }
ControlCommand::TcpConnected(connected) => {
state.tcp_connected = connected;
} }
} }

View File

@@ -46,6 +46,7 @@ pub enum ControlCommand {
ChangeActiveTab(TabActive), ChangeActiveTab(TabActive),
Start(Mode), Start(Mode),
Stop, Stop,
TcpConnected(bool),
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
@@ -107,6 +108,7 @@ pub struct AppState {
pub electrode_settings: ElectrodeSettings, pub electrode_settings: ElectrodeSettings,
pub sweep_points: SweepPoints, pub sweep_points: SweepPoints,
pub tab_active: TabActive, pub tab_active: TabActive,
pub tcp_connected: bool,
} }
impl Default for AppState { impl Default for AppState {
@@ -119,6 +121,7 @@ impl Default for AppState {
electrode_settings: ElectrodeSettings::new(), electrode_settings: ElectrodeSettings::new(),
sweep_points: SweepPoints::Eighteen, sweep_points: SweepPoints::Eighteen,
tab_active: TabActive::Single, tab_active: TabActive::Single,
tcp_connected: false,
} }
} }
} }

View File

@@ -10,6 +10,7 @@ pub async fn tcp_command_server(app_control_tx: Sender<ControlCommand>) {
loop { loop {
let (socket, addr) = listener.accept().await.unwrap(); let (socket, addr) = listener.accept().await.unwrap();
app_control_tx.try_send(ControlCommand::TcpConnected(true)).unwrap();
println!("Client connected: {:?}", addr); println!("Client connected: {:?}", addr);
let tx = app_control_tx.clone(); let tx = app_control_tx.clone();
@@ -42,6 +43,7 @@ pub async fn tcp_command_server(app_control_tx: Sender<ControlCommand>) {
} }
println!("Client disconnected: {:?}", addr); println!("Client disconnected: {:?}", addr);
tx.try_send(ControlCommand::TcpConnected(false)).unwrap();
}); });
} }
} }