From 80507f9418805e886a1ea0ab6e61fb247fb2330c Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 12 May 2015 19:47:05 +0200 Subject: Add more commands --- cutter.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 16 deletions(-) (limited to 'cutter.go') diff --git a/cutter.go b/cutter.go index 16b35cc..50f544c 100644 --- a/cutter.go +++ b/cutter.go @@ -9,9 +9,9 @@ import ( /* A4 Cutting area - 5mm y 5mm + 10mm y 10mm +-----------------+ - | | 5mm + | | 10mm | +-------------+ | | | | | . . . . x @@ -78,12 +78,16 @@ const ( func (c Cutter) Add(a ...interface{}) { fmt.Fprint(c, a...) +} + +func (c Cutter) EOT() { c.WriteByte(ETX) + c.Flush() } func (c Cutter) Send(a ...interface{}) { c.Add(a...) - c.Flush() + c.EOT() } type StepDirection byte @@ -134,14 +138,30 @@ func (c Cutter) SetOrigin(n int) { c.Send("SO", n) } -func (c Cutter) Draw(p Point) { - c.Send("D", p) +func (c Cutter) Draw(pts ...Point) { + c.Add("D") + for _, p := range pts { + c.Add(p, ",") + } + c.EOT() +} + +func (c Cutter) DrawRelative(pts ...Point) { + c.Add("E") + for _, p := range pts { + c.Add(p, ",") + } + c.EOT() } func (c Cutter) Move(p Point) { c.Send("M", p) } +func (c Cutter) MoveRelative(p Point) { + c.Send("O", p) +} + type LineStyle int const ( @@ -331,10 +351,6 @@ func (c Cutter) Wait() { } } -func (c Cutter) Bezier(a int, p0, p1, p2, p3 Point) { - c.Send("BZ", a, ",", p0, ",", p1, ",", p2, ",", p3) -} - type Orientation int const ( @@ -381,19 +397,35 @@ func (c Cutter) ManualSearchMarks(p Point) bool { return c.returnUnit() == 0 } +func (c Cutter) Curve(a int, pts ...Point) { + c.Add("Y", a, ",") + for _, p := range pts { + c.Add(p, ",") + } + c.EOT() +} + +func (c Cutter) CurveRelative(a int, pts ...Point) { + c.Add("_", a, ",") + for _, p := range pts { + c.Add(p, ",") + } + c.EOT() +} + func (c Cutter) Circle(p Point, start, end Polar) { c.Send("W", p, ",", start.R, ",", end.R, ",", start.Theta, ",", end.Theta) } -// Not supported? -func (c Cutter) Curve(a int, ph Path) { - c.Add("Y", a) - for _, p := range ph { - c.Add(",", p) - } - c.Flush() +func (c Cutter) CircleRelative(start, end Polar) { + c.Send("]", start.R, ",", end.R, ",", + start.Theta, ",", end.Theta) +} + +func (c Cutter) Circle3P(p1, p2, p3 Point) { + c.Send("WP", p1, ",", p2, ",", p3) } func (c Cutter) Ellipse(a int, p Point, start, end Polar, theta Unit) { @@ -401,6 +433,10 @@ func (c Cutter) Ellipse(a int, p Point, start, end Polar, theta Unit) { start.Theta, ",", end.Theta, ",", theta) } +func (c Cutter) Bezier(a int, p0, p1, p2, p3 Point) { + c.Send("BZ", a, ",", p0, ",", p1, ",", p2, ",", p3) +} + func (c Cutter) Gin() Triple { c.Send("G") return c.returnTriple() -- cgit v1.2.3