This repository has been archived by the owner on May 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 165
/
Adafruit_Thermal.h
363 lines (353 loc) · 12.2 KB
/
Adafruit_Thermal.h
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*!
* @file Adafruit_Thermal.h
*/
#ifndef ADAFRUIT_THERMAL_H
#define ADAFRUIT_THERMAL_H
#include "Arduino.h"
// Internal character sets used with ESC R n
#define CHARSET_USA 0 //!< American character set
#define CHARSET_FRANCE 1 //!< French character set
#define CHARSET_GERMANY 2 //!< German character set
#define CHARSET_UK 3 //!< UK character set
#define CHARSET_DENMARK1 4 //!< Danish character set 1
#define CHARSET_SWEDEN 5 //!< Swedish character set
#define CHARSET_ITALY 6 //!< Italian character set
#define CHARSET_SPAIN1 7 //!< Spanish character set 1
#define CHARSET_JAPAN 8 //!< Japanese character set
#define CHARSET_NORWAY 9 //!< Norwegian character set
#define CHARSET_DENMARK2 10 //!< Danish character set 2
#define CHARSET_SPAIN2 11 //!< Spanish character set 2
#define CHARSET_LATINAMERICA 12 //!< Latin American character set
#define CHARSET_KOREA 13 //!< Korean character set
#define CHARSET_SLOVENIA 14 //!< Slovenian character set
#define CHARSET_CROATIA 14 //!< Croatian character set
#define CHARSET_CHINA 15 //!< Chinese character set
// Character code tables used with ESC t n
#define CODEPAGE_CP437 0 //!< USA, Standard Europe character code table
#define CODEPAGE_KATAKANA 1 //!< Katakana (Japanese) character code table
#define CODEPAGE_CP850 2 //!< Multilingual character code table
#define CODEPAGE_CP860 3 //!< Portuguese character code table
#define CODEPAGE_CP863 4 //!< Canadian-French character code table
#define CODEPAGE_CP865 5 //!< Nordic character code table
#define CODEPAGE_WCP1251 6 //!< Cyrillic character code table
#define CODEPAGE_CP866 7 //!< Cyrillic #2 character code table
#define CODEPAGE_MIK 8 //!< Cyrillic/Bulgarian character code table
#define CODEPAGE_CP755 9 //!< East Europe, Latvian 2 character code table
#define CODEPAGE_IRAN 10 //!< Iran 1 character code table
#define CODEPAGE_CP862 15 //!< Hebrew character code table
#define CODEPAGE_WCP1252 16 //!< Latin 1 character code table
#define CODEPAGE_WCP1253 17 //!< Greek character code table
#define CODEPAGE_CP852 18 //!< Latin 2 character code table
#define CODEPAGE_CP858 19 //!< Multilingual Latin 1 + Euro character code table
#define CODEPAGE_IRAN2 20 //!< Iran 2 character code table
#define CODEPAGE_LATVIAN 21 //!< Latvian character code table
#define CODEPAGE_CP864 22 //!< Arabic character code table
#define CODEPAGE_ISO_8859_1 23 //!< West Europe character code table
#define CODEPAGE_CP737 24 //!< Greek character code table
#define CODEPAGE_WCP1257 25 //!< Baltic character code table
#define CODEPAGE_THAI 26 //!< Thai character code table
#define CODEPAGE_CP720 27 //!< Arabic character code table
#define CODEPAGE_CP855 28 //!< Cyrillic character code table
#define CODEPAGE_CP857 29 //!< Turkish character code table
#define CODEPAGE_WCP1250 30 //!< Central Europe character code table
#define CODEPAGE_CP775 31 //!< Baltic character code table
#define CODEPAGE_WCP1254 32 //!< Turkish character code table
#define CODEPAGE_WCP1255 33 //!< Hebrew character code table
#define CODEPAGE_WCP1256 34 //!< Arabic character code table
#define CODEPAGE_WCP1258 35 //!< Vietnam character code table
#define CODEPAGE_ISO_8859_2 36 //!< Latin 2 character code table
#define CODEPAGE_ISO_8859_3 37 //!< Latin 3 character code table
#define CODEPAGE_ISO_8859_4 38 //!< Baltic character code table
#define CODEPAGE_ISO_8859_5 39 //!< Cyrillic character code table
#define CODEPAGE_ISO_8859_6 40 //!< Arabic character code table
#define CODEPAGE_ISO_8859_7 41 //!< Greek character code table
#define CODEPAGE_ISO_8859_8 42 //!< Hebrew character code table
#define CODEPAGE_ISO_8859_9 43 //!< Turkish character code table
#define CODEPAGE_ISO_8859_15 44 //!< Latin 3 character code table
#define CODEPAGE_THAI2 45 //!< Thai 2 character code page
#define CODEPAGE_CP856 46 //!< Hebrew character code page
#define CODEPAGE_CP874 47 //!< Thai character code page
/*!
* Barcode types used with GS k m
*/
enum barcodes {
UPC_A, /**< UPC-A barcode system. 11-12 char */
UPC_E, /**< UPC-E barcode system. 11-12 char */
EAN13, /**< EAN13 (JAN13) barcode system. 12-13 char */
EAN8, /**< EAN8 (JAN8) barcode system. 7-8 char */
CODE39, /**< CODE39 barcode system. 1<=num of chars */
ITF, /**< ITF barcode system. 1<=num of chars, must be an even number */
CODABAR, /**< CODABAR barcode system. 1<=num<=255 */
CODE93, /**< CODE93 barcode system. 1<=num<=255 */
CODE128, /**< CODE128 barcode system. 2<=num<=255 */
};
/*!
* Driver for the thermal printer
*/
class Adafruit_Thermal : public Print {
public:
// IMPORTANT: constructor syntax has changed from prior versions
// of this library. Please see notes in the example code!
/*!
* @brief Thermal constructor
* @param s Serial stream
* @param dtr Data Terminal Ready control
*/
Adafruit_Thermal(Stream *s = &Serial, uint8_t dtr = 255);
size_t
/*!
* @brief Writes a character to the thermal printer
* @param c Character to write
* @return Returns true if successful
*/
write(uint8_t c);
void
/*!
* @param version firmware version as integer, e.g. 268 = 2.68 firmware
*/
begin(uint16_t version=268),
/*!
* @brief Disables bold text
*/
boldOff(),
/*!
* @brief Enables bold text
*/
boldOn(),
/*!
* @brief Disables double-height text
*/
doubleHeightOff(),
/*!
* @brief Enables double-height text
*/
doubleHeightOn(),
/*!
* @brief Disables double-width text
*/
doubleWidthOff(),
/*!
* @brief Enables double-width text
*/
doubleWidthOn(),
/*!
* @brief Feeds by the specified number of lines
* @param x How many lines to feed
*/
feed(uint8_t x=1),
/*!
* @brief Feeds by the specified number of individual pixel rows
* @param rows How many rows to feed
*/
feedRows(uint8_t),
/*!
* @brief Flush data pending in the printer
*/
flush(),
/*!
* @brief Disables white/black reverse printing mode
*/
inverseOff(),
/*!
* @brief Enables white/black reverse printing mode
*/
inverseOn(),
/*!
* @brief Set the justification of text
* @param value justification, must be JUSTIFY_LEFT, JUSTIFY_CENTER, JUSTIFY_RIGHT
*/
justify(char value),
/*!
* @brief Put the printer into an offline state. No other commands can be sent until an online call is made
*/
offline(),
/*!
* @brief Put the printer into an online state after previously put offline
*/
online(),
/*!
* @brief Print a barcode
* @param text The specified text/number (the meaning varies based on the type of barcode) and type to write to the barcode
* @param type Value from the datasheet or class-level variables like UPC-A. Note the type value changes depending on the firmware version so use class-level values where possible
*/
printBarcode(const char *text, uint8_t type),
/*!
* @brief Prints a bitmap
* @param w Width of the image in pixels
* @param h Height of the image in pixels
* @param bitmap Bitmap data, from a file.
* @param fromProgMem
*/
printBitmap(int w, int h, const uint8_t *bitmap, bool fromProgMem=true),
/*!
* @brief Prints a bitmap
* @param w Width of the image in pixels
* @param h Height of the image in pixels
* @param fromStream Stream to get bitmap data from
*/
printBitmap(int w, int h, Stream *fromStream),
/*!
* @brief Prints a bitmap
* @param fromStream Stream to get bitmap data from
*/
printBitmap(Stream *fromStream),
/*!
* @brief Sets text to normal mode
*/
normal(),
/*!
* @brief Reset the printer
*/
reset(),
/*!
* @brief Sets the barcode height
* @param val Desired height of the barcode
*/
setBarcodeHeight(uint8_t val=50),
/*!
* @brief Sets the font
* @param font Desired font, either A or B
*/
setFont(char font='A'),
/*!
* @brief Sets the character spacing
* @param spacing Desired character spacing
*/
setCharSpacing(int spacing=0), // Only works w/recent firmware
/*!
* @brief Sets the character set
* @param val Value of the desired character set
*/
setCharset(uint8_t val=0),
/*!
* @brief Sets character code page
* @param val Value of the desired character code page
*/
setCodePage(uint8_t val=0),
/*!
* @brief Sets the default settings
*/
setDefault(),
/*!
* @brief Sets the line height
* @param val Desired line height
*/
setLineHeight(int val=30),
/*!
* @brief Set max rows to write
* @param val Max rows to write
*/
setMaxChunkHeight(int val=256),
/*!
* @brief Sets text size
* @param value Text size
*/
setSize(char value),
/*!
* @brief Sets print and feed speed
* @param p print speed
* @param f feed speed
*/
setTimes(unsigned long, unsigned long),
/*!
* @brief Sets print head heating configuration
* @param dots max printing dots, 8 dots per increment
* @param time heating time, 10us per increment
* @param interval heating interval, 10 us per increment
*/
setHeatConfig(uint8_t dots=11, uint8_t time=120, uint8_t interval=40),
/*!
* @brief Sets print density
* @param density printing density
* @param breakTime printing break time
*/
setPrintDensity(uint8_t density=10, uint8_t breakTime=2),
/*!
* @brief Puts the printer into a low-energy state immediately
*/
sleep(),
/*!
* @brief Puts the printer into a low-energe state after the given number of seconds
* @param seconds How many seconds to wait until sleeping
*/
sleepAfter(uint16_t seconds),
/*!
* @brief Disables delete line mode
*/
strikeOff(),
/*!
* @brief Enables delete line mode
*/
strikeOn(),
/*!
* @brief Sends tab to device
*/
tab(), // Only works w/recent firmware
/*!
* @brief Prints test text
*/
test(),
/*!
* @brief Prints test page
*/
testPage(),
/*!
* @brief Sets the estimated completion time for a just-issued task
* @param x Estimated completion time
*/
timeoutSet(unsigned long),
/*!
* @brief Waits for the prior task to complete
*/
timeoutWait(),
/*!
* @brief Disables underline
*/
underlineOff(),
/*!
* @brief Enables underline
* @param weight Weight of the line
*/
underlineOn(uint8_t weight=1),
/*!
* @brief Disables upside-down text mode
*/
upsideDownOff(),
/*!
* @brief Enables upside-down text mode
*/
upsideDownOn(),
/*!
* @brief Wakes device that was in sleep mode
*/
wake();
bool
/*!
* @brief Whether or not the printer has paper
* @return Returns true if there is still paper
*/
hasPaper();
private:
Stream *stream;
uint8_t printMode,
prevByte, // Last character issued to printer
column, // Last horizontal column printed
maxColumn, // Page width (output 'wraps' at this point)
charHeight, // Height of characters, in 'dots'
lineSpacing, // Inter-line spacing (not line height), in dots
barcodeHeight, // Barcode height in dots, not including text
maxChunkHeight,
dtrPin; // DTR handshaking pin (experimental)
uint16_t firmware; // Firmware version
boolean dtrEnabled; // True if DTR pin set & printer initialized
unsigned long
resumeTime, // Wait until micros() exceeds this before sending byte
dotPrintTime, // Time to print a single dot line, in microseconds
dotFeedTime; // Time to feed a single dot line, in microseconds
void writeBytes(uint8_t a), writeBytes(uint8_t a, uint8_t b),
writeBytes(uint8_t a, uint8_t b, uint8_t c),
writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d),
setPrintMode(uint8_t mask), unsetPrintMode(uint8_t mask),
writePrintMode(), adjustCharValues(uint8_t printMode);
};
#endif // ADAFRUIT_THERMAL_H