Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for gcode_macro #30

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ license = "MIT"
nom = "7"
lexical-core = "^0.7"
serde = { version = "^1", features = ["derive"] }
glam = { version = "0.20", features = ["serde"] }
glam = { version = "0.21", features = ["serde"] }
thiserror = "1"
regex = "1"
lazy_static = "1"
minijinja = { version = "^0.18", default-features = false, features = ["source", "sync", "debug"] }
serde_json = "^1"
2 changes: 1 addition & 1 deletion lib/src/firmware_retraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct FirmwareRetractionOptions {
pub lift_z: f64,
}

#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub enum FirmwareRetractionState {
Unretracted,
Retracted {
Expand Down
9 changes: 5 additions & 4 deletions lib/src/gcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::BTreeMap;
use std::fmt::Display;
use std::io::{self, BufRead};

use serde::Serialize;
use thiserror::Error;

#[derive(Debug, PartialEq, PartialOrd, Clone)]
Expand Down Expand Up @@ -81,7 +82,7 @@ impl Display for GCodeOperation {
}
}

#[derive(Debug, PartialEq, PartialOrd, Clone)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)]
pub struct GCodeTraditionalParams(Vec<(char, String)>);

impl GCodeTraditionalParams {
Expand Down Expand Up @@ -121,7 +122,7 @@ impl Display for GCodeTraditionalParams {
}
}

#[derive(Debug, PartialEq, PartialOrd, Clone)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, Serialize)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to add a to_map or similar function that the caller can then serialize after. Doesn't feel right to need this to be Serialize within gcode.rs. A better option still is likely to add a wrapper in macros.rs. This wrapper can implement minijinja::value::Object and call directly to getters without going through a serialization step.

pub struct GCodeExtendedParams(BTreeMap<String, String>);

impl GCodeExtendedParams {
Expand Down Expand Up @@ -279,7 +280,7 @@ mod parser {
fn parse(s: &str) -> IResult<&str, GCodeCommand> {
let (s, _) = space0(s)?;

let (s, _line_no) = opt(line_number)(s)?;
// let (s, _line_no) = opt(line_number)(s)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an issue with this?


let (s, (op, comment)) = alt((
complete(traditional_gcode),
Expand Down Expand Up @@ -314,7 +315,7 @@ mod parser {
}

fn traditional_gcode(s: &str) -> IResult<&str, (GCodeOperation, Option<&str>)> {
let (s, letter) = satisfy(|c| c.is_alphabetic())(s)?;
let (s, letter) = satisfy(|c| matches!(c.to_ascii_lowercase(), 'g' | 'm'))(s)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not good, as e.g. tool selections fall under "traditional gcode" as well. Why was this change needed?

let (s, code) = match lexical_core::parse_partial::<u16>(s.as_bytes()) {
Ok((_, 0)) => return Err(Err::Error(Error::from_error_kind(s, ErrorKind::Digit))),
Ok((value, processed)) => (s.slice(processed..), value),
Expand Down
1 change: 1 addition & 0 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate lazy_static;
pub mod firmware_retraction;
pub mod gcode;
mod kind_tracker;
mod macros;
pub mod planner;
pub mod slicer;

Expand Down
Loading