diff --git a/src/modem.rs b/src/modem.rs index 51da832..e019ca0 100644 --- a/src/modem.rs +++ b/src/modem.rs @@ -62,7 +62,7 @@ impl Iterator for IterableRx { break None } thread::sleep(Duration::from_millis(200)); - self.timeout = Some(timeout - now.elapsed()); + self.timeout = Some(timeout.saturating_sub(now.elapsed())); } } } @@ -140,7 +140,7 @@ impl Modem { let match_text: String = contains.unwrap_or("\n".to_string()); loop { - let rdln = self.read_line(start + timeout - Instant::now()); + let rdln = self.read_line(timeout.saturating_sub(start.elapsed())); if let Ok(line) = rdln { println!("Read {} bytes from serial ({})", line.len(), line); response.push_str(&line);