Fix typos so that code properly compiles

This commit is contained in:
Blizzard Finnegan 2023-05-15 13:48:21 -04:00
parent 0df0316aac
commit f4741d3d8e
No known key found for this signature in database
GPG key ID: CA68D42A2F00D450
2 changed files with 5 additions and 9 deletions

View file

@ -41,9 +41,9 @@ fn main(){
let available_ttys = std::fs::read_dir("/dev/serial/by-id").unwrap();
let mut possible_devices:Vec<Option<Device>> = Vec::new();
let mut tty_test_threads:Vec<JoinHandle<Option<Device>>> = Vec::new();
for possible_tty in available_ttys.to_vec(){
for possible_tty in available_ttys.into_iter(){
tty_test_threads.push(thread::spawn(move ||{
let mut possible_port = TTY::new(possible_tty.as_ref().unwrap().path().to_str().as_ref());
let mut possible_port = TTY::new(possible_tty.as_ref().unwrap().path().to_str().unwrap());
log::info!("Testing port {}. This may take a moment...",possible_tty.as_ref().unwrap().path().to_string_lossy());
possible_port.write_to_device(tty::Command::Newline);
let response = possible_port.read_from_device(Some(":"));

View file

@ -86,20 +86,16 @@ impl std::fmt::Debug for TTY{
impl TTY{
pub fn new(serial_location:&str) -> Self{
if !AVAILABLE_TTYS.iter().any(|tty_info| tty_info.port_name == serial_location ) {
panic!("Invalid TTY init string!");
}
else {
return TTY {
TTY {
tty: serialport::new(serial_location,BAUD_RATE).timeout(SERIAL_READ_TIMEOUT).open().unwrap()
};
}
}
}
pub fn write_to_device(&mut self,command:Command) -> bool {
log::debug!("writing {:?} to tty {}...", command, self.tty.name().unwrap_or("unknown".to_string()));
let output = self.tty.write_all(COMMAND_MAP.get(&command).unwrap().as_bytes()).is_ok();
_ = self.tty.flush();
std::thread::sleep(std::time::Duration::from_millis(500));
return output;
}