Require Send and Debug on GcodeCommand not on mpsc

This commit is contained in:
Frederik Menke 2022-10-22 19:43:03 +02:00
parent 13781bd29e
commit c6c0f65f7a
2 changed files with 8 additions and 3 deletions

View file

@ -1,7 +1,9 @@
use std::fmt::Debug;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
pub trait GcodeCommand { pub trait GcodeCommand: Debug + Send {
fn command(&self) -> &str; fn command(&self) -> &str;
fn parse_reply(&self, reply: &str) -> GcodeReply; fn parse_reply(&self, reply: &str) -> GcodeReply;
} }

View file

@ -21,7 +21,7 @@ pub struct State {
} }
pub struct Printer { pub struct Printer {
pub printer_in: Sender<Box<dyn GcodeCommand + Send>>, pub printer_in: Sender<Box<dyn GcodeCommand>>,
pub state: Rc<State>, pub state: Rc<State>,
} }
@ -35,9 +35,12 @@ impl Printer {
.expect("Unable to set serial port exclusive to false"); .expect("Unable to set serial port exclusive to false");
let connection = LineCodec.framed(port); let connection = LineCodec.framed(port);
let (tx, mut rx) = channel::<Box<dyn GcodeCommand + Send>>(32); let (tx, mut rx) = channel::<Box<dyn GcodeCommand>>(32);
tokio::spawn(async move { tokio::spawn(async move {
let (mut printer_tx, mut printer_rx) = connection.split(); let (mut printer_tx, mut printer_rx) = connection.split();
// The printer will send some info after connecting. We need to wait for this
// to be received as it will otherwise stop responding for some reason:
while let Some(stuff) = printer_rx.next().await { while let Some(stuff) = printer_rx.next().await {
if stuff.map(|s| s.contains("Loaded")).unwrap_or(false) { if stuff.map(|s| s.contains("Loaded")).unwrap_or(false) {
break; break;