From 51a2c28c556527ad7c3aaf64ef5c1eac9490ea8c Mon Sep 17 00:00:00 2001 From: Hubald Verzijl Date: Thu, 30 Apr 2026 10:46:08 +0200 Subject: [PATCH] Change tabs depending on TCP input. Co-authored-by: Copilot --- src/app.rs | 22 +++++++++++++++++++++- src/control.rs | 6 +++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/app.rs b/src/app.rs index faa9b7a..412b636 100644 --- a/src/app.rs +++ b/src/app.rs @@ -48,10 +48,19 @@ pub enum TabActive { Shortcuts, } +impl ToString for TabActive { + fn to_string(&self) -> String { + match self { + TabActive::Single => "Single".to_string(), + TabActive::Sweep => "Sweep".to_string(), + TabActive::Shortcuts => "Shortcuts".to_string(), + } + } +} + pub struct App { tree: DockState, tab_viewer: CustomTabs, - // tab_active: TabActive, log_filename: Arc>, log_marker_modal: bool, log_marker: String, @@ -865,6 +874,17 @@ impl eframe::App for App { .show_inside(ui, &mut self.tab_viewer); }); + // Check if tab is different from the active tab in app state, if so, switch to that tab + if let Some((_, name)) = self.tree.find_active_focused() { + if self.app_state_rx.borrow().tab_active.to_string() != *name { + let active_tab = self.app_state_rx.borrow().tab_active.to_string(); + self.tree.set_active_tab(self.tree.find_tab(&active_tab).unwrap()); + } + } else { + let active_tab = self.app_state_rx.borrow().tab_active.to_string(); + self.tree.set_active_tab(self.tree.find_tab(&active_tab).unwrap()); + } + // CMD- or control-W to close window if ctx.input(|i| i.modifiers.cmd_ctrl_matches(Modifiers::COMMAND)) && ctx.input(|i| i.key_pressed(Key::W)) diff --git a/src/control.rs b/src/control.rs index db03894..3840316 100644 --- a/src/control.rs +++ b/src/control.rs @@ -41,8 +41,12 @@ pub async fn app_control_loop(mut app_control_rx: mpsc::Receiver info!("Cannot start measurement: No hardware connected!"); continue; } - state.mode = mode; + if hardware_state_rx.borrow().running { + info!("Measurement already running, stopping first..."); + hardware_control_tx.try_send(StartStopSignal::Stop).unwrap(); + } info!("Starting impedance hardware with mode {:?}...", mode); + state.mode = mode; match (mode, hardware_state_rx.borrow().hardware_connected) { (Mode::Single, HardwareConnected::WithoutMultiplexer) => {