From 91d3472be75004b6e937cd57ad27a8a6f6872b09 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 4 May 2015 23:19:46 +0200 Subject: More functions --- cutter.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++-------- main.go | 20 ++++++++++---------- misc.go | 17 +++++++++++++++++ testpattern.go | 2 +- 4 files changed, 74 insertions(+), 19 deletions(-) diff --git a/cutter.go b/cutter.go index 500cfd0..de12352 100644 --- a/cutter.go +++ b/cutter.go @@ -52,6 +52,10 @@ type Path []Point Usable: 4000x5440 pt */ +type Triple struct { + U, V, W float64 +} + var ( A4 = Point{5440, 4000} // Portrait Origin = Point{0, 0} @@ -61,6 +65,10 @@ func (p Point) String() string { return fmt.Sprintf("%v,%v", p.X, p.Y) } +func (t Triple) String() string { + return fmt.Sprintf("%v,%v,%v", t.U, t.V, t.W) +} + type Cutter struct { *bufio.ReadWriter } @@ -146,10 +154,14 @@ func (c Cutter) Home() { c.Send("H") } -func (c Cutter) SetOrigin() { +func (c Cutter) SetCurrentOrigin() { c.Send("FJ") } +func (c Cutter) SetOrigin(p Point) { + c.Send("SO", p) +} + func (c Cutter) Draw(p Point) { c.Send("D", p) } @@ -180,8 +192,8 @@ func (c Cutter) LineScale(n int) { c.Send("B", n) } -func (c Cutter) Factor(n int) { - c.Send("&", n, ",", n, ",", n) +func (c Cutter) Factor(t Triple) { + c.Send("&", t) } func (c Cutter) Offset(p Point) { @@ -220,11 +232,6 @@ func (c Cutter) MediaType(n int) { c.Send("FW", n) } -func (c Cutter) ReadUpperRight() (string, error) { - c.Send("U") - return c.readResponse() -} - // Speed 10..100 mm/s func (c Cutter) Speed(n int) { if n >= 1 && n <= 10 { @@ -262,6 +269,12 @@ func (c Cutter) parsePoint() (p Point) { return } +func (c Cutter) parseTriple() (t Triple) { + s, _ := c.readResponse() + fmt.Sscanf(s, "%v,%v,%v", &t.U, &t.V, &t.W) + return +} + func (c Cutter) RegMarkLen(n int) { c.Send("TB51,", n) } @@ -395,3 +408,28 @@ func (c Cutter) Ellipse(a int, p Point, start, end Polar, theta float64) { c.Send(")", a, ",", p, ",", start.R, ",", end.R, ",", start.Theta, ",", end.Theta, ",", theta) } + +func (c Cutter) Gin() Triple { + c.Send("G") + return c.parseTriple() +} + +func (c Cutter) CallGin() Triple { + c.Send("C") + return c.parseTriple() +} + +func (c Cutter) ReadOffset() Point { + c.Send("?") + return c.parsePoint() +} + +func (c Cutter) ReadLowerLeft() Point { + c.Send("[") + return c.parsePoint() +} + +func (c Cutter) ReadUpperRight() Point { + c.Send("U") + return c.parsePoint() +} diff --git a/main.go b/main.go index 6587821..eca1d9b 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,7 @@ package main +import "fmt" + func main() { dev := NewDevice() defer dev.Close() @@ -18,14 +20,12 @@ func main() { //fmt.Println(c.UnknownFQ5()) //c.Bezier(1, Point{0,0},Point{0,1000},Point{0,0},Point{1000,0}) //c.DrawCircles() - if !c.SearchMarks(Point{5240, 3800}, 400) { - return - } - - for _, path := range parsePage() { - c.Move(path[0]) - for _, p := range path[1:] { - c.Draw(p) - } - } + + fmt.Println("Gin", c.Gin()) + fmt.Println("Call Gin", c.CallGin()) + + fmt.Println("Offset", c.ReadOffset()) + fmt.Println("Upper Right", c.ReadUpperRight()) + fmt.Println("Lower Left", c.ReadLowerLeft()) + } diff --git a/misc.go b/misc.go index 6ea5aa9..5934211 100644 --- a/misc.go +++ b/misc.go @@ -1,5 +1,7 @@ package main +import "log" + func (c Cutter) DrawAtom() { base := Point{2000, 2000} for i := 0; i < 3; i++ { @@ -26,3 +28,18 @@ func (c Cutter) DrawCircles() { Polar{100 * float64(i), 3600}) } } + +func (c Cutter) DrawPic() { + for _, path := range parsePage() { + c.Move(path[0]) + for _, p := range path[1:] { + c.Draw(p) + } + } +} + +func (c Cutter) MustMarks(p Point) { + if !c.SearchMarks(p, 400) { + log.Fatal("marks not found") + } +} diff --git a/testpattern.go b/testpattern.go index e615d57..342f45b 100644 --- a/testpattern.go +++ b/testpattern.go @@ -1,7 +1,7 @@ package main func (c Cutter) TestPattern() { - c.Factor(100) + c.Factor(Triple{100, 100, 100}) c.Offset(Origin) c.WriteLowerLeft(Origin) -- cgit v1.2.3