Add G0
This commit is contained in:
parent
826c9183e4
commit
797dd215d2
|
@ -19,7 +19,30 @@ async fn main() -> tokio_serial::Result<()> {
|
|||
.await
|
||||
.unwrap();
|
||||
loop {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
|
||||
printer
|
||||
.printer_in
|
||||
.send(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
|
||||
.printer_in
|
||||
.send(Box::new(G0Command {
|
||||
x: Some(25.0),
|
||||
y: Some(25.0),
|
||||
z: Some(5.0),
|
||||
e: None,
|
||||
velocity: None,
|
||||
}))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
38
red/src/printer/gcode/g0.rs
Normal file
38
red/src/printer/gcode/g0.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use super::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct G0Command {
|
||||
pub x: Option<f64>,
|
||||
pub y: Option<f64>,
|
||||
pub z: Option<f64>,
|
||||
pub e: Option<f64>,
|
||||
pub velocity: Option<f64>,
|
||||
}
|
||||
|
||||
impl GcodeCommand for G0Command {
|
||||
fn command(&self) -> String {
|
||||
fn unpack(letter: &str, o: Option<f64>) -> String {
|
||||
o.map(|x| format!("{}{:.3}", letter, x)).unwrap_or_default()
|
||||
}
|
||||
format!(
|
||||
"G0 {} {} {} {} {}",
|
||||
unpack("X", self.x),
|
||||
unpack("Y", self.y),
|
||||
unpack("Z", self.z),
|
||||
unpack("E", self.e),
|
||||
unpack("F", self.velocity)
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_reply(&self, reply: &str) -> Result<GcodeReply> {
|
||||
if reply.is_empty() {
|
||||
Ok(GcodeReply::NoReply)
|
||||
} else {
|
||||
Err(GcodeReplyError {
|
||||
sent_command: self.command(),
|
||||
parsed_input: reply.to_string(),
|
||||
problem: "Expected empty reply".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ impl GcodeCommand for G28Command {
|
|||
problem: "Expected no reply".to_string(),
|
||||
})
|
||||
} else {
|
||||
Ok(GcodeReply::G28Reply)
|
||||
Ok(GcodeReply::NoReply)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
mod g0;
|
||||
mod g28;
|
||||
mod m114;
|
||||
pub use g0::G0Command;
|
||||
pub use g28::G28Command;
|
||||
pub use m114::M114Command;
|
||||
use std::fmt::Debug;
|
||||
|
@ -9,7 +11,7 @@ type Result<T> = std::result::Result<T, GcodeReplyError>;
|
|||
#[derive(Debug)]
|
||||
pub enum GcodeReply {
|
||||
M114Reply { x: f64, y: f64, z: f64, e: f64 },
|
||||
G28Reply,
|
||||
NoReply,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
Loading…
Reference in a new issue