Adds basic documentation to some functions

master
Loren Rogers 5 years ago
parent f19992a536
commit d5cb2e0306

@ -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 { pub fn validate_gcode(gcode: &&str) -> bool {
use regex::Regex; use regex::Regex;
let re = Regex::new(r##"^(?:(?:%|\(.*\)|(?:[A-Z^E^U][+-]?\d+(?:\.\d*)?))\h*)*$"##).unwrap(); let re = Regex::new(r##"^(?:(?:%|\(.*\)|(?:[A-Z^E^U][+-]?\d+(?:\.\d*)?))\h*)*$"##).unwrap();

@ -1,6 +1,10 @@
/// State machine used to generate gcode for various operations.
///
/// TODO: more detailed examples
use crate::code::*; 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 { pub struct Machine {
tool_state: Option<Tool>, tool_state: Option<Tool>,
distance_mode: Option<Distance>, distance_mode: Option<Distance>,
@ -8,6 +12,7 @@ pub struct Machine {
pub tool_off_action: Vec<GCode>, pub tool_off_action: Vec<GCode>,
} }
// Assigns reasonable default settings that apply to most gcode applications.
impl Default for Machine { impl Default for Machine {
fn default() -> Self { fn default() -> Self {
Self { Self {
@ -33,7 +38,9 @@ impl Default for Machine {
} }
} }
// Implements the state machine functions
impl Machine { impl Machine {
// Outputs gcode to turn the tool on.
pub fn tool_on(&mut self) -> Vec<GCode> { pub fn tool_on(&mut self) -> Vec<GCode> {
if self.tool_state == Some(Tool::Off) || self.tool_state == None { if self.tool_state == Some(Tool::Off) || self.tool_state == None {
self.tool_state = Some(Tool::On); 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<GCode> { pub fn tool_off(&mut self) -> Vec<GCode> {
if self.tool_state == Some(Tool::On) || self.tool_state == None { if self.tool_state == Some(Tool::On) || self.tool_state == None {
self.tool_state = Some(Tool::Off); 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<GCode> { pub fn distance(&mut self, is_absolute: bool) -> Vec<GCode> {
if is_absolute { if is_absolute {
self.absolute() self.absolute()
@ -60,6 +69,7 @@ impl Machine {
} }
} }
// Outputs gcode command to use absolute motion
pub fn absolute(&mut self) -> Vec<GCode> { pub fn absolute(&mut self) -> Vec<GCode> {
if self.distance_mode == Some(Distance::Incremental) || self.distance_mode == None { if self.distance_mode == Some(Distance::Incremental) || self.distance_mode == None {
self.distance_mode = Some(Distance::Absolute); 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<GCode> { pub fn incremental(&mut self) -> Vec<GCode> {
if self.distance_mode == Some(Distance::Absolute) || self.distance_mode == None { if self.distance_mode == Some(Distance::Absolute) || self.distance_mode == None {
self.distance_mode = Some(Distance::Incremental); self.distance_mode = Some(Distance::Incremental);

Loading…
Cancel
Save