From f41cf1dd1d42ad13d882734934d59f223e844df9 Mon Sep 17 00:00:00 2001 From: hacknus Date: Mon, 14 Oct 2024 15:55:24 +0200 Subject: [PATCH] fix reconnection bug --- src/gui.rs | 6 +++++- src/serial.rs | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui.rs b/src/gui.rs index 8fb76c9..dc31e67 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -525,7 +525,11 @@ impl MyApp { if !devices.contains(&self.device) { self.device.clear(); } - + if let Ok(dev) = self.device_lock.read() { + if !dev.name.is_empty() { + self.device = dev.name.clone(); + } + } ui.add_space(10.0); ui.horizontal(|ui| { ui.label("Device"); diff --git a/src/serial.rs b/src/serial.rs index 9cc11a6..57262b3 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -197,7 +197,12 @@ fn get_device( *write_guard = devices.clone(); } + // do reconnect if devices.contains(&last_connected_device.name) { + if let Ok(mut device) = device_lock.write() { + device.name = last_connected_device.name.clone(); + device.baud_rate = last_connected_device.baud_rate; + } return last_connected_device.clone(); }