diff --git a/src/device.rs b/src/device.rs index 9ba594a..10e43a2 100755 --- a/src/device.rs +++ b/src/device.rs @@ -5,7 +5,6 @@ use rppal::gpio::{Gpio,OutputPin}; const BP_RUN_1:Duration = Duration::from_secs(29); const TEMP_WAIT:Duration = Duration::from_secs(3); const BP_RUN_2:Duration = Duration::from_secs(28); -const LOGIN_WAIT:Duration = Duration::from_secs(1); const REBOOTS_SECTION: &str = "Reboots: "; const BP_SECTION: &str = "Successful BP tests: "; const TEMP_SECTION: &str = "Successful temp tests: "; @@ -165,14 +164,13 @@ impl Device{ }, State::LoginPrompt => { self.usb_tty.write_to_device(Command::Login); - thread::sleep(LOGIN_WAIT); _ = self.usb_tty.read_from_device(None); self.usb_tty.write_to_device(Command::DebugMenu); _ = self.usb_tty.read_from_device(None); self.current_state = State::DebugMenu; }, State::Shutdown => { - while self.usb_tty.read_from_device(None) != Response::Rebooting {} + while self.usb_tty.read_from_device(None) != Response::LoginPrompt{} self.current_state = State::LoginPrompt; }, }; @@ -196,7 +194,6 @@ impl Device{ }, State::LoginPrompt => { self.usb_tty.write_to_device(Command::Login); - thread::sleep(LOGIN_WAIT); _ = self.usb_tty.read_from_device(None); self.usb_tty.write_to_device(Command::DebugMenu); _ = self.usb_tty.read_from_device(None); @@ -204,7 +201,7 @@ impl Device{ return self; }, State::Shutdown => { - while self.usb_tty.read_from_device(None) != Response::Rebooting {} + while self.usb_tty.read_from_device(None) != Response::LoginPrompt {} self.current_state = State::LoginPrompt; }, }; @@ -229,14 +226,13 @@ impl Device{ }, State::LoginPrompt => { self.usb_tty.write_to_device(Command::Login); - thread::sleep(LOGIN_WAIT); _ = self.usb_tty.read_from_device(None); self.usb_tty.write_to_device(Command::DebugMenu); _ = self.usb_tty.read_from_device(None); self.current_state = State::DebugMenu; }, State::Shutdown => { - while self.usb_tty.read_from_device(None) != Response::Rebooting {} + while self.usb_tty.read_from_device(None) != Response::LoginPrompt {} self.current_state = State::LoginPrompt; }, }; diff --git a/src/tty.rs b/src/tty.rs index 49df070..87dea27 100755 --- a/src/tty.rs +++ b/src/tty.rs @@ -111,6 +111,7 @@ impl TTY{ 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(); + if command == Command::Login { std::thread::sleep(std::time::Duration::from_secs(2)); } std::thread::sleep(std::time::Duration::from_millis(500)); return output; } @@ -141,6 +142,11 @@ impl TTY{ } } } + else if enum_value == Response::PasswordPrompt { + log::error!("Recieved password prompt on device {}! Something fell apart here. Check preceeding log lines.",self.tty.name().unwrap_or("unknown shell".to_string())); + self.write_to_device(Command::Newline); + _ = self.read_from_device(None); + } else{ return enum_value; }