-
Notifications
You must be signed in to change notification settings - Fork 19
/
thermalprinter.cpp
197 lines (166 loc) · 3.61 KB
/
thermalprinter.cpp
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*******************************************
* see header-file for further informations
********************************************/
#include "Arduino.h"
#include "thermalprinter.h"
static const char LF = 0xA; // print buffer and line feed
Epson::Epson(int rxPin, int txPin)
{
this->_rxPin = rxPin;
this->_txPin = txPin;
this->start();
}
void Epson::start(){
pinMode(this->_txPin, OUTPUT);
pinMode(this->_rxPin, INPUT);
this->_printer = new SoftwareSerial (this->_rxPin, this->_txPin);
this->_printer->begin(9600);
}
// query status of printer. when online returns value 22.
int Epson::getStatus(){
this->write(0x10);
this->write(0x04);
this->write(1);
int result;
result = this->_printer->read();
return result;
}
int Epson::read(){
int result;
result = this->_printer->read();
return result;
}
// Print and feed n lines
// prints the data in the print buffer and feeds n lines
void Epson::feed(uint8_t n){
this->write(0x1B);
this->write(0x64);
this->write(n);
}
// Print one line
void Epson::feed(){
this->feed(1);
}
// Set line spacing
// sets the line spacing to n/180-inch
void Epson::lineSpacing(uint8_t n){
this->write(0x1B);
this->write(0x33);
this->write(n);
}
// Select default line spacing
// sets the line spacing to 1/6 inch (n=60). This is equivalent to 30 dots.
void Epson::defaultLineSpacing(){
this->write(0x1B);
this->write(0x32);
}
// Select an international character set
// 0 = U.S.A.
// 1 = France
// 2 = Germany
// 3 = U.K.
// 4 = Denmark I
// 5 = Sweden
// 6 = Italy
// 7 = Spain
// 8 = Japan
// 9 = Norway
// 10 = Denmark II
// see reference for Details!
void Epson::characterSet(uint8_t n){
this->write(0x1B);
this->write(0x52);
this->write(n);
}
void Epson::doubleHeightOn(){
this->write(0x1B);
this->write(0x21);
this->write(16);
}
void Epson::doubleHeightOff(){
this->write(0x1B);
this->write(0x21);
this->write(0);
}
void Epson::boldOn(){
this->write(0x1B);
this->write(0x21);
this->write(8);
}
void Epson::boldOff(){
this->write(0x1B);
this->write(0x21);
this->write(0);
}
void Epson::underlineOff() {
this->write(0x1B);
this->write(0x21);
this->write(0);
}
void Epson::underlineOn() {
this->write(0x1B);
this->write(0x21);
this->write(128);
}
// Turn white/black reverse printing mode on/off
void Epson::reverseOn() {
this->write(0x1D);
this->write(0x42);
this->write(1);
}
void Epson::reverseOff() {
this->write(0x1D);
this->write(0x42);
this->write(0);
}
void Epson::justifyLeft() {
this->write(0x1B);
this->write(0x61);
this->write(0);
}
void Epson::justifyCenter() {
this->write(0x1B);
this->write(0x61);
this->write(1);
}
void Epson::justifyRight() {
this->write(0x1B);
this->write(0x61);
this->write(2);
}
//n range 1-255
void Epson::barcodeHeight(uint8_t n) {
this->write(0x1D);
this->write(0x68);
this->write(n);
}
//n range 2-6
void Epson::barcodeWidth(uint8_t n) {
this->write(0x1D);
this->write(0x77);
this->write(n);
}
//n range 0-3
void Epson::barcodeNumberPosition(uint8_t n) {
this->write(0x1D);
this->write(0x48);
this->write(n);
}
//m range 65-73 (code type)
//n (digit length)
void Epson::printBarcode(uint8_t m, uint8_t n) {
this->write(0x1D);
this->write(0x6B);
this->write(m);
this->write(n);
}
void Epson::cut() {
this->write(0x1D);
this->write('V');
this->write(66);
this->write(0xA); // print buffer and line feed
}
size_t Epson::write(uint8_t c) {
this->_printer->write(c);
return 1;
}