mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2026-07-23 16:47:43 +00:00
Show TCP connected status.
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
24
src/app.rs
24
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| {
|
||||
|
||||
@@ -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))),
|
||||
);
|
||||
|
||||
@@ -88,7 +88,10 @@ pub async fn app_control_loop(mut app_control_rx: mpsc::Receiver<ControlCommand>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ pub async fn tcp_command_server(app_control_tx: Sender<ControlCommand>) {
|
||||
|
||||
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<ControlCommand>) {
|
||||
}
|
||||
|
||||
println!("Client disconnected: {:?}", addr);
|
||||
tx.try_send(ControlCommand::TcpConnected(false)).unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user