Move mains to their own functions

This commit is contained in:
Frederik Menke 2023-08-26 21:13:48 +02:00
parent 742dfddce1
commit 54b51b50ba

View file

@ -9,43 +9,53 @@ const DEFAULT_TTY: &str = "/dev/ttyUSB0";
#[tokio::main]
async fn main() -> Never {
communicate().await
}
async fn communicate() -> Never {
let mut printer = Printer::connect(DEFAULT_TTY).await.unwrap();
printer
.send_gcode(Box::new(M114Command::new()))
.await
.unwrap();
printer
.send_gcode(Box::new(G28Command::new(true, true, true)))
.await
.unwrap();
loop {
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
printer
.send_gcode(Box::new(G0Command {
x: Some(50.0),
y: Some(50.0),
z: Some(5.0),
e: None,
velocity: None,
}))
.await
.unwrap();
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
printer
.send_gcode(Box::new(G0Command {
x: Some(25.0),
y: Some(25.0),
z: Some(5.0),
e: None,
velocity: None,
}))
.await
.unwrap();
}
}
async fn jog() -> Never {
let jogger = jogger::Jogger::new().await.unwrap();
loop {
tokio::time::sleep(Duration::from_secs(2)).await;
let setpoint = jogger.speed_setpoint();
println!("speed setpoint: {} {} {}", setpoint.0, setpoint.1, setpoint.2);
println!(
"speed setpoint: {} {} {}",
setpoint.0, setpoint.1, setpoint.2
);
}
// let mut printer = Printer::connect(DEFAULT_TTY).await.unwrap();
// printer
// .send_gcode(Box::new(M114Command::new()))
// .await
// .unwrap();
// printer
// .send_gcode(Box::new(G28Command::new(true, true, true)))
// .await
// .unwrap();
// loop {
// tokio::time::sleep(std::time::Duration::from_secs(5)).await;
// printer
// .send_gcode(Box::new(G0Command {
// x: Some(50.0),
// y: Some(50.0),
// z: Some(5.0),
// e: None,
// velocity: None,
// }))
// .await
// .unwrap();
// tokio::time::sleep(std::time::Duration::from_secs(5)).await;
// printer
// .send_gcode(Box::new(G0Command {
// x: Some(25.0),
// y: Some(25.0),
// z: Some(5.0),
// e: None,
// velocity: None,
// }))
// .await
// .unwrap();
// }
}