aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-09-26 01:02:29 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-09-26 01:02:29 +0200
commit365c44d8d352650e47995760daeca985e8a7e064 (patch)
treec65710ed58bd3890ef70e3f7447c1cae209e99e2
parent06fe0f88b8cfb51ab7e58c3d6ef5c8c940963ed8 (diff)
wip
-rw-r--r--cmd/drawtext/main.go8
-rw-r--r--cmd/version/main.go4
-rw-r--r--easteregg.go6
-rw-r--r--plot.go44
-rw-r--r--testpattern.go15
5 files changed, 60 insertions, 17 deletions
diff --git a/cmd/drawtext/main.go b/cmd/drawtext/main.go
index f05a251..62c80d3 100644
--- a/cmd/drawtext/main.go
+++ b/cmd/drawtext/main.go
@@ -13,17 +13,15 @@ var scale = flag.Float64("scale", 1.0, "font scale")
func main() {
flag.Parse()
- dev, err := robo.Open()
+ r, err := robo.NewRobo()
if err != nil {
log.Fatal(err)
}
- defer dev.Close()
-
- handle := dev.Handle()
- defer robo.Home(handle.Writer)
+ defer r.Close()
robo.Initialize(handle, 113, robo.Portrait)
robo.A4.UpperRight(handle.Writer)
robo.Triple{100, 100, 100}.Factor(handle.Writer)
robo.Print(handle.Writer, os.Stdin, robo.Unit(*scale))
+ r.Home()
}
diff --git a/cmd/version/main.go b/cmd/version/main.go
index ed780fb..7e9c95b 100644
--- a/cmd/version/main.go
+++ b/cmd/version/main.go
@@ -14,9 +14,7 @@ func main() {
}
defer r.Close()
r.Init()
- if !r.Ready() {
- log.Fatal("not ready")
- }
+ r.Wait4Ready()
ver := r.Version()
fmt.Println("Version:", ver)
r.GoHome()
diff --git a/easteregg.go b/easteregg.go
index 2e3ad05..a1a9326 100644
--- a/easteregg.go
+++ b/easteregg.go
@@ -1,7 +1,5 @@
package robo
-import "bufio"
-
// found in firmware V2.30
var easteregg = []string{
`FU5440,4000`,
@@ -341,8 +339,8 @@ var easteregg = []string{
`FO0`,
}
-func EasterEgg(c *bufio.Writer) {
+func (r Robo) EasterEgg() {
for _, cmd := range easteregg {
- Send(c, cmd)
+ r.Printf(cmd)
}
}
diff --git a/plot.go b/plot.go
index 39953ba..1625da4 100644
--- a/plot.go
+++ b/plot.go
@@ -3,6 +3,7 @@ package robo
import (
"fmt"
"strings"
+ "time"
)
type Robo struct {
@@ -59,19 +60,52 @@ func Curve(a int, p ...Point) string { return fmt.Sprintf("Y%d,%v", a, Path(p))
func (r Robo) Version() string {
r.dev.WriteString("FG")
resp, _ := r.dev.ReadString()
- return resp
+ return strings.TrimSpace(resp)
}
-func (r Robo) Init() {
- r.dev.Command([]byte{4})
+func (r Robo) Wait4Ready() {
+ t := time.NewTicker(time.Second)
+ defer t.Stop()
+ for range t.C {
+ if r.Ready() {
+ return
+ }
+ }
}
+func (r Robo) Step(d Direction) { r.dev.Command([]byte{0, byte(d)}) }
+func (r Robo) BootUpgrade() { r.dev.Command([]byte{1}) }
+func (r Robo) Init() { r.dev.Command([]byte{4}) }
+
func (r Robo) Ready() bool {
r.dev.Command([]byte{5})
resp, _ := r.dev.ReadString()
return resp == "0"
}
-func (r Robo) GoHome() {
- r.dev.WriteString("TT")
+func (r Robo) Printf(f string, a ...interface{}) {
+ s := fmt.Sprintf(f, a...)
+ r.dev.WriteString(s)
+}
+
+func (r Robo) GoHome() { r.Printf("TT") }
+func (r Robo) Home() { r.Printf("H") }
+func (r Robo) Origin() { r.Printf("FJ") }
+func (r Robo) Calibrate() { r.Printf("TB70") }
+func (r Robo) TestCut() { r.Printf("FH") }
+func (r Robo) TestLoop() { r.Printf("FI") }
+func (r Robo) Factor(x, y, z Unit) { r.Printf("&%v", Triple{x, y, z}) }
+func (r Robo) Offset(p Point) { r.Printf("^%v", p) }
+func (r Robo) LowerLeft(p Point) { r.Printf("\\%v", p) }
+func (r Robo) UpperRight(p Point) { r.Printf("Z%v", p) }
+func (r Robo) CuttingArea(p Point) { r.Printf("FU%v", p) }
+func (r Robo) Calibration(p Point) { r.Printf("TB72,%v", p) }
+func (r Robo) Move(p Point) { r.Printf("M%v", p) }
+func (r Robo) MoveRelative(p Point) { r.Printf("O%v", p) }
+func (r Robo) Draw(p ...Point) { r.Printf("D%v", Path(p)) }
+func (r Robo) DrawRelative(p Point) { r.Printf("E%v", p) }
+func (r Robo) Bezier(a, b, c, d Point) { r.Printf("BZ1,%v", Path{a, b, c, d}) }
+func (r Robo) Line(p ...Point) {
+ r.Move(p[0])
+ r.Draw(p[1:]...)
}
diff --git a/testpattern.go b/testpattern.go
index 27e7593..e9fb235 100644
--- a/testpattern.go
+++ b/testpattern.go
@@ -36,3 +36,18 @@ func TestPattern(c *bufio.Writer) {
}.Line(c)
Point{0, 0}.Move(c)
}
+
+func (r Robo) TestPattern() {
+ r.Factor(100, 100, 100)
+ r.Offset(Point{0, 0})
+ r.LowerLeft(Point{0, 0})
+ r.Move(Point{510, 637})
+ r.Bezier(Point{510, 637}, Point{439, 637}, Point{383, 580}, Point{383, 510})
+ r.Bezier(Point{383, 510}, Point{383, 439}, Point{439, 383}, Point{510, 383})
+ r.Bezier(Point{510, 383}, Point{580, 383}, Point{637, 439}, Point{637, 510})
+ r.Bezier(Point{637, 510}, Point{637, 580}, Point{580, 637}, Point{510, 637})
+ r.Line(Point{764, 764}, Point{256, 764}, Point{256, 256}, Point{764, 256}, Point{764, 764})
+ r.Line(Point{2, 510}, Point{1018, 510})
+ r.Line(Point{510, 1018}, Point{510, 2})
+ r.Move(Point{0, 0})
+}