From 89fc9d86c727aa8dc80232b461a7903a3c16d10e Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Fri, 12 Apr 2019 23:10:42 +0200 Subject: Cleanup, improve communication while printing --- ql/status.go | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 ql/status.go (limited to 'ql/status.go') diff --git a/ql/status.go b/ql/status.go new file mode 100644 index 0000000..ab3e675 --- /dev/null +++ b/ql/status.go @@ -0,0 +1,206 @@ +package ql + +import ( + "fmt" + "io" + "strings" +) + +// Status is a decoder for the status packed returned by the printer. +type Status [32]byte + +func (s *Status) MediaWidthMM() int { return int(s[10]) } +func (s *Status) MediaLengthMM() int { return int(s[17]) } + +type StatusType byte + +const ( + StatusTypeReplyToRequest StatusType = 0x00 + StatusTypePrintingCompleted = 0x01 + StatusTypeErrorOccurred = 0x02 + StatusTypeTurnedOff = 0x04 + StatusTypeNotification = 0x05 + StatusTypePhaseChange = 0x06 +) + +func (s *Status) Type() StatusType { return StatusType(s[18]) } + +type StatusPhase byte + +const ( + StatusPhaseReceiving StatusPhase = 0x00 + StatusPhasePrinting = 0x01 +) + +func (s *Status) Phase() StatusPhase { return StatusPhase(s[19]) } + +func decodeBitfieldErrors(b byte, errors [8]string) []string { + var result []string + for i := uint(0); i < 8; i++ { + if b&(1<