summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Porte <microjoe@microjoe.org>2018-09-22 11:09:22 +0200
committerRomain Porte <microjoe@microjoe.org>2018-09-22 11:09:25 +0200
commit8998066f4b203bea883690737d8d28d4281d1611 (patch)
tree57070114feb85adda582a26e5cca57836e13f47d
downloademilly-8998066f4b203bea883690737d8d28d4281d1611.tar.gz
emilly-8998066f4b203bea883690737d8d28d4281d1611.zip
initial commit
-rw-r--r--.gitignore2
-rw-r--r--Cargo.lock155
-rw-r--r--Cargo.toml8
-rw-r--r--src/main.rs80
-rw-r--r--test.gc8
5 files changed, 253 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..53eaa21
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/target
+**/*.rs.bk
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..7278c1c
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,155 @@
+[[package]]
+name = "ansi_term"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "arrayvec"
+version = "0.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "atty"
+version = "0.2.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
+ "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "bitflags"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "clap"
+version = "2.32.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "emilly"
+version = "0.1.0"
+dependencies = [
+ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gcode 0.3.2-alpha.0 (git+https://github.com/Michael-F-Bryan/gcode-rs/)",
+]
+
+[[package]]
+name = "gcode"
+version = "0.3.2-alpha.0"
+source = "git+https://github.com/Michael-F-Bryan/gcode-rs/#4dc460c494609c2d0d1a488cb7813568f1e42e16"
+dependencies = [
+ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.43"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "nodrop"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "redox_syscall"
+version = "0.1.40"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "redox_termios"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "strsim"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "termion"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "textwrap"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "unicode-width"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "vec_map"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
+"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
+"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
+"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
+"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
+"checksum gcode 0.3.2-alpha.0 (git+https://github.com/Michael-F-Bryan/gcode-rs/)" = "<none>"
+"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
+"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
+"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
+"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
+"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
+"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
+"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
+"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
+"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
+"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
+"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..4406e2f
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "emilly"
+version = "0.1.0"
+authors = ["Romain Porte <microjoe@microjoe.org>"]
+
+[dependencies]
+clap = "2.32.*"
+gcode = { git = "https://github.com/Michael-F-Bryan/gcode-rs/" }
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..47262c6
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,80 @@
+extern crate clap;
+extern crate gcode;
+
+use std::io;
+use std::io::prelude::*;
+
+use clap::{App, Arg, SubCommand};
+use gcode::*;
+
+fn translate(mut gcode: Gcode, letter: char, offset: f32) -> Gcode {
+ for arg in gcode.args_mut() {
+ if arg.letter == letter {
+ arg.value += offset;
+ }
+ }
+ gcode
+}
+
+fn translate_optional(gcode: Gcode, letter: char, offset: Option<f32>) -> Gcode {
+ match offset {
+ Some(offset) => translate(gcode, letter, offset),
+ None => gcode
+ }
+}
+
+fn read_stdin() -> io::Result<String> {
+ let mut buffer = String::new();
+ let stdin = io::stdin();
+ let mut handle = stdin.lock();
+
+ handle.read_to_string(&mut buffer)?;
+ Ok(buffer)
+}
+
+fn parse_float_opt(matches: &clap::ArgMatches, letter: &str) -> Option<f32> {
+ matches.value_of(letter)
+ .map(|v| v.parse().expect(&format!("could not parse {}", letter)))
+}
+
+fn main() {
+ let matches = App::new("emilly")
+ .version("1.0")
+ .about("A simple gcode processor")
+ .author("Romain Porte <microjoe@microjoe.org>")
+ .subcommand(
+ SubCommand::with_name("translate")
+ .about("Linear translation of gcode axis")
+ .arg(
+ Arg::with_name("x")
+ .short("x")
+ .takes_value(true)
+ .help("Offset value for X axis"),
+ ).arg(
+ Arg::with_name("y")
+ .short("y")
+ .takes_value(true)
+ .help("Offset value for Y axis"),
+ ).arg(
+ Arg::with_name("z")
+ .short("z")
+ .takes_value(true)
+ .help("Offset value for Z axis"),
+ ),
+ ).get_matches();
+
+ if let Some(matches) = matches.subcommand_matches("translate") {
+ let buffer = read_stdin().expect("could not read stdin");
+ let mut gc = gcode::parse(&buffer).map(|g| g);
+
+ let x = parse_float_opt(&matches, "x");
+ let y = parse_float_opt(&matches, "y");
+ let z = parse_float_opt(&matches, "z");
+
+ gc
+ .map(|g| translate_optional(g, 'X', x))
+ .map(|g| translate_optional(g, 'Y', y))
+ .map(|g| translate_optional(g, 'Z', z))
+ .for_each(|g| println!("{}", g));
+ }
+}
diff --git a/test.gc b/test.gc
new file mode 100644
index 0000000..66df9f1
--- /dev/null
+++ b/test.gc
@@ -0,0 +1,8 @@
+O1000
+(Test program comment)
+T1 M6
+G90
+G01 X-75 Y-75 S500 M3
+G43 Z100 H1
+G01 Z5
+N20 G01 Z-20 F100