Most of the cleanup done
This commit is contained in:
parent
3b6a6a865f
commit
dccaa7bab2
|
|
@ -180,30 +180,26 @@ pub(crate) struct ConnectionInfo {
|
|||
}
|
||||
|
||||
impl ConnectionInfo {
|
||||
/// Create a connection
|
||||
pub(crate) fn new(
|
||||
/// Create the initial connection containing only the initial mutex for error collection
|
||||
pub(crate) fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
/// Updates the connection with the given data
|
||||
pub(crate) fn fill(
|
||||
&mut self,
|
||||
port: String,
|
||||
baudrate: u32,
|
||||
start: usize,
|
||||
stop: usize,
|
||||
points: usize,
|
||||
repeat: usize,
|
||||
) -> Self {
|
||||
Self {
|
||||
points,
|
||||
port,
|
||||
progress: Arc::new(Mutex::new(0)),
|
||||
repeat,
|
||||
return_data: Arc::new(Mutex::new(None)),
|
||||
scan_info: Arc::new(Mutex::new(String::new())),
|
||||
scan_message: Arc::new(Mutex::new(String::new())),
|
||||
start,
|
||||
stop,
|
||||
baudrate,
|
||||
file_name: Arc::new(Mutex::new(String::new())),
|
||||
connection_status: Arc::new(Mutex::new(ConnectionStatus::Uninitialised)),
|
||||
error_raised: Arc::new(Mutex::new(None)),
|
||||
}
|
||||
) {
|
||||
self.port = port;
|
||||
self.baudrate = baudrate;
|
||||
self.start = start;
|
||||
self.stop = stop;
|
||||
self.points = points;
|
||||
self.repeat = repeat;
|
||||
}
|
||||
|
||||
/// Updates the generic scan message
|
||||
|
|
@ -284,3 +280,23 @@ impl ConnectionInfo {
|
|||
// self.error_raised.lock().as_ref().unwrap()
|
||||
// }
|
||||
}
|
||||
|
||||
impl Default for ConnectionInfo {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
points: 11,
|
||||
baudrate: 115_200,
|
||||
port: String::new(),
|
||||
progress: Arc::new(Mutex::new(0)),
|
||||
repeat: 1,
|
||||
return_data: Arc::new(Mutex::new(None)),
|
||||
scan_info: Arc::new(Mutex::new(String::new())),
|
||||
scan_message: Arc::new(Mutex::new(String::new())),
|
||||
start: 240,
|
||||
stop: 960,
|
||||
file_name: Arc::new(Mutex::new(String::new())),
|
||||
connection_status: Arc::new(Mutex::new(ConnectionStatus::Uninitialised)),
|
||||
error_raised: Arc::new(Mutex::new(None)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
src/ui.rs
28
src/ui.rs
|
|
@ -130,6 +130,7 @@ impl<'a> AppInfo<'a> {
|
|||
|
||||
/// Initialisation of the config window
|
||||
fn init_config(&mut self) -> Result<(), TinyUIError> {
|
||||
self.connection_info = Some(ConnectionInfo::new());
|
||||
self.menu_items.portlist = Some(
|
||||
List::new(self.port_list.to_vecstr())
|
||||
.block(Block::bordered().title("COM Ports"))
|
||||
|
|
@ -627,22 +628,23 @@ impl<'a> AppInfo<'a> {
|
|||
AppState::FinalConfig(_) => {
|
||||
self.flow_state = AppState::Finished;
|
||||
self.init_progress()?;
|
||||
// Start the scan
|
||||
// let cstatus = self.get_connection_info()?.get_connection_status();
|
||||
// let error = self.scan_error.clone();
|
||||
let connection_info = ConnectionInfo::new(
|
||||
self.port_list.selected_port()?,
|
||||
self.baudrate.selected_baudrate()?,
|
||||
self.start_frequency.mhz_to_usize(),
|
||||
self.stop_frequency.mhz_to_usize(),
|
||||
self.points.int_to_usize(),
|
||||
self.repeat.int_to_usize(),
|
||||
);
|
||||
self.connection_info = Some(connection_info.clone());
|
||||
let mut co = self.connection_info.take();
|
||||
co.as_mut()
|
||||
.ok_or(TinyUIError::NoConnectionInfoCreated)?
|
||||
.fill(
|
||||
self.port_list.selected_port()?,
|
||||
self.baudrate.selected_baudrate()?,
|
||||
self.start_frequency.mhz_to_usize(),
|
||||
self.stop_frequency.mhz_to_usize(),
|
||||
self.points.int_to_usize(),
|
||||
self.repeat.int_to_usize(),
|
||||
);
|
||||
self.connection_info = co.clone();
|
||||
let co = co.unwrap();
|
||||
let connection = self.get_connection_info()?.clone();
|
||||
self.save_config()?;
|
||||
thread::spawn(move || {
|
||||
let status = scan::scan_with_progress(connection_info);
|
||||
let status = scan::scan_with_progress(co);
|
||||
match status {
|
||||
Ok(_) => {
|
||||
connection.update_connection_status(ConnectionStatus::ClosedWithSuccess)
|
||||
|
|
|
|||
Loading…
Reference in New Issue