diff --git a/src/code.rs b/src/code.rs index dcf81ce..f4883f6 100644 --- a/src/code.rs +++ b/src/code.rs @@ -58,7 +58,7 @@ macro_rules! write_if_some { }; } -/// Rudimentary regular expression GCode validator. +// Rudimentary regular expression GCode validator. pub fn validate_gcode(gcode: &&str) -> bool { use regex::Regex; let re = Regex::new(r##"^(?:(?:%|\(.*\)|(?:[A-Z^E^U][+-]?\d+(?:\.\d*)?))\h*)*$"##).unwrap(); diff --git a/src/machine.rs b/src/machine.rs index 5e03a40..92ff56f 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1,6 +1,10 @@ +/// State machine used to generate gcode for various operations. +/// +/// TODO: more detailed examples + use crate::code::*; -/// Generic machine state simulation, assuming nothing is known about the machine when initialized. +// Generic machine state simulation, assuming nothing is known about the machine when initialized. pub struct Machine { tool_state: Option, distance_mode: Option, @@ -8,6 +12,7 @@ pub struct Machine { pub tool_off_action: Vec, } +// Assigns reasonable default settings that apply to most gcode applications. impl Default for Machine { fn default() -> Self { Self { @@ -33,7 +38,9 @@ impl Default for Machine { } } +// Implements the state machine functions impl Machine { + // Outputs gcode to turn the tool on. pub fn tool_on(&mut self) -> Vec { if self.tool_state == Some(Tool::Off) || self.tool_state == None { self.tool_state = Some(Tool::On); @@ -43,6 +50,7 @@ impl Machine { } } + // Outputs gcode to turn the tool off. pub fn tool_off(&mut self) -> Vec { if self.tool_state == Some(Tool::On) || self.tool_state == None { self.tool_state = Some(Tool::Off); @@ -52,6 +60,7 @@ impl Machine { } } + // Outputs gcode for how distance should be measured: relative or absolute. pub fn distance(&mut self, is_absolute: bool) -> Vec { if is_absolute { self.absolute() @@ -60,6 +69,7 @@ impl Machine { } } + // Outputs gcode command to use absolute motion pub fn absolute(&mut self) -> Vec { if self.distance_mode == Some(Distance::Incremental) || self.distance_mode == None { self.distance_mode = Some(Distance::Absolute); @@ -69,6 +79,7 @@ impl Machine { } } + // Outputs gcode command to use relative motion pub fn incremental(&mut self) -> Vec { if self.distance_mode == Some(Distance::Absolute) || self.distance_mode == None { self.distance_mode = Some(Distance::Incremental);