aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-09-24 03:44:16 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-09-24 03:44:16 +0200
commit09067cfbedb18de674595c56425953afd493c57c (patch)
tree3e4d5ae3cafd3b22a2d4879623926dfab12a2a83
parent2931ed698a28544ad1510c2fb5d1cb2b4be4ef6e (diff)
resort definitions
-rw-r--r--robo.go44
-rw-r--r--units.go47
2 files changed, 47 insertions, 44 deletions
diff --git a/robo.go b/robo.go
index d0cf9da..807645a 100644
--- a/robo.go
+++ b/robo.go
@@ -47,17 +47,6 @@ func (p Point) SearchMarks(c *bufio.ReadWriter, auto bool) bool {
return parseUnit(recv(c.Reader)) == 0
}
-func (p Point) Scale(f Unit) Point {
- return Point{p.X * f, p.Y * f}
-}
-
-func (ph Path) Scale(f Unit) (ret Path) {
- for _, p := range ph {
- ret = append(ret, p.Scale(f))
- }
- return
-}
-
func (ph Path) send(c *bufio.Writer, a ...interface{}) {
fmt.Fprint(c, a...)
for _, p := range ph {
@@ -174,32 +163,11 @@ func Version(c io.Writer) string {
//func Version(c *bufio.ReadWriter) string { return str(c, "FG") }
func StatusWord(c *bufio.ReadWriter) string { return str(c, "@") }
-type Orientation int
-
-const (
- Portrait Orientation = iota
- Landscape
-)
-
func (o Orientation) Orientation(c *bufio.Writer) {
orientation = o
send(c, "FN", o)
}
-type LineStyle int
-
-const (
- Solid LineStyle = iota
- Dots
- ShortDash
- Dash
- LongDash
- DashDot
- DashLongDot
- DashDoubleDot
- DashLongDoubleDot
-)
-
func (l LineStyle) LineStyle(c *bufio.Writer) { send(c, "L", l) }
func (p Point) LineStyle(c *bufio.Writer) { p.send(c, "L100,1,") }
@@ -241,16 +209,6 @@ func Initialize(c *bufio.ReadWriter, mid int, o Orientation) {
o.Orientation(c.Writer)
}
-type Direction byte
-
-const (
- Stop Direction = 1 << iota >> 1
- Down
- Up
- Right
- Left
-)
-
func (d Direction) Step(c *bufio.Writer) { esc(c, NUL, byte(d)) }
// Untested
@@ -259,7 +217,9 @@ func BootUpgrade(c *bufio.ReadWriter) string {
s, _ := c.ReadString(' ')
return s
}
+
func UpdateFirmware(c *bufio.ReadWriter) bool {
return str(c, "CC1VERUP") == string(NUL)
}
+
func EnableDebug(c *bufio.Writer) { send(c, "FP,GRFCC1") }
diff --git a/units.go b/units.go
index 7939c65..1acd3e1 100644
--- a/units.go
+++ b/units.go
@@ -31,12 +31,19 @@ func parseUnit(s string) (u Unit) {
return
}
+type Orientation int
+
+const (
+ Portrait Orientation = iota
+ Landscape
+)
+
+var orientation = Portrait
+
type Point struct {
X, Y Unit
}
-var orientation = Portrait
-
func (p Point) String() (s string) {
switch orientation {
case Portrait:
@@ -47,6 +54,10 @@ func (p Point) String() (s string) {
return
}
+func (p Point) Scale(f Unit) Point {
+ return Point{p.X * f, p.Y * f}
+}
+
func parsePoint(s string) (p Point) {
fmt.Sscanf(s, "%v,%v", &p.X, &p.Y)
return
@@ -74,3 +85,35 @@ func (p Path) String() string {
}
return strings.Join(pp, ",")
}
+
+func (ph Path) Scale(f Unit) Path {
+ ret := make(Path, len(ph))
+ for i, p := range ph {
+ ret[i] = p.Scale(f)
+ }
+ return ret
+}
+
+type LineStyle int
+
+const (
+ Solid LineStyle = iota
+ Dots
+ ShortDash
+ Dash
+ LongDash
+ DashDot
+ DashLongDot
+ DashDoubleDot
+ DashLongDoubleDot
+)
+
+type Direction byte
+
+const (
+ Stop Direction = 1 << iota >> 1
+ Down
+ Up
+ Right
+ Left
+)