mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2026-07-24 00:57:44 +00:00
Show TCP connected status.
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
22
src/app.rs
22
src/app.rs
@@ -687,6 +687,9 @@ 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| {
|
||||||
|
|||||||
@@ -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))),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ pub async fn app_control_loop(mut app_control_rx: mpsc::Receiver<ControlCommand>
|
|||||||
info!("Failed to send stop command: {:?}", e);
|
info!("Failed to send stop command: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ControlCommand::TcpConnected(connected) => {
|
||||||
|
state.tcp_connected = connected;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app_state_tx.send(state.clone()).unwrap();
|
app_state_tx.send(state.clone()).unwrap();
|
||||||
|
|||||||
@@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user