-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathqr204.py
85 lines (63 loc) · 2.06 KB
/
qr204.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import time
class QR204(object):
_uart = None
def __init__(self, uart):
self._uart = uart
self._uart.write(b"\xff\xff\xff")
self._uart.write(b"\x1b\x76\x00")
self._uart.write(b"\x1b\x40")
self._uart.write(b"\x1b\x37")
self._uart.write(b"\x07\x50\x02") # heating dots/heat time/heat interval
self._uart.write(b"\x12\x23\xff")
def newline(self, n=3):
self._uart.write(b"\x0a" * n)
def inverse_enbl(self):
self._uart.write(b"\x1d\x42\x01")
def inverse_dsbl(self):
self._uart.write(b"\x1d\x42\x00")
def bold_enbl(self):
self._uart.write(b"\x1b\x45\x01")
def bold_dsbl(self):
self._uart.write(b"\x1b\x45\x00")
def font_b(self):
self._uart.write(b"\x1b\x21\x01")
def font_a(self):
self._uart.write(b"\x1b\x21\x00")
def uline_enbl(self):
self._uart.write(b"\x1b\x2d\x01")
def uline_dsbl(self):
self._uart.write(b"\x1b\x2d\x00")
def align(self, arg="<"):
if "<" in arg:
self._uart.write(b"\x1b\x61\x00")
elif ">" in arg:
self._uart.write(b"\x1b\x61\x02")
else:
self._uart.write(b"\x1b\x61\x01")
def sleep(self):
self._uart.write(b"\x1b\x38\x01")
def awake(self):
self._uart.write(b"\xff\x1b\x76\x00")
def write(self, text):
self._uart.write(text.encode())
def writeln(self, text):
self.write(text)
self.write("\n")
def paper(self):
self._uart.write(b"\x1b\x76\x00")
res = 1
for i in range(10):
if self._uart.any() > 0:
res = ord(self._uart.read(1)) & 4
break
time.sleep(0.1)
return res == 0
def print_image(self):
self.newline(1)
with open('data.bin', 'rb') as fd:
line = fd.read(48)
while line:
self._uart.write(b'\x12\x2a\x01\x30')
self._uart.write(line)
line = fd.read(48)
self.newline()