forked from Klemen1337/node-thermal-printer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.js
More file actions
106 lines (98 loc) · 2.56 KB
/
Copy pathprinter.js
File metadata and controls
106 lines (98 loc) · 2.56 KB
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
var lwip = require('lwip');
var writeFile = require('write-file-queue')({
retries : 1000 // number of write attempts before failing
, waitTime : 200 // number of milliseconds to wait between write attempts
//, debug : console.error // optionally pass a function to do dump debug information to
});
var config = undefined;
var printText = "";
module.exports = {
init: function(type){
if(type === 'star'){
config = require('./starConfig');
} else {
config = require('./epsonConfig');
}
printText = "";
},
execute: function(){
writeFile('/dev/usb/lp0', printText, function (err) {
if (err) {
console.log('Print failed', err);
} else {
console.log('Print done');
printText = "";
}
});
},
cut: function(){
append(config.CTL_VT);
append(config.CTL_VT);
append(config.PAPER_FULL_CUT);
append(config.HW_INIT);
},
print: function(text){
append(text);
},
println: function(text){
append(text + "\n");
},
bold: function(enabled){
if(enabled) append(config.TXT_BOLD_ON);
else append(config.TXT_BOLD_OFF);
},
alignCenter: function (){
append(config.TXT_ALIGN_CT);
},
alignLeft: function (){
append(config.TXT_ALIGN_LT);
},
alignRight: function(){
append(config.TXT_ALIGN_RT);
},
setTypeFontA: function(){
append(config.TXT_FONT_A);
},
setTypeFontB: function(){
append(config.TXT_FONT_B);
},
setTextNormal: function(){
append(config.TXT_NORMAL);
},
setTextDoubleHeight: function(){
append(config.TXT_2HEIGHT);
},
setTextDoubleWidth: function(){
append(config.TXT_2WIDTH);
},
setTextQuadArea: function(){
append(config.TXT_4SQUARE);
},
drawLine: function(){
append(config.TXT_BOLD_ON);
append("\n-----------------------------------------------\n");
append(config.TXT_BOLD_OFF);
},
setLogos: function(fileNames) {
}
};
var append = function(text){
printText += text;
};
var intToHex = function(int){
return "\\x" + int.toString(16);
};
var raw = function(text){
writeFile('/dev/usb/lp0', text, function (err) {
if (err) {
console.log('Raw write failed', err);
} else {
console.log('Raw done');
}
});
};
String.prototype.parseHex = function(){
return this.replace(/\\x([a-fA-F0-9]{2})/g, function(a,b){
return String.fromCharCode(parseInt(b,16));
});
};