Skip to content

Commit af11cfe

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents d04ef4f + 628d395 commit af11cfe

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

.github/workflows/deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v3
1818
- name: Update Libs
19-
run: sudo apt-get install libgtk-3-dev && sudo apt-get install libudev-dev && cargo install cargo-bundle
19+
run: sudo apt-get install -y libclang-dev libgtk-3-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev && sudo apt-get install libudev-dev && cargo install cargo-bundle
2020
- name: Build
2121
run: cargo bundle --release
2222
# - name: Compress.

src/serial.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn serial_thread(
109109
*connected = false;
110110
}
111111

112-
let device = get_device(&devices_lock, &device_lock);
112+
let (devices, device) = get_device(&devices_lock, &device_lock);
113113

114114
let mut port = match serialport::new(&device.name, device.baud_rate)
115115
.timeout(Duration::from_millis(100))
@@ -150,18 +150,16 @@ pub fn serial_thread(
150150
.create();
151151

152152
'connected_loop: loop {
153-
let devices = available_devices();
154-
if let Ok(mut write_guard) = devices_lock.write() {
155-
*write_guard = devices.clone();
156-
}
157-
158153
if let Some(message) = disconnected(&device, &devices, &device_lock) {
159154
print_to_console(&print_lock, message);
160155
break 'connected_loop;
161156
}
162157

163158
perform_writes(&mut port, &send_rx, &raw_data_tx, t_zero);
164-
perform_reads(&mut port, &raw_data_tx, t_zero);
159+
if let Some(e) = perform_reads(&mut port, &raw_data_tx, t_zero) {
160+
print_to_console(&print_lock, Print::Error(e.to_string()));
161+
break 'connected_loop;
162+
};
165163

166164
//std::thread::sleep(Duration::from_millis(10));
167165
}
@@ -180,7 +178,7 @@ fn available_devices() -> Vec<String> {
180178
fn get_device(
181179
devices_lock: &Arc<RwLock<Vec<String>>>,
182180
device_lock: &Arc<RwLock<Device>>,
183-
) -> Device {
181+
) -> (Vec<String>, Device) {
184182
loop {
185183
let devices = available_devices();
186184
if let Ok(mut write_guard) = devices_lock.write() {
@@ -189,7 +187,7 @@ fn get_device(
189187

190188
if let Ok(device) = device_lock.read() {
191189
if devices.contains(&device.name) {
192-
return device.clone();
190+
return (devices.clone(), device.clone());
193191
}
194192
}
195193
std::thread::sleep(Duration::from_millis(100));
@@ -253,7 +251,7 @@ fn perform_reads(
253251
port: &mut BufReader<Box<dyn SerialPort>>,
254252
raw_data_tx: &Sender<Packet>,
255253
t_zero: Instant,
256-
) {
254+
) -> Option<std::io::Error> {
257255
let mut buf = "".to_string();
258256
match serial_read(port, &mut buf) {
259257
Ok(_) => {
@@ -270,8 +268,12 @@ fn perform_reads(
270268
}
271269
// Timeout is ok, just means there is no data to read
272270
Err(ref e) if e.kind() == std::io::ErrorKind::TimedOut => {}
271+
Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => {
272+
return Some(e);
273+
}
273274
Err(e) => {
274275
println!("Error reading: {:?}", e);
275276
}
276-
}
277+
};
278+
None
277279
}

0 commit comments

Comments
 (0)