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";
|
const UNINITIALISED_SERIAL: &str = "uninitialised";
|
||||||
#[derive(PartialEq,Debug)]
|
#[derive(PartialEq,Debug)]
|
||||||
pub enum State{
|
pub enum State{
|
||||||
|
Shutdown,
|
||||||
LoginPrompt,
|
LoginPrompt,
|
||||||
DebugMenu,
|
DebugMenu,
|
||||||
LifecycleMenu,
|
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{
|
fn go_to_brightness_menu(&mut self) -> &mut Self{
|
||||||
while !(self.current_state == State::BrightnessMenu){
|
while !(self.current_state == State::BrightnessMenu){
|
||||||
match self.current_state {
|
match self.current_state {
|
||||||
|
@ -182,6 +167,10 @@ impl Device{
|
||||||
_ = self.usb_tty.read_from_device(None);
|
_ = self.usb_tty.read_from_device(None);
|
||||||
self.current_state = State::DebugMenu;
|
self.current_state = State::DebugMenu;
|
||||||
},
|
},
|
||||||
|
State::Shutdown => {
|
||||||
|
while self.usb_tty.read_from_device(None) != Response::Rebooting {}
|
||||||
|
self.current_state = State::LoginPrompt;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return self;
|
return self;
|
||||||
|
@ -209,6 +198,10 @@ impl Device{
|
||||||
self.current_state = State::DebugMenu;
|
self.current_state = State::DebugMenu;
|
||||||
return self;
|
return self;
|
||||||
},
|
},
|
||||||
|
State::Shutdown => {
|
||||||
|
while self.usb_tty.read_from_device(None) != Response::Rebooting {}
|
||||||
|
self.current_state = State::LoginPrompt;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return self;
|
return self;
|
||||||
|
@ -236,6 +229,10 @@ impl Device{
|
||||||
_ = self.usb_tty.read_from_device(None);
|
_ = self.usb_tty.read_from_device(None);
|
||||||
self.current_state = State::DebugMenu;
|
self.current_state = State::DebugMenu;
|
||||||
},
|
},
|
||||||
|
State::Shutdown => {
|
||||||
|
while self.usb_tty.read_from_device(None) != Response::Rebooting {}
|
||||||
|
self.current_state = State::LoginPrompt;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return self;
|
return self;
|
||||||
|
@ -363,7 +360,11 @@ impl Device{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn reboot(&mut self) -> () {
|
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;
|
self.current_state = State::LoginPrompt;
|
||||||
}
|
}
|
||||||
pub fn is_rebooted(&mut self) -> bool {
|
pub fn is_rebooted(&mut self) -> bool {
|
||||||
|
@ -371,7 +372,7 @@ impl Device{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
self.go_to_login_prompt();
|
self.reboot();
|
||||||
self.reboots +=1;
|
self.reboots +=1;
|
||||||
self.save_values();
|
self.save_values();
|
||||||
return true;
|
return true;
|
||||||
|
@ -380,7 +381,7 @@ impl Device{
|
||||||
pub fn test_cycle(&mut self, bp_cycles: Option<u64>, temp_cycles: Option<u64>) -> () {
|
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_bp_cycles: u64 = bp_cycles.unwrap_or(3);
|
||||||
let local_temp_cycles: u64 = temp_cycles.unwrap_or(2);
|
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);
|
thread::sleep(BOOT_TIME);
|
||||||
self.go_to_lifecycle_menu();
|
self.go_to_lifecycle_menu();
|
||||||
_ = self.usb_tty.read_from_device(Some("["));
|
_ = 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] = [
|
const RESPONSES:[(&str,Response);10] = [
|
||||||
|
("reboot: Restarting",Response::Rebooting),
|
||||||
("login:",Response::LoginPrompt),
|
("login:",Response::LoginPrompt),
|
||||||
("Password:",Response::PasswordPrompt),
|
("Password:",Response::PasswordPrompt),
|
||||||
("root@",Response::ShellPrompt),
|
("root@",Response::ShellPrompt),
|
||||||
|
@ -69,7 +70,6 @@ const RESPONSES:[(&str,Response);10] = [
|
||||||
("Temp:",Response::TempSuccess),
|
("Temp:",Response::TempSuccess),
|
||||||
("> ",Response::DebugMenuWithContinuedMessage),
|
("> ",Response::DebugMenuWithContinuedMessage),
|
||||||
(">",Response::DebugMenuReady),
|
(">",Response::DebugMenuReady),
|
||||||
("[",Response::Rebooting),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
pub struct TTY{
|
pub struct TTY{
|
||||||
|
|
Loading…
Add table
Reference in a new issue