-
Notifications
You must be signed in to change notification settings - Fork 4
/
thermal_print.ts
140 lines (139 loc) · 3.37 KB
/
thermal_print.ts
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// sample JavaScript code for thermal printers on BBC micro:bit
// original Python code by Giles Booth @blogmywiki
// converted to JavaScript by Niels Swinkels
// for more information see
// http://www.suppertime.co.uk/blogmywiki/2016/12/microbit-thermal/
input.onButtonPressed(Button.A, () => {
print("Microbit thermal printer demo")
centreAlign()
print("Centre text")
rightAlign()
print("right align")
leftAlign()
print("left align")
wideOn()
print(" Wide text")
wideOff()
inverseOn()
print("inverse text")
inverseOff()
boldOn()
print(" bold text")
boldOff()
largeFontOn()
print("really big font")
largeFontOff()
smallFontOn()
print("A really very teeny tiny font indeed")
smallFontOff()
upsideDownOn()
print("upside down text")
upsideDownOff()
doubleHeightOn()
print("Double height text")
doubleHeightOff()
print("I can print several common barcode formats with or without human-readable numbers")
print("UPC-A:")
barcodeHumanReadable()
barcodeUPCA("086126100326")
print("EAN13:")
barcodeEAN13("9781477520826")
barcode128("CODE128")
barcode93("CODE93")
})
function print(msg: string) {
serial.writeLine(msg)
}
function doubleHeightOn() {
serial.writeString("\x1B\x21\x10")
}
function doubleHeightOff() {
serial.writeString("\x1B\x21\x00")
}
function smallFontOn() {
serial.writeString("\x1B\x21\x01")
}
function smallFontOff() {
serial.writeString("\x1B\x21\x00")
}
function boldOn() {
serial.writeString("\x1B\x45\x01")
}
function boldOff() {
serial.writeString("\x1B\x45\x00")
}
function wideOn() {
serial.writeString("\x1B\x0E")
}
function wideOff() {
serial.writeString("\x1B\x14")
}
function inverseOn() {
serial.writeString("\x1B\x21\x02")
}
function inverseOff() {
serial.writeString("\x1B\x21\x00")
}
function upsideDownOn() {
serial.writeString("\x1B\x7B\x01")
}
function upsideDownOff() {
serial.writeString("\x1B\x7B\x00")
}
function underlineOn() {
serial.writeString("\x1B\x2D\x02")
}
function underlineOff() {
serial.writeString("\x1B\x2D\x00")
}
function largeFontOn() {
serial.writeString("\x1D\x21\x11")
}
function largeFontOff() {
serial.writeString("\x1D\x21\x00")
}
function leftAlign() {
serial.writeString("\x1B\x61\x00")
}
function centreAlign() {
serial.writeString("\x1B\x61\x01")
}
function rightAlign() {
serial.writeString("\x1B\x61\x02")
}
// prints test page
function printerTest() {
serial.writeString("\x12\x54")
}
// resets the printer to default values
function printerReset() {
serial.writeString("\x1B\x40")
}
function barcodeHumanReadable() {
// print numbers below
serial.writeString("\x1D\x48\x02")
}
function barcodeNotHumanReadable() {
// print no numbers
serial.writeString("\x1D\x48\x00")
}
function barcodeUPCA(num: string) {
// must be 12 digits long
serial.writeString("\x1D\x6B\x00" + num + "\x00")
}
function barcodeEAN13(num: string) {
serial.writeString("\x1D\x6B\x02" + num + "\x00")
}
function barcode128(barcode: string) {
serial.writeString("\x1D\x6B\x08" + barcode + "\x00")
}
function barcode93(barcode: string) {
serial.writeString("\x1D\x6B\x07" + barcode + "\x00")
}
serial.redirect(
SerialPin.P0,
SerialPin.P1,
BaudRate.BaudRate19200
)
// increase printing temperature and time
print("\x1B\x37\x07\xFF\xFF")