diff --git a/src/device.rs b/src/device.rs index 256b6b5..c5deb03 100755 --- a/src/device.rs +++ b/src/device.rs @@ -11,6 +11,7 @@ const OUTPUT_FOLDER: &str = "output/"; const UNINITIALISED_SERIAL: &str = "uninitialised"; #[derive(PartialEq,Debug)] pub enum State{ + Shutdown, LoginPrompt, DebugMenu, LifecycleMenu, @@ -144,22 +145,6 @@ impl Device{ } } - fn go_to_login_prompt(&mut self) -> &mut Self{ - while !(self.current_state == State::LoginPrompt){ - match self.current_state { - State::LoginPrompt => return self, - State::DebugMenu | State::LifecycleMenu | State::BrightnessMenu => { - self.usb_tty.write_to_device(Command::Quit); - _ = self.usb_tty.read_from_device(None); - self.current_state = State::LoginPrompt; - self.reboots+=1; - return self; - }, - }; - }; - return self; - } - fn go_to_brightness_menu(&mut self) -> &mut Self{ while !(self.current_state == State::BrightnessMenu){ match self.current_state { @@ -182,6 +167,10 @@ impl Device{ _ = self.usb_tty.read_from_device(None); self.current_state = State::DebugMenu; }, + State::Shutdown => { + while self.usb_tty.read_from_device(None) != Response::Rebooting {} + self.current_state = State::LoginPrompt; + }, }; }; return self; @@ -209,6 +198,10 @@ impl Device{ self.current_state = State::DebugMenu; return self; }, + State::Shutdown => { + while self.usb_tty.read_from_device(None) != Response::Rebooting {} + self.current_state = State::LoginPrompt; + }, }; }; return self; @@ -236,6 +229,10 @@ impl Device{ _ = self.usb_tty.read_from_device(None); self.current_state = State::DebugMenu; }, + State::Shutdown => { + while self.usb_tty.read_from_device(None) != Response::Rebooting {} + self.current_state = State::LoginPrompt; + }, }; }; return self; @@ -363,7 +360,11 @@ impl Device{ } } pub fn reboot(&mut self) -> () { - self.go_to_login_prompt(); + //self.go_to_login_prompt(); + self.usb_tty.write_to_device(Command::Quit); + while self.usb_tty.read_from_device(None) != Response::Rebooting {} + self.current_state = State::Shutdown; + while self.usb_tty.read_from_device(None) != Response::LoginPrompt {} self.current_state = State::LoginPrompt; } pub fn is_rebooted(&mut self) -> bool { @@ -371,7 +372,7 @@ impl Device{ return true; } else{ - self.go_to_login_prompt(); + self.reboot(); self.reboots +=1; self.save_values(); return true; @@ -380,7 +381,7 @@ impl Device{ pub fn test_cycle(&mut self, bp_cycles: Option, temp_cycles: Option) -> () { let local_bp_cycles: u64 = bp_cycles.unwrap_or(3); let local_temp_cycles: u64 = temp_cycles.unwrap_or(2); - self.go_to_login_prompt(); + if self.current_state != State::LoginPrompt { self.reboot(); } thread::sleep(BOOT_TIME); self.go_to_lifecycle_menu(); _ = self.usb_tty.read_from_device(Some("[")); diff --git a/src/tty.rs b/src/tty.rs index 3281325..75a1a29 100755 --- a/src/tty.rs +++ b/src/tty.rs @@ -60,6 +60,7 @@ const COMMAND_MAP:Lazy> = Lazy::new(||HashMap::from([ ])); const RESPONSES:[(&str,Response);10] = [ + ("reboot: Restarting",Response::Rebooting), ("login:",Response::LoginPrompt), ("Password:",Response::PasswordPrompt), ("root@",Response::ShellPrompt), @@ -69,7 +70,6 @@ const RESPONSES:[(&str,Response);10] = [ ("Temp:",Response::TempSuccess), ("> ",Response::DebugMenuWithContinuedMessage), (">",Response::DebugMenuReady), - ("[",Response::Rebooting), ]; pub struct TTY{