Detect serial port path automatically
This commit is contained in:
parent
594a31d983
commit
8d74ff0942
|
@ -1,6 +1,6 @@
|
|||
use crate::gamepad::Gamepad;
|
||||
use crate::printer::gcode::{G0Command, G91Command};
|
||||
use crate::printer::{GcodeCommand, Printer};
|
||||
use crate::printer::{Printer};
|
||||
use euclid::{vec3, Vector3D};
|
||||
use futures::never::Never;
|
||||
use std::sync::Arc;
|
||||
|
|
|
@ -5,7 +5,9 @@ use red::gamepad;
|
|||
use red::jogger;
|
||||
use red::printer::gcode::*;
|
||||
use red::printer::Printer;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use tokio_serial::SerialPortInfo;
|
||||
|
||||
const DEFAULT_TTY: &str = "/dev/ttyUSB0";
|
||||
const I2C_ADDRESS_EXTENDER: u8 = 25;
|
||||
|
@ -35,9 +37,22 @@ const I2C_REGISTER_SPINDLE_SPEED: u8 = 0;
|
|||
#[tokio::main]
|
||||
async fn main() -> Never {
|
||||
println!("Entering App");
|
||||
let serial_ports = tokio_serial::available_ports()
|
||||
.expect("Could not list serial ports")
|
||||
.into_iter()
|
||||
.filter(|port| port.port_name.contains("ttyUSB"))
|
||||
.collect::<Vec<SerialPortInfo>>();
|
||||
let port = match serial_ports.len() {
|
||||
1 => serial_ports.to_owned().pop().unwrap(),
|
||||
0 => panic!("No USB serial port found! Is the green board disconnected or turned off?"),
|
||||
_ => panic!("There are multiple USB serial ports and we have no way to check which one is the Marlin board!")
|
||||
};
|
||||
let port_path = Path::new("/dev").join(Path::new(&port.port_name).file_name().unwrap());
|
||||
println!("Found serial port: {:?}", &port_path);
|
||||
let gamepad = gamepad::Gamepad::new().await.unwrap();
|
||||
let printer = Printer::connect("/dev/ttyUSB2").await.unwrap();
|
||||
// TODO: Make printer do relative movements
|
||||
let printer = Printer::connect(&port_path.as_os_str().to_string_lossy())
|
||||
.await
|
||||
.unwrap();
|
||||
jogger::jog(gamepad, printer).await
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ use tokio_util::codec::{Decoder, Encoder};
|
|||
|
||||
pub use gcode::{GcodeCommand, GcodeReply};
|
||||
|
||||
use crate::printer::gcode::{G91Command, M997Command};
|
||||
use crate::printer::gcode::G91Command;
|
||||
|
||||
use self::gcode::GcodeReplyError;
|
||||
|
||||
|
|
Loading…
Reference in a new issue