From 7606cf967fbc21f75afcf57f9beebe998c7a009e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 25 Sep 2024 06:13:42 -0500 Subject: [PATCH] Fixes a repeat issue --- src/scan.rs | 18 +++++++++--------- src/ui.rs | 4 +++- src/ui_struct.rs | 2 ++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/scan.rs b/src/scan.rs index 64b1088..5ecb42f 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -1,9 +1,5 @@ //! The "lib" used for all scan related functions -/// The default start value for a scan -static START: usize = 240_000_000; -/// The default stop value for a scan -static STOP: usize = 959_000_000; /// The offset used for sending data static OFFSET: usize = 128; /// The base delay used inbetween commands @@ -52,11 +48,12 @@ pub(crate) fn scan_with_progress( start: usize, stop: usize, points: usize, + repeat: usize, ) -> Result<(), TinyError> { // TODO: Pass the connection status mutex to advance it *scan_message.lock().unwrap() = "Oppening connection".to_string(); let port = serialport::new(port, 115_200) - .timeout(Duration::from_millis(3000)) + .timeout(Duration::from_millis(5000)) .open(); // .expect("Failed to open port"); if let Err(e) = port { // *scan_message.lock().unwrap() = "Noo".to_string(); @@ -77,6 +74,11 @@ pub(crate) fn scan_with_progress( } *scan_info.lock().unwrap() = format!("{}{}", v, i); + *scan_message.lock().unwrap() = "Setting up repeat".to_string(); + // TODO: Investigate this behaviour + send_cmd(&mut port, &format!("repeat {}\r", 4), SHORT_WAIT); + send_cmd(&mut port, &format!("calc aver16\r"), SHORT_WAIT); + *progress.lock().unwrap() = 16; *scan_message.lock().unwrap() = "Setting zero...".to_string(); send_cmd(&mut port, &format!("zero {}\r", OFFSET), SHORT_WAIT); @@ -88,15 +90,13 @@ pub(crate) fn scan_with_progress( *progress.lock().unwrap() = 18; *scan_message.lock().unwrap() = "Setting up scan & mode".to_string(); - // return Err(TinyError::ConfigNotFound); - // panic!(); let mode = mode_from(start, stop)?; send_cmd(&mut port, &format!("mode {} input\r", mode), SHORT_WAIT); *progress.lock().unwrap() = 19; *scan_message.lock().unwrap() = "Setting up sweep".to_string(); - send_cmd(&mut port, &format!("sweep start {}\r", START), SHORT_WAIT); - send_cmd(&mut port, &format!("sweep stop {}\r", STOP), SHORT_WAIT); + send_cmd(&mut port, &format!("sweep start {}\r", start), SHORT_WAIT); + send_cmd(&mut port, &format!("sweep stop {}\r", stop), SHORT_WAIT); *progress.lock().unwrap() = 20; *scan_message.lock().unwrap() = "Starting scan...".to_string(); diff --git a/src/ui.rs b/src/ui.rs index b3bce1a..538a606 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -81,6 +81,7 @@ impl<'a> AppInfo<'a> { scan_message: Arc::new(Mutex::new(String::new())), return_data: Arc::new(Mutex::new(Vec::new())), connection_status: Arc::new(Mutex::new(ConnectionStatus::Uninitialised)), + repeat: UIUsize::new(1, 1, 1000), } } @@ -502,12 +503,13 @@ impl<'a> AppInfo<'a> { let start = self.start_frequency.mhz_to_usize(); let stop = self.stop_frequency.mhz_to_usize(); let points = self.points.int_to_usize(); + let repeat = self.repeat.int_to_usize(); // BYPASS *self.progress.lock().unwrap() = 100; self.save_config()?; thread::spawn(move || { let status = scan::scan_with_progress( - pmtx, mmtx, cmtx, rdata, port, start, stop, points, + pmtx, mmtx, cmtx, rdata, port, start, stop, points, repeat, ); match status { Ok(_) => *cstatus.lock().unwrap() = ConnectionStatus::ClosedWithSuccess, diff --git a/src/ui_struct.rs b/src/ui_struct.rs index 5218752..fac823f 100644 --- a/src/ui_struct.rs +++ b/src/ui_struct.rs @@ -43,6 +43,8 @@ pub(crate) struct AppInfo<'a> { pub(crate) stop_frequency: UIUsize, /// The number of points pub(crate) points: UIUsize, + /// Number of times to repeat a measure + pub(crate) repeat: UIUsize, /// Global progress pub(crate) progress: Arc>, /// Global initialisation data