aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-05-02 19:24:49 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-05-02 19:24:49 +0200
commiteb5be8c003e1177da7171eaf16b88d8e99e8dd4a (patch)
tree8ffd8ddf7dd7c4c76f05f7e3c0501a40423dcabf
parent68a4ed0b73bece074ceafc2890db99cbd83f282f (diff)
Refactor response reader
-rw-r--r--cutter.go18
-rw-r--r--main.go4
2 files changed, 10 insertions, 12 deletions
diff --git a/cutter.go b/cutter.go
index e54b818..ba290fe 100644
--- a/cutter.go
+++ b/cutter.go
@@ -222,12 +222,14 @@ func (c Cutter) UnknownFE(n int) {
c.Send("FE", n)
}
-func parseDigit(s string) (n int) {
+func (c Cutter) parseDigit() (n int) {
+ s, _ := c.readResponse()
fmt.Sscanf(s, "%v", &n)
return
}
-func parsePoint(s string) (p Point) {
+func (c Cutter) parsePoint() (p Point) {
+ s, _ := c.readResponse()
fmt.Sscanf(s, "%v,%v", &p.X, &p.Y)
return
}
@@ -243,15 +245,13 @@ func (c Cutter) Calibrate() {
// Sensor position
func (c Cutter) GetCalibration() Point {
c.Send("TB71")
- s, _ := c.readResponse()
- return parsePoint(s)
+ return c.parsePoint()
}
// Emited after calibration
func (c Cutter) UnknownFQ5() int {
c.Send("FQ5")
- s, _ := c.readResponse()
- return parseDigit(s)
+ return c.parseDigit()
}
func (c Cutter) SetCalibration(p Point) {
@@ -276,8 +276,7 @@ func (c Cutter) UnknownTB(n int) (string, error) {
func (c Cutter) UnknownFA() Point {
c.Send("FA")
- s, _ := c.readResponse()
- return parsePoint(s)
+ return c.parsePoint()
}
// VersionUpgrade
@@ -307,8 +306,7 @@ func (c Cutter) Ready() bool {
c.WriteByte(ESC)
c.WriteByte(5)
c.Flush()
- ans, _ := c.readResponse()
- return ans == "0"
+ return c.parseDigit() == 0
}
func (c Cutter) Wait() {
diff --git a/main.go b/main.go
index 32e2e11..8c3568b 100644
--- a/main.go
+++ b/main.go
@@ -10,8 +10,8 @@ func main() {
//defer cu.LineType(Solid)
//cu.Raw([]string{"L100,1,400,100"})
- cu.TestCut()
- //cu.TestPattern()
+ //cu.TestCut()
+ cu.TestPattern()
//cu.EasterEgg()
//cu.DrawMarks()
//cu.Move(Point{300, 300})