summaryrefslogtreecommitdiff
path: root/pttarget.py
diff options
context:
space:
mode:
Diffstat (limited to 'pttarget.py')
-rw-r--r--pttarget.py67
1 files changed, 46 insertions, 21 deletions
diff --git a/pttarget.py b/pttarget.py
index 37f6509..ff05a1e 100644
--- a/pttarget.py
+++ b/pttarget.py
@@ -6,13 +6,55 @@ import tempfile, os, struct, sys, array, time
import qrcode
class PTPrinter(object):
- def __init__(self):
- pass
+ def __init__(self, dummy_width=24):
+ self.dummy_width = dummy_width
+ self.last_status = None
+
+ def __str__(self):
+ return 'Dummy PTPrinter, Tape width %d' % self.dummy_width
+
def setup(self):
pass
+
+ def check_status(self):
+ self.refresh_status()
+
+ def find_tape(self):
+ for tape in PTTape.tapes:
+ if int(tape.sizemm) == self.media_width:
+ return tape
+ return None
+
def is_interactive(self):
return False
+ def get_errstr(self):
+ errs = []
+ for i in range(0, 8):
+ if self.err1 & (1 << i):
+ errs.append(codes_err1.get(1 << i, '<1:%02x>' % (1 << i)))
+ for i in range(0, 8):
+ if self.err2 & (1 << i):
+ errs.append(codes_err2.get(1 << i, '<2:%02x>' % (1 << i)))
+ if len(errs) == 0:
+ return 'OK'
+ return ', '.join(errs)
+
+ def refresh_status(self):
+ self.err1 = 0x00
+ self.err2 = 0x00
+ self.media_width = self.dummy_width
+ self.media_type = 0x01
+ self.media_length = 8000
+ self.status_type = 0x00
+ self.phase_type = 0x00
+ self.phase_bytes = 0x00
+ self.notify_num = 0x00
+ self.last_status = time.time()
+
+ def send(self, data):
+ pass
+
media_types = {
0x01: 'Laminated',
0x02: 'Lettering',
@@ -37,8 +79,8 @@ codes_err2 = {
class PTUSB(PTPrinter):
def __init__(self, usbdev):
+ super(PTUSB, self).__init__()
self.usbdev = usbdev
- self.last_status = None
def __str__(self):
return '%s %s (%04x:%04x @ %d.%d)' % (
@@ -95,12 +137,6 @@ class PTUSB(PTPrinter):
self.notify_num = ar[22]
self.last_status = time.time()
- def find_tape(self):
- for tape in PTTape.tapes:
- if int(tape.sizemm) == self.media_width:
- return tape
- return None
-
def check_status(self):
ar = self.if_rd.read(16)
if len(ar) == 0:
@@ -110,18 +146,6 @@ class PTUSB(PTPrinter):
ar += self.if_rd.read(16)
self.refresh_status(ar)
- def get_errstr(self):
- errs = []
- for i in range(0, 8):
- if self.err1 & (1 << i):
- errs.append(codes_err1.get(1 << i, '<1:%02x>' % (1 << i)))
- for i in range(0, 8):
- if self.err2 & (1 << i):
- errs.append(codes_err2.get(1 << i, '<2:%02x>' % (1 << i)))
- if len(errs) == 0:
- return 'OK'
- return ', '.join(errs)
-
def send(self, data):
offset = 0
size = len(data)
@@ -308,3 +332,4 @@ if __name__ == '__main__':
# bytearray(((w + 7) / 8) * '\xff'))
p.send(data.get())
+