Change tabs depending on TCP input.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-30 10:46:08 +02:00
parent cd80468f54
commit 51a2c28c55
2 changed files with 26 additions and 2 deletions

View File

@@ -48,10 +48,19 @@ pub enum TabActive {
Shortcuts, 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 { pub struct App {
tree: DockState<String>, tree: DockState<String>,
tab_viewer: CustomTabs, tab_viewer: CustomTabs,
// tab_active: TabActive,
log_filename: Arc<Mutex<String>>, log_filename: Arc<Mutex<String>>,
log_marker_modal: bool, log_marker_modal: bool,
log_marker: String, log_marker: String,
@@ -865,6 +874,17 @@ impl eframe::App for App {
.show_inside(ui, &mut self.tab_viewer); .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 // CMD- or control-W to close window
if ctx.input(|i| i.modifiers.cmd_ctrl_matches(Modifiers::COMMAND)) if ctx.input(|i| i.modifiers.cmd_ctrl_matches(Modifiers::COMMAND))
&& ctx.input(|i| i.key_pressed(Key::W)) && ctx.input(|i| i.key_pressed(Key::W))

View File

@@ -41,8 +41,12 @@ pub async fn app_control_loop(mut app_control_rx: mpsc::Receiver<ControlCommand>
info!("Cannot start measurement: No hardware connected!"); info!("Cannot start measurement: No hardware connected!");
continue; 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); info!("Starting impedance hardware with mode {:?}...", mode);
state.mode = mode;
match (mode, hardware_state_rx.borrow().hardware_connected) { match (mode, hardware_state_rx.borrow().hardware_connected) {
(Mode::Single, HardwareConnected::WithoutMultiplexer) => { (Mode::Single, HardwareConnected::WithoutMultiplexer) => {