aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-05-02 15:32:25 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-05-02 15:32:25 +0200
commit7ef7d72b4f0ce867250e79e15124a06fa00646a5 (patch)
tree5beedad863594104010db8c6ca2a15993f9e54aa
parent64d999c0dc45065dc563bb075a4db2bd33df5918 (diff)
Refactor ETX/Flush
-rw-r--r--cutter.go92
-rw-r--r--easteregg.go11
-rw-r--r--marks.go14
3 files changed, 47 insertions, 70 deletions
diff --git a/cutter.go b/cutter.go
index f056072..5ce877b 100644
--- a/cutter.go
+++ b/cutter.go
@@ -81,14 +81,14 @@ const (
ESC = 0x1b
)
-func (c Cutter) Emit() {
- c.WriteByte(ETX)
+func (c Cutter) Send(a ...interface{}) {
+ a = append(a, ETX)
+ fmt.Fprint(c, a...)
c.Flush()
}
func (c Cutter) TestCut() {
- c.WriteString("FH")
- c.Emit()
+ c.Send("FH")
}
type StepDirection byte
@@ -110,29 +110,24 @@ func (c Cutter) Step(dir StepDirection) {
// CR returns carret to home on same line
func (c Cutter) CR() {
- c.WriteString("TT")
- c.Emit()
+ c.Send("TT")
}
// Home retuns carret to home position
func (c Cutter) Home() {
- c.WriteString("H")
- c.Emit()
+ c.Send("H")
}
func (c Cutter) SetOrigin() {
- c.WriteString("FJ")
- c.Emit()
+ c.Send("FJ")
}
func (c Cutter) Draw(p Point) {
- fmt.Fprint(c, "D", p)
- c.Emit()
+ c.Send("D", p)
}
func (c Cutter) Move(p Point) {
- fmt.Fprint(c, "M", p)
- c.Emit()
+ c.Send("M", p)
}
type LineStyle int
@@ -150,39 +145,32 @@ const (
)
func (c Cutter) LineType(n LineStyle) {
- fmt.Fprint(c, "L", n)
- c.Emit()
+ c.Send("L", n)
}
func (c Cutter) LineScale(n int) {
- fmt.Fprint(c, "B", n)
- c.Emit()
+ c.Send("B", n)
}
func (c Cutter) Factor(n int) {
- fmt.Fprintf(c, "&%v,%v,%v", n, n, n)
- c.Emit()
+ c.Send("&", n, ",", n, ",", n)
}
func (c Cutter) Offset(p Point) {
- fmt.Fprint(c, "^", p)
- c.Emit()
+ c.Send("^", p)
}
func (c Cutter) WriteLowerLeft(p Point) {
- fmt.Fprint(c, "\\", p)
- c.Emit()
+ c.Send("\\", p)
}
func (c Cutter) WriteUpperRight(p Point) {
- fmt.Fprint(c, "Z", p)
- c.Emit()
+ c.Send("Z", p)
}
// CuttingArea ???
func (c Cutter) CuttingArea(p Point) {
- fmt.Fprint(c, "FU", p)
- c.Emit()
+ c.Send("FU", p)
}
func (c Cutter) readResponse() (string, error) {
@@ -202,8 +190,7 @@ func (c Cutter) Version() (string, error) {
// MediaType (Meida ID)
func (c Cutter) MediaType(n int) {
- fmt.Fprint(c, "FW", n)
- c.Emit()
+ c.Send("FW", n)
}
func (c Cutter) ReadUpperRight() (string, error) {
@@ -215,15 +202,13 @@ func (c Cutter) ReadUpperRight() (string, error) {
// Speed 10..100 mm/s
func (c Cutter) Speed(n int) {
if n >= 1 && n <= 10 {
- fmt.Fprint(c, "!", n)
- c.Emit()
+ c.Send("!", n)
}
}
func (c Cutter) Thickness(n int) {
if n >= 1 && n <= 30 {
- fmt.Fprint(c, "FX", n, ",0")
- c.Emit()
+ c.Send("FX", n, ",0")
}
}
@@ -232,13 +217,11 @@ func (c Cutter) Force(n int) {
}
func (c Cutter) UnknownFC(n int) {
- fmt.Fprint(c, "FC", n)
- c.Emit()
+ c.Send("FC", n)
}
func (c Cutter) UnknownFE(n int) {
- fmt.Fprint(c, "FE", n)
- c.Emit()
+ c.Send("FE", n)
}
func parseDigit(s string) (n int) {
@@ -252,27 +235,23 @@ func parsePoint(s string) (p Point) {
}
func (c Cutter) RegistrationMarksLength(n int) {
- fmt.Fprint(c, "TB51,", n)
- c.Emit()
+ c.Send("TB51,", n)
}
func (c Cutter) Calibrate() {
- fmt.Fprint(c, "TB70")
- c.Emit()
+ c.Send("TB70")
}
// Sensor position
func (c Cutter) GetCalibration() Point {
- fmt.Fprint(c, "TB71")
- c.Emit()
+ c.Send("TB71")
s, _ := c.readResponse()
return parsePoint(s)
}
// Emited after calibration
func (c Cutter) UnknownFQ5() int {
- fmt.Fprint(c, "FQ5")
- c.Emit()
+ c.Send("FQ5")
s, _ := c.readResponse()
return parseDigit(s)
}
@@ -281,8 +260,7 @@ func (c Cutter) SetCalibration(p Point) {
if p.X > 40 || p.Y > 40 || p.X < -40 || p.Y < -40 {
return
}
- fmt.Fprint(c, "TB72,", p)
- c.Emit()
+ c.Send("TB72,", p)
}
// Arg: percent +/- 2.00% -> +/- 200
@@ -290,19 +268,16 @@ func (c Cutter) DistanseCorrection(n int) {
if n > 200 || n < -200 {
return
}
- fmt.Fprint(c, "FB", n, ",0")
- c.Emit()
+ c.Send(c, "FB", n, ",0")
}
func (c Cutter) UnknownTB(n int) (string, error) {
- fmt.Fprint(c, "TB", n)
- c.Emit()
+ c.Send("TB", n)
return c.readResponse()
}
func (c Cutter) UnknownFA() Point {
- fmt.Fprint(c, "FA")
- c.Emit()
+ c.Send("FA")
s, _ := c.readResponse()
return parsePoint(s)
}
@@ -346,8 +321,7 @@ func (c Cutter) Wait() {
}
func (c Cutter) Bezier(a int, p0, p1, p2, p3 Point) {
- fmt.Fprintf(c, "BZ%v,%v,%v,%v,%v", a, p0, p1, p2, p3)
- c.Emit()
+ c.Send("BZ", a, ",", p0, ",", p1, ",", p2, ",", p3)
}
type Orientation int
@@ -358,8 +332,7 @@ const (
)
func (c Cutter) Orientation(l Orientation) {
- fmt.Fprint(c, "FN", l)
- c.Emit()
+ c.Send("FN", l)
}
type OnOff int
@@ -372,6 +345,5 @@ const (
// TrackEnhancing moves paper back and forth for better traction
// Not for thickness less then 19
func (c Cutter) TrackEnhancing(state OnOff) {
- c.Emit()
- fmt.Fprint(c, "FY", state)
+ c.Send("FY", state)
}
diff --git a/easteregg.go b/easteregg.go
index 232ca40..281d97d 100644
--- a/easteregg.go
+++ b/easteregg.go
@@ -1,7 +1,5 @@
package main
-import "fmt"
-
// found in firmware V2.30
var easteregg = []string{
`FU5440,4000`,
@@ -302,13 +300,8 @@ var easteregg = []string{
}
func (c Cutter) EasterEgg() {
- c.Raw(easteregg)
-}
-
-func (c Cutter) Raw(s []string) {
- for _, cmd := range s {
- fmt.Fprint(c, cmd)
- c.Emit()
+ for _, cmd := range easteregg {
+ c.Send(cmd)
c.Wait()
}
}
diff --git a/marks.go b/marks.go
index 5fee812..92b62f0 100644
--- a/marks.go
+++ b/marks.go
@@ -25,6 +25,16 @@ package main
length 20 mm
*/
+/* Landscape Portrait
+ +- H -+ +- W -+
+ |x1 3| |2 1x|
+
+ W -> | H
+ v
+ |2 3|
+ +- -+
+*/
+
func (c Cutter) DrawMarks() (string, error) {
c.Move(Point{600, 3800})
c.Draw(Point{200, 3800})
@@ -44,5 +54,7 @@ func (c Cutter) DrawMarks() (string, error) {
func (c Cutter) SearchMarks() {
//cmd := []string{"TB99", "TB55,1", "TB123,3800,5240"}
cmd := []string{"TB99", "TB55,1", "TB23,3800,5240"}
- c.Raw(cmd)
+ for _, s := range cmd {
+ c.Send(s)
+ }
}