Start wrapping up device file
This commit is contained in:
parent
32b642263f
commit
48d4f9291b
1 changed files with 83 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
use rppal::gpio::OutputPin;
|
||||
use std::{fs::{self, File}, path::Path, io::{BufReader, BufRead}};
|
||||
use crate::tty;
|
||||
use crate::{tty, gpio_facade::gpio_facade};
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum State{
|
||||
|
@ -101,13 +101,94 @@ impl Device{
|
|||
self.usb_tty.write_to_device(tty::Command::Login);
|
||||
self.usb_tty.write_to_device(tty::Command::DebugMenu);
|
||||
self.current_state = State::DebugMenu;
|
||||
return;
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
fn go_to_debug_menu(&mut self) -> (){
|
||||
while !(self.current_state == State::DebugMenu){
|
||||
match self.current_state {
|
||||
State::DebugMenu => return,
|
||||
State::BrightnessMenu => {
|
||||
self.usb_tty.write_to_device(tty::Command::UpMenuLevel);
|
||||
self.current_state = State::LifecycleMenu;
|
||||
},
|
||||
State::LifecycleMenu =>{
|
||||
self.usb_tty.write_to_device(tty::Command::UpMenuLevel);
|
||||
self.current_state = State::BrightnessMenu;
|
||||
},
|
||||
State::LoginPrompt => {
|
||||
self.usb_tty.write_to_device(tty::Command::Login);
|
||||
self.usb_tty.write_to_device(tty::Command::DebugMenu);
|
||||
self.current_state = State::DebugMenu;
|
||||
return;
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
fn go_to_lifecycle_menu(&mut self) -> (){
|
||||
while !(self.current_state == State::LifecycleMenu){
|
||||
match self.current_state {
|
||||
State::LifecycleMenu => return,
|
||||
State::DebugMenu => {
|
||||
self.usb_tty.write_to_device(tty::Command::LifecycleMenu);
|
||||
self.current_state = State::LifecycleMenu;
|
||||
return;
|
||||
},
|
||||
State::BrightnessMenu =>{
|
||||
self.usb_tty.write_to_device(tty::Command::UpMenuLevel);
|
||||
self.current_state = State::BrightnessMenu;
|
||||
},
|
||||
State::LoginPrompt => {
|
||||
self.usb_tty.write_to_device(tty::Command::Login);
|
||||
self.usb_tty.write_to_device(tty::Command::DebugMenu);
|
||||
self.current_state = State::DebugMenu;
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
pub fn set_serial(&mut self, serial:&str) -> (){}
|
||||
pub fn set_gpio(&mut self, gpio_pin: OutputPin) -> (){}
|
||||
pub fn start_temp(&mut self) -> () {}
|
||||
pub fn stop_temp(&mut self) -> () {}
|
||||
pub fn start_bp(&mut self) -> () {
|
||||
self.go_to_lifecycle_menu();
|
||||
self.usb_tty.write_to_device(tty::Command::StartBP);
|
||||
_ = self.usb_tty.read_from_device(None);
|
||||
}
|
||||
pub fn darken_screen(&mut self) -> () {
|
||||
self.go_to_brightness_menu();
|
||||
self.usb_tty.write_to_device(tty::Command::BrightnessLow);
|
||||
_ = self.usb_tty.read_from_device(None);
|
||||
self.usb_tty.write_to_device(tty::Command::RedrawMenu);
|
||||
_ = self.usb_tty.read_from_device(None);
|
||||
}
|
||||
pub fn brighten_screen(&mut self) -> () {
|
||||
self.go_to_brightness_menu();
|
||||
self.usb_tty.write_to_device(tty::Command::BrightnessHigh);
|
||||
_ = self.usb_tty.read_from_device(None);
|
||||
self.usb_tty.write_to_device(tty::Command::RedrawMenu);
|
||||
_ = self.usb_tty.read_from_device(None);
|
||||
}
|
||||
pub fn is_temp_running(&mut self) -> bool {
|
||||
self.go_to_lifecycle_menu();
|
||||
self.usb_tty.write_to_device(tty::Command::ReadTemp);
|
||||
match self.usb_tty.read_from_device(None){
|
||||
tty::Response::TempSuccess => return true,
|
||||
_ => return false
|
||||
}
|
||||
}
|
||||
pub fn reboot(&mut self) -> () {}
|
||||
pub fn is_rebooted(&mut self) -> bool {
|
||||
if self.current_state == State::LoginPrompt{
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
self.go_to_login_prompt();
|
||||
self.reboots +=1;
|
||||
//Write values to file
|
||||
return true;
|
||||
}
|
||||
}
|
||||
pub fn test_cycle(&mut self, bp_cycles: Option<u64>, temp_cycles: Option<u64>) -> () {}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue