Skip to content

Commit

Permalink
feat: add gcode meta data, imp. rel. tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tirithen committed Apr 27, 2024
1 parent a3c675d commit e8ed51d
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 74 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ moby-name-gen = "0.1.0"
hostname = "0.4.0"
username = "0.2.0"

[dev-dependencies]
regex = "1.10.4"

[profile.release]
opt-level = 's'
lto = true
Expand Down
16 changes: 14 additions & 2 deletions src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,18 @@ mod tests {
let gcode = read_to_string("test-temp.gcode")?;
remove_file("test-temp.gcode")?;

assert_eq!(gcode, r#"G17
let pattern =
regex::Regex::new(r"\;\((Created\s+on|Created\s+by|Generator):\s*[^\)]+\)").unwrap();
let gcode = pattern.replace_all(&gcode, ";($1: MASKED)");

assert_eq!(gcode, r#"
;(Name: test-temp)
;(Created on: MASKED)
;(Created by: MASKED)
;(Generator: MASKED)
;(Workarea: size_x = 95 mm, size_y = 132 mm, size_z = 3.1 mm, min_x = -28 mm, min_y = -30 mm, max_z = 3 mm, z_safe = 10 mm, z_tool_change = 50 mm)
G17
;(Tool change: type = Cylindrical, diameter = 4 mm, length = 50 mm, direction = clockwise, spindle_speed = 5000 rpm, feed_rate = 400 mm/min)
G21
Expand All @@ -163,6 +174,7 @@ M5
T1 M6
S5000
M3
G4 P4
;(Cut path at: x = 0, y = 0)
G0 Z10
Expand Down Expand Up @@ -200,7 +212,7 @@ G1 X23 Y12 Z-0.1
G0 Z10
G0 Z50
M2"#.to_string());
M2"#.to_string().trim());

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
//! 20.0, // Cutter length
//! 10.0, // Cutter diameter
//! Direction::Clockwise, // Spindle rotation direction
//! 20000.0, // Spindle speed (rpm)
//! 5000.0, // Max feed rate/speed that the cutter will travel with (mm/min)
//! 10000.0, // Spindle speed (rpm)
//! 3000.0, // Max feed rate/speed that the cutter will travel with (mm/min)
//! );
//!
//! // Get the tool context to extend the program
Expand All @@ -57,7 +57,7 @@
//! // Write the G-code (for CNC) `planing.gcode` and Camotics project file
//! // `planing.camotics` (for simulation) to disk using a resolution value
//! // of 0.5 for the Camotics simulation.
//! write_project("planing", &program, 0.5)?;
//! write_project(&program, 0.5)?;
//!
//! Ok(())
//! }
Expand Down
Loading

0 comments on commit e8ed51d

Please sign in to comment.