Start dealing with reboot
This commit is contained in:
parent
7cf87ee58a
commit
c38b476f9f
2 changed files with 21 additions and 20 deletions
|
@ -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("["));
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Add table
Reference in a new issue