aboutsummaryrefslogtreecommitdiff
path: root/cutter.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-04-24 02:26:28 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-04-24 02:26:28 +0200
commitad7161543017bcef6d9b565bbbab790efc45f32f (patch)
tree39efbbf1daca448562d88fed5bf792917c891ab4 /cutter.go
parentbfbc8bea34269c60f14b1e191e43913142a557c7 (diff)
Reduce magic values
Diffstat (limited to 'cutter.go')
-rw-r--r--cutter.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/cutter.go b/cutter.go
index 950c06a..ce03f6c 100644
--- a/cutter.go
+++ b/cutter.go
@@ -51,8 +51,14 @@ func NewCutter(io *bufio.ReadWriter) Cutter {
return Cutter{io}
}
+const (
+ NUL = 0x00
+ ETX = 0x03 // End of Text
+ ESC = 0x1b
+)
+
func (c Cutter) Emit() {
- c.WriteByte(0x03) // send End Of Text
+ c.WriteByte(ETX)
c.Flush()
}
@@ -61,7 +67,7 @@ func (c Cutter) TestCut() {
c.Emit()
}
-type StepDirection int
+type StepDirection byte
const (
stepEnd StepDirection = 1 << iota >> 1
@@ -72,7 +78,9 @@ const (
)
func (c Cutter) step(dir StepDirection) {
- fmt.Fprintf(c, "\x1b\x00%c", dir)
+ c.WriteByte(ESC)
+ c.WriteByte(NUL)
+ c.WriteByte(byte(dir))
c.Flush()
}
@@ -159,7 +167,7 @@ func (c Cutter) CuttingArea(p Point) {
}
func (c Cutter) readResponse() (string, error) {
- ans, err := c.ReadString(0x03)
+ ans, err := c.ReadString(ETX)
if err != nil {
return "", err
}
@@ -233,7 +241,8 @@ func (c Cutter) UnknownTB51() {
// Updater Version ???
func (c Cutter) UpdaterVersion() (string, error) {
- c.WriteString("\x1b\x01")
+ c.WriteByte(ESC)
+ c.WriteByte(1)
c.Flush()
return c.readResponse()
}
@@ -244,17 +253,19 @@ func (c Cutter) Update() (bool, error) {
c.WriteString("CC1VERUP")
c.Flush()
ans, err := c.readResponse()
- return ans == "\x00", err
+ return ans == string(NUL), err
}
// Initialize ???
func (c Cutter) Initialize() {
- c.WriteString("\x1b\x04")
+ c.WriteByte(ESC)
+ c.WriteByte(4)
c.Flush()
}
func (c Cutter) Ready() bool {
- c.WriteString("\x1b\x05")
+ c.WriteByte(ESC)
+ c.WriteByte(5)
c.Flush()
ans, _ := c.readResponse()
return ans == "0"