v2.1.0 #3
2 changed files with 31 additions and 16 deletions
|
@ -284,6 +284,9 @@ impl Device{
|
|||
pub fn get_serial(&mut self) -> &str{
|
||||
&self.serial
|
||||
}
|
||||
pub fn get_location(&mut self) -> String{
|
||||
std::format!("{:?}",self.usb_tty)
|
||||
}
|
||||
pub fn set_pin_address(&mut self, address:u8) -> &mut Self{
|
||||
self.address = Some(address.clone());
|
||||
let temp = self.gpio.get(address);
|
||||
|
|
44
src/main.rs
44
src/main.rs
|
@ -61,7 +61,10 @@ fn main(){
|
|||
log::debug!("{} is valid port!",tty_name);
|
||||
let new_device = Device::new(port,Some(response));
|
||||
match new_device{
|
||||
Ok(device) => Some(device),
|
||||
Ok(mut device) => {
|
||||
device.darken_screen();
|
||||
Some(device)
|
||||
},
|
||||
Err(_) => None
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +74,6 @@ fn main(){
|
|||
}
|
||||
},
|
||||
Err(error)=>{
|
||||
//log::warn!("Invalid TTY location");
|
||||
log::debug!("{}",error);
|
||||
None
|
||||
}
|
||||
|
@ -90,28 +92,23 @@ fn main(){
|
|||
}
|
||||
}
|
||||
|
||||
log::info!("\n\n--------------------------------------");
|
||||
log::info!("Number of devices detected: {}",devices.len());
|
||||
log::info!("--------------------------------------\n\n");
|
||||
|
||||
log::info!("Dimming all screens...");
|
||||
for device in devices.iter_mut(){
|
||||
device.darken_screen();
|
||||
}
|
||||
//log::info!("Dimming all screens...");
|
||||
//for device in devices.iter_mut(){
|
||||
// device.darken_screen();
|
||||
//}
|
||||
|
||||
for device in devices.iter_mut(){
|
||||
device.brighten_screen()
|
||||
.set_serial(&input_filtering(Some("Enter the serial of the device with the bright screen: ")).to_string())
|
||||
.darken_screen();
|
||||
log::debug!("Number of unassigned addresses: {}",gpio.get_unassigned_addresses().len());
|
||||
for &address in gpio.get_unassigned_addresses(){
|
||||
device.set_pin_address(address).start_temp();
|
||||
if device.is_temp_running(){
|
||||
device.stop_temp();
|
||||
gpio.remove_address(address);
|
||||
break;
|
||||
}
|
||||
else{
|
||||
device.stop_temp();
|
||||
}
|
||||
if !find_gpio(device, gpio){
|
||||
device.set_pin_address(21);
|
||||
log::error!("Unable to find GPIO for device {}. Please ensure that the probe well is installed properly, and the calibration key is plugged in.",device.get_location());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,6 +137,21 @@ fn main(){
|
|||
}
|
||||
}
|
||||
|
||||
fn find_gpio(device:&mut Device,gpio:&mut GpioPins) -> bool{
|
||||
for &address in gpio.get_unassigned_addresses(){
|
||||
device.set_pin_address(address).start_temp();
|
||||
if device.is_temp_running(){
|
||||
device.stop_temp();
|
||||
gpio.remove_address(address);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
device.stop_temp();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn setup_logs(){
|
||||
let chrono_now: DateTime<Local> = Local::now();
|
||||
if ! Path::new("logs").is_dir(){
|
||||
|
|
Loading…
Add table
Reference in a new issue