Start dealing with reboot
All checks were successful
Basic Cargo Checks / docker-build (push) Successful in 3m55s
Basic Cargo Checks / docker-check (push) Successful in 11m29s

This commit is contained in:
Blizzard Finnegan 2023-06-12 16:06:23 -04:00
parent 7cf87ee58a
commit c38b476f9f
Signed by: blizzardfinnegan
GPG key ID: 61C1E13067E0018E
2 changed files with 21 additions and 20 deletions

View file

@ -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<u64>, temp_cycles: Option<u64>) -> () {
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("["));

View file

@ -60,6 +60,7 @@ const COMMAND_MAP:Lazy<HashMap<Command,&str>> = 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{