From 6cac20d8bc57b6177d7054734242a2ab96ae368f Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 2 May 2015 21:05:41 +0200 Subject: Add Esc() --- cutter.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'cutter.go') diff --git a/cutter.go b/cutter.go index ba290fe..d26d534 100644 --- a/cutter.go +++ b/cutter.go @@ -87,10 +87,6 @@ func (c Cutter) Send(a ...interface{}) { c.Flush() } -func (c Cutter) TestCut() { - c.Send("FH") -} - type StepDirection byte const ( @@ -101,13 +97,22 @@ const ( StepLeft ) -func (c Cutter) Step(dir StepDirection) { +func (c Cutter) Esc(bytes ...byte) { c.WriteByte(ESC) - c.WriteByte(NUL) - c.WriteByte(byte(dir)) + for _, b := range bytes { + c.WriteByte(b) + } c.Flush() } +func (c Cutter) Step(dir StepDirection) { + c.Esc(NUL, byte(dir)) +} + +func (c Cutter) TestCut() { + c.Send("FH") +} + // CR returns carret to home on same line func (c Cutter) CR() { c.Send("TT") @@ -281,9 +286,7 @@ func (c Cutter) UnknownFA() Point { // VersionUpgrade func (c Cutter) BootVersion() (string, error) { - c.WriteByte(ESC) - c.WriteByte(1) - c.Flush() + c.Esc(1) return c.ReadString(' ') } @@ -297,15 +300,11 @@ func (c Cutter) Upgrade() (bool, error) { // Initialize ??? func (c Cutter) Initialize() { - c.WriteByte(ESC) - c.WriteByte(4) - c.Flush() + c.Esc(4) } func (c Cutter) Ready() bool { - c.WriteByte(ESC) - c.WriteByte(5) - c.Flush() + c.Esc(5) return c.parseDigit() == 0 } -- cgit v1.2.3