Accumulate printer reply until ok is sent

This commit is contained in:
Frederik Menke 2022-10-27 22:00:56 +02:00
parent a9dcb7e517
commit 7bf752828f

View file

@ -72,17 +72,19 @@ impl Printer {
while let Some(command) = printer_in_rx.recv().await {
let command_text = format!("{}\n", command.command());
serial_tx.send(command_text).await.unwrap();
while let Some(reply) = serial_rx.next().await {
let reply = reply.unwrap();
if reply.contains("ok") {
break;
} else {
let mut reply = "".to_string();
while let Some(line) = serial_rx.next().await {
let line = line.unwrap();
if line.contains("ok") {
let reply = command.parse_reply(&reply);
println!("got reply: {:?}", reply);
printer_out_tx
.send(reply.map_err(PrinterError::GcodeReply))
.await
.unwrap();
break;
} else {
reply.push_str(&line);
}
}
}