This is the Adafruit thermal printer, whose Arduino library is published here: http://www.ladyada.net/products/thermalprinter/. This is a basic port to mbed that needs proper testing. The first printBitmap function is implemented but not fully tested, the stream versions are not ported yet.

Dependents:   SMS_LEDMatrixPrinter

Fork of AdafruitThermalPrinter by Ashley Mills

Committer:
SomeRandomBloke
Date:
Tue Nov 20 13:07:13 2012 +0000
Revision:
2:6c38e763c285
Parent:
1:315c49946ded
Child:
3:0e12bed6b295
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:c4a48036e46f 1 /***************************************************
ashleymills 0:c4a48036e46f 2 This is a library for the Adafruit Thermal Printer
ashleymills 0:c4a48036e46f 3
ashleymills 0:c4a48036e46f 4 Pick one up at --> http://www.adafruit.com/products/597
ashleymills 0:c4a48036e46f 5 These printers use TTL serial to communicate, 2 pins are required
ashleymills 0:c4a48036e46f 6
ashleymills 0:c4a48036e46f 7 Adafruit invests time and resources providing this open source code,
ashleymills 0:c4a48036e46f 8 please support Adafruit and open-source hardware by purchasing
ashleymills 0:c4a48036e46f 9 products from Adafruit!
ashleymills 0:c4a48036e46f 10
ashleymills 0:c4a48036e46f 11 Written by Limor Fried/Ladyada for Adafruit Industries.
ashleymills 0:c4a48036e46f 12 MIT license, all text above must be included in any redistribution
ashleymills 0:c4a48036e46f 13 ****************************************************/
ashleymills 0:c4a48036e46f 14
ashleymills 1:315c49946ded 15 /** Ported hastily to mbed by Ashley Mills - NOTE: printBitmap not ported, nothing tested **/
ashleymills 0:c4a48036e46f 16 #include "mbed.h"
ashleymills 0:c4a48036e46f 17 #include "AdafruitThermal.h"
ashleymills 0:c4a48036e46f 18
ashleymills 0:c4a48036e46f 19
ashleymills 0:c4a48036e46f 20 AdafruitThermal::AdafruitThermal(PinName RX_Pin, PinName TX_Pin) {
ashleymills 0:c4a48036e46f 21 _RX_Pin = RX_Pin;
ashleymills 0:c4a48036e46f 22 _TX_Pin = TX_Pin;
ashleymills 0:c4a48036e46f 23 }
ashleymills 0:c4a48036e46f 24
ashleymills 0:c4a48036e46f 25 void AdafruitThermal::begin(int heatTime) {
ashleymills 0:c4a48036e46f 26 _printer = new Serial(_RX_Pin, _TX_Pin);
ashleymills 0:c4a48036e46f 27 _printer->baud(19200);
ashleymills 0:c4a48036e46f 28
ashleymills 0:c4a48036e46f 29 // The printer can't start receiving data immediately
ashleymills 0:c4a48036e46f 30 // upon power up -- needs a moment to initialize. If
ashleymills 0:c4a48036e46f 31 // Arduino & printer are powered from the same supply,
ashleymills 0:c4a48036e46f 32 // they're starting simultaneously. Need to pause for
ashleymills 0:c4a48036e46f 33 // a moment so the printer is ready for commands.
ashleymills 0:c4a48036e46f 34 // (A more robust approach might be to wait in a loop
ashleymills 0:c4a48036e46f 35 // issuing status commands until valid response.)
ashleymills 0:c4a48036e46f 36 wait(0.5);
ashleymills 0:c4a48036e46f 37
ashleymills 0:c4a48036e46f 38 reset();
ashleymills 0:c4a48036e46f 39
ashleymills 0:c4a48036e46f 40 // Description of print settings from page 23 of the manual:
ashleymills 0:c4a48036e46f 41 // ESC 7 n1 n2 n3 Setting Control Parameter Command
ashleymills 0:c4a48036e46f 42 // Decimal: 27 55 n1 n2 n3
ashleymills 0:c4a48036e46f 43 // Set "max heating dots", "heating time", "heating interval"
ashleymills 0:c4a48036e46f 44 // n1 = 0-255 Max printing dots, Unit (8dots), Default: 7 (64 dots)
ashleymills 0:c4a48036e46f 45 // n2 = 3-255 Heating time, Unit (10us), Default: 80 (800us)
ashleymills 0:c4a48036e46f 46 // n3 = 0-255 Heating interval, Unit (10us), Default: 2 (20us)
ashleymills 0:c4a48036e46f 47 // The more max heating dots, the more peak current will cost
ashleymills 0:c4a48036e46f 48 // when printing, the faster printing speed. The max heating
ashleymills 0:c4a48036e46f 49 // dots is 8*(n1+1). The more heating time, the more density,
ashleymills 0:c4a48036e46f 50 // but the slower printing speed. If heating time is too short,
ashleymills 0:c4a48036e46f 51 // blank page may occur. The more heating interval, the more
ashleymills 0:c4a48036e46f 52 // clear, but the slower printing speed.
ashleymills 0:c4a48036e46f 53
ashleymills 0:c4a48036e46f 54 writeBytes(27, 55); // Esc 7 (print settings)
ashleymills 0:c4a48036e46f 55 writeBytes(20); // Heating dots (20=balance of darkness vs no jams)
ashleymills 0:c4a48036e46f 56 writeBytes(heatTime); // Library default = 255 (max)
ashleymills 0:c4a48036e46f 57 writeBytes(250); // Heat interval (500 uS = slower, but darker)
ashleymills 0:c4a48036e46f 58
ashleymills 0:c4a48036e46f 59 // Description of print density from page 23 of the manual:
ashleymills 0:c4a48036e46f 60 // DC2 # n Set printing density
ashleymills 0:c4a48036e46f 61 // Decimal: 18 35 n
ashleymills 0:c4a48036e46f 62 // D4..D0 of n is used to set the printing density. Density is
ashleymills 0:c4a48036e46f 63 // 50% + 5% * n(D4-D0) printing density.
ashleymills 0:c4a48036e46f 64 // D7..D5 of n is used to set the printing break time. Break time
ashleymills 0:c4a48036e46f 65 // is n(D7-D5)*250us.
ashleymills 0:c4a48036e46f 66 // (Unsure of the default value for either -- not documented)
ashleymills 0:c4a48036e46f 67
ashleymills 0:c4a48036e46f 68 const int
ashleymills 0:c4a48036e46f 69 printDensity = 14, // 120% (? can go higher, text is darker but fuzzy)
ashleymills 0:c4a48036e46f 70 printBreakTime = 4; // 500 uS
ashleymills 0:c4a48036e46f 71 writeBytes(18, 35); // DC2 # (print density)
ashleymills 0:c4a48036e46f 72 writeBytes((printBreakTime << 5) | printDensity);
ashleymills 0:c4a48036e46f 73 }
ashleymills 0:c4a48036e46f 74
ashleymills 0:c4a48036e46f 75 // reset printer
ashleymills 0:c4a48036e46f 76 void AdafruitThermal::reset() {
ashleymills 0:c4a48036e46f 77 writeBytes(27, 64);
ashleymills 0:c4a48036e46f 78 }
ashleymills 0:c4a48036e46f 79
ashleymills 0:c4a48036e46f 80 // reset formatting
ashleymills 0:c4a48036e46f 81 void AdafruitThermal::setDefault(){
ashleymills 0:c4a48036e46f 82 online();
ashleymills 0:c4a48036e46f 83 justify('L');
ashleymills 0:c4a48036e46f 84 inverseOff();
ashleymills 0:c4a48036e46f 85 doubleHeightOff();
ashleymills 0:c4a48036e46f 86 setLineHeight(32);
ashleymills 0:c4a48036e46f 87 boldOff();
ashleymills 0:c4a48036e46f 88 underlineOff();
ashleymills 0:c4a48036e46f 89 setBarcodeHeight(50);
ashleymills 0:c4a48036e46f 90 setSize('s');
ashleymills 0:c4a48036e46f 91 }
ashleymills 0:c4a48036e46f 92
ashleymills 0:c4a48036e46f 93 void AdafruitThermal::test(){
ashleymills 0:c4a48036e46f 94 write('h');
ashleymills 0:c4a48036e46f 95 write('e');
ashleymills 0:c4a48036e46f 96 write('l');
ashleymills 0:c4a48036e46f 97 write('l');
ashleymills 0:c4a48036e46f 98 write('o');
ashleymills 0:c4a48036e46f 99 write('!');
ashleymills 0:c4a48036e46f 100 write('\n');
ashleymills 0:c4a48036e46f 101 feed(2);
ashleymills 0:c4a48036e46f 102 }
ashleymills 0:c4a48036e46f 103
ashleymills 0:c4a48036e46f 104 void AdafruitThermal::print(char *string) {
ashleymills 0:c4a48036e46f 105 while(*string!=0) {
ashleymills 0:c4a48036e46f 106 write(*string);
ashleymills 0:c4a48036e46f 107 string++;
ashleymills 0:c4a48036e46f 108 }
ashleymills 0:c4a48036e46f 109 }
ashleymills 0:c4a48036e46f 110
ashleymills 0:c4a48036e46f 111 void AdafruitThermal::testPage() {
ashleymills 0:c4a48036e46f 112 writeBytes(18, 84);
ashleymills 0:c4a48036e46f 113 }
ashleymills 0:c4a48036e46f 114
ashleymills 0:c4a48036e46f 115 // this is the basic function for all printing, the rest is taken care of by the
ashleymills 0:c4a48036e46f 116 // inherited Print class!
ashleymills 0:c4a48036e46f 117 size_t AdafruitThermal::write(uint8_t c) {
ashleymills 0:c4a48036e46f 118 if (c == 0x13) return 0;
ashleymills 0:c4a48036e46f 119
ashleymills 0:c4a48036e46f 120 if (c != 0xA)
ashleymills 0:c4a48036e46f 121 linefeedneeded = true;
ashleymills 0:c4a48036e46f 122 else
ashleymills 0:c4a48036e46f 123 linefeedneeded = false;
ashleymills 0:c4a48036e46f 124
ashleymills 0:c4a48036e46f 125 //DBG(" 0x");
ashleymills 0:c4a48036e46f 126 //DBG(c, HEX);
ashleymills 0:c4a48036e46f 127 //DBG(" (");
ashleymills 0:c4a48036e46f 128
ashleymills 0:c4a48036e46f 129 PRINTER_PRINT(c);
ashleymills 0:c4a48036e46f 130
ashleymills 0:c4a48036e46f 131 return 1;
ashleymills 0:c4a48036e46f 132
ashleymills 0:c4a48036e46f 133 }
ashleymills 0:c4a48036e46f 134
ashleymills 0:c4a48036e46f 135 void AdafruitThermal::setBarcodeHeight(int val){
ashleymills 0:c4a48036e46f 136 //default is 50
ashleymills 0:c4a48036e46f 137 writeBytes(29, 104, val);
ashleymills 0:c4a48036e46f 138 }
ashleymills 0:c4a48036e46f 139
ashleymills 0:c4a48036e46f 140 void AdafruitThermal::printBarcode(char * text, uint8_t type) {
ashleymills 0:c4a48036e46f 141 int i;
ashleymills 0:c4a48036e46f 142 uint8_t c;
ashleymills 0:c4a48036e46f 143
ashleymills 0:c4a48036e46f 144 delay(1000); // Need these delays else barcode doesn't always print. ???
ashleymills 0:c4a48036e46f 145 writeBytes(29, 107, type); // set the type first
ashleymills 0:c4a48036e46f 146 delay(500);
ashleymills 0:c4a48036e46f 147 // Copy string, not including NUL terminator
ashleymills 0:c4a48036e46f 148 for(i=0; (c = text[i]); i++) PRINTER_PRINT(c);
ashleymills 0:c4a48036e46f 149 delay(500);
ashleymills 0:c4a48036e46f 150 PRINTER_PRINT(c); // Terminator must follow delay. ???
ashleymills 0:c4a48036e46f 151
ashleymills 0:c4a48036e46f 152 delay(3000); // For some reason we can't immediately have line feeds here
ashleymills 0:c4a48036e46f 153 feed(2);
ashleymills 0:c4a48036e46f 154 }
ashleymills 0:c4a48036e46f 155
ashleymills 0:c4a48036e46f 156 void AdafruitThermal::writeBytes(uint8_t a) {
ashleymills 0:c4a48036e46f 157 PRINTER_PRINT(a);
ashleymills 0:c4a48036e46f 158 }
ashleymills 0:c4a48036e46f 159
ashleymills 0:c4a48036e46f 160 void AdafruitThermal::writeBytes(uint8_t a, uint8_t b) {
ashleymills 0:c4a48036e46f 161 PRINTER_PRINT(a);
ashleymills 0:c4a48036e46f 162 PRINTER_PRINT(b);
ashleymills 0:c4a48036e46f 163 }
ashleymills 0:c4a48036e46f 164
ashleymills 0:c4a48036e46f 165 void AdafruitThermal::writeBytes(uint8_t a, uint8_t b, uint8_t c) {
ashleymills 0:c4a48036e46f 166 PRINTER_PRINT(a);
ashleymills 0:c4a48036e46f 167 PRINTER_PRINT(b);
ashleymills 0:c4a48036e46f 168 PRINTER_PRINT(c);
ashleymills 0:c4a48036e46f 169 }
ashleymills 0:c4a48036e46f 170
ashleymills 0:c4a48036e46f 171 void AdafruitThermal::writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
ashleymills 0:c4a48036e46f 172 PRINTER_PRINT(a);
ashleymills 0:c4a48036e46f 173 PRINTER_PRINT(b);
ashleymills 0:c4a48036e46f 174 PRINTER_PRINT(c);
ashleymills 0:c4a48036e46f 175 PRINTER_PRINT(d);
ashleymills 0:c4a48036e46f 176 }
ashleymills 0:c4a48036e46f 177
ashleymills 0:c4a48036e46f 178 // === Character commands ===
ashleymills 0:c4a48036e46f 179
ashleymills 0:c4a48036e46f 180 #define INVERSE_MASK (1 << 1)
ashleymills 0:c4a48036e46f 181 #define UPDOWN_MASK (1 << 2)
ashleymills 0:c4a48036e46f 182 #define BOLD_MASK (1 << 3)
ashleymills 0:c4a48036e46f 183 #define DOUBLE_HEIGHT_MASK (1 << 4)
ashleymills 0:c4a48036e46f 184 #define DOUBLE_WIDTH_MASK (1 << 5)
ashleymills 0:c4a48036e46f 185 #define STRIKE_MASK (1 << 6)
ashleymills 0:c4a48036e46f 186
ashleymills 0:c4a48036e46f 187 void AdafruitThermal::setPrintMode(uint8_t mask) {
ashleymills 0:c4a48036e46f 188 printMode |= mask;
ashleymills 0:c4a48036e46f 189 writePrintMode();
ashleymills 0:c4a48036e46f 190 }
ashleymills 0:c4a48036e46f 191 void AdafruitThermal::unsetPrintMode(uint8_t mask) {
ashleymills 0:c4a48036e46f 192 printMode &= ~mask;
ashleymills 0:c4a48036e46f 193 writePrintMode();
ashleymills 0:c4a48036e46f 194 }
ashleymills 0:c4a48036e46f 195
ashleymills 0:c4a48036e46f 196 void AdafruitThermal::writePrintMode() {
ashleymills 0:c4a48036e46f 197 writeBytes(27, 33, printMode);
ashleymills 0:c4a48036e46f 198 }
ashleymills 0:c4a48036e46f 199
ashleymills 0:c4a48036e46f 200 void AdafruitThermal::normal() {
ashleymills 0:c4a48036e46f 201 printMode = 0;
ashleymills 0:c4a48036e46f 202 writePrintMode();
ashleymills 0:c4a48036e46f 203 }
ashleymills 0:c4a48036e46f 204
ashleymills 0:c4a48036e46f 205 void AdafruitThermal::inverseOn(){
ashleymills 0:c4a48036e46f 206 setPrintMode(INVERSE_MASK);
ashleymills 0:c4a48036e46f 207 }
ashleymills 0:c4a48036e46f 208
ashleymills 0:c4a48036e46f 209 void AdafruitThermal::inverseOff(){
ashleymills 0:c4a48036e46f 210 unsetPrintMode(INVERSE_MASK);
ashleymills 0:c4a48036e46f 211 }
ashleymills 0:c4a48036e46f 212
ashleymills 0:c4a48036e46f 213 void AdafruitThermal::upsideDownOn(){
ashleymills 0:c4a48036e46f 214 setPrintMode(UPDOWN_MASK);
ashleymills 0:c4a48036e46f 215 }
ashleymills 0:c4a48036e46f 216
ashleymills 0:c4a48036e46f 217 void AdafruitThermal::upsideDownOff(){
ashleymills 0:c4a48036e46f 218 unsetPrintMode(UPDOWN_MASK);
ashleymills 0:c4a48036e46f 219 }
ashleymills 0:c4a48036e46f 220
ashleymills 0:c4a48036e46f 221 void AdafruitThermal::doubleHeightOn(){
ashleymills 0:c4a48036e46f 222 setPrintMode(DOUBLE_HEIGHT_MASK);
ashleymills 0:c4a48036e46f 223 }
ashleymills 0:c4a48036e46f 224
ashleymills 0:c4a48036e46f 225 void AdafruitThermal::doubleHeightOff(){
ashleymills 0:c4a48036e46f 226 unsetPrintMode(DOUBLE_HEIGHT_MASK);
ashleymills 0:c4a48036e46f 227 }
ashleymills 0:c4a48036e46f 228
ashleymills 0:c4a48036e46f 229 void AdafruitThermal::doubleWidthOn(){
ashleymills 0:c4a48036e46f 230 setPrintMode(DOUBLE_WIDTH_MASK);
ashleymills 0:c4a48036e46f 231 }
ashleymills 0:c4a48036e46f 232
ashleymills 0:c4a48036e46f 233 void AdafruitThermal::doubleWidthOff(){
ashleymills 0:c4a48036e46f 234 unsetPrintMode(DOUBLE_WIDTH_MASK);
ashleymills 0:c4a48036e46f 235 }
ashleymills 0:c4a48036e46f 236
ashleymills 0:c4a48036e46f 237 void AdafruitThermal::strikeOn(){
ashleymills 0:c4a48036e46f 238 setPrintMode(STRIKE_MASK);
ashleymills 0:c4a48036e46f 239 }
ashleymills 0:c4a48036e46f 240
ashleymills 0:c4a48036e46f 241 void AdafruitThermal::strikeOff(){
ashleymills 0:c4a48036e46f 242 unsetPrintMode(STRIKE_MASK);
ashleymills 0:c4a48036e46f 243 }
ashleymills 0:c4a48036e46f 244
ashleymills 0:c4a48036e46f 245 void AdafruitThermal::boldOn(){
ashleymills 0:c4a48036e46f 246 setPrintMode(BOLD_MASK);
ashleymills 0:c4a48036e46f 247 }
ashleymills 0:c4a48036e46f 248
ashleymills 0:c4a48036e46f 249 void AdafruitThermal::boldOff(){
ashleymills 0:c4a48036e46f 250 unsetPrintMode(BOLD_MASK);
ashleymills 0:c4a48036e46f 251 }
ashleymills 0:c4a48036e46f 252
ashleymills 0:c4a48036e46f 253 void AdafruitThermal::justify(char value){
ashleymills 0:c4a48036e46f 254 uint8_t pos = 0;
ashleymills 0:c4a48036e46f 255
ashleymills 0:c4a48036e46f 256 if(value == 'l' || value == 'L') pos = 0;
ashleymills 0:c4a48036e46f 257 if(value == 'c' || value == 'C') pos = 1;
ashleymills 0:c4a48036e46f 258 if(value == 'r' || value == 'R') pos = 2;
ashleymills 0:c4a48036e46f 259
ashleymills 0:c4a48036e46f 260 writeBytes(0x1B, 0x61, pos);
ashleymills 0:c4a48036e46f 261 }
ashleymills 0:c4a48036e46f 262
ashleymills 0:c4a48036e46f 263 // Feeds by the specified number of lines
ashleymills 0:c4a48036e46f 264 void AdafruitThermal::feed(uint8_t x){
ashleymills 0:c4a48036e46f 265 // The datasheet claims sending bytes 27, 100, <x> will work
ashleymills 0:c4a48036e46f 266 // but it feeds much much more.
ashleymills 0:c4a48036e46f 267 while (x--)
ashleymills 0:c4a48036e46f 268 write('\n');
ashleymills 0:c4a48036e46f 269 }
ashleymills 0:c4a48036e46f 270
ashleymills 0:c4a48036e46f 271 // Feeds by the specified number of rows of pixels
ashleymills 0:c4a48036e46f 272 void AdafruitThermal::feedRows(uint8_t rows) {
ashleymills 0:c4a48036e46f 273 writeBytes(27, 74, rows);
ashleymills 0:c4a48036e46f 274 }
ashleymills 0:c4a48036e46f 275
ashleymills 0:c4a48036e46f 276 void AdafruitThermal::flush() {
ashleymills 0:c4a48036e46f 277 writeBytes(12);
ashleymills 0:c4a48036e46f 278 }
ashleymills 0:c4a48036e46f 279
ashleymills 0:c4a48036e46f 280 void AdafruitThermal::setSize(char value){
ashleymills 0:c4a48036e46f 281 int size = 0;
ashleymills 0:c4a48036e46f 282
ashleymills 0:c4a48036e46f 283 if(value == 's' || value == 'S') size = 0;
ashleymills 0:c4a48036e46f 284 if(value == 'm' || value == 'M') size = 10;
ashleymills 0:c4a48036e46f 285 if(value == 'l' || value == 'L') size = 25;
ashleymills 0:c4a48036e46f 286
ashleymills 0:c4a48036e46f 287 writeBytes(29, 33, size, 10);
ashleymills 0:c4a48036e46f 288 // if (linefeedneeded)
ashleymills 0:c4a48036e46f 289 // println("lfn"); //feed();
ashleymills 0:c4a48036e46f 290 //linefeedneeded = false;
ashleymills 0:c4a48036e46f 291 }
ashleymills 0:c4a48036e46f 292
ashleymills 0:c4a48036e46f 293 // Underlines of different weights can be produced:
ashleymills 0:c4a48036e46f 294 // 0 - no underline
ashleymills 0:c4a48036e46f 295 // 1 - normal underline
ashleymills 0:c4a48036e46f 296 // 2 - thick underline
ashleymills 0:c4a48036e46f 297 void AdafruitThermal::underlineOn(uint8_t weight) {
ashleymills 0:c4a48036e46f 298 writeBytes(27, 45, weight);
ashleymills 0:c4a48036e46f 299 }
ashleymills 0:c4a48036e46f 300
ashleymills 0:c4a48036e46f 301 void AdafruitThermal::underlineOff() {
ashleymills 0:c4a48036e46f 302 underlineOn(0);
ashleymills 0:c4a48036e46f 303 }
ashleymills 0:c4a48036e46f 304
SomeRandomBloke 2:6c38e763c285 305
ashleymills 0:c4a48036e46f 306 void AdafruitThermal::printBitmap(int w, int h, const uint8_t *bitmap) {
ashleymills 0:c4a48036e46f 307 if (w > 384) return; // maximum width of the printer
ashleymills 0:c4a48036e46f 308 for (int rowStart=0; rowStart < h; rowStart += 256) {
ashleymills 0:c4a48036e46f 309 int chunkHeight = ((h - rowStart) > 255) ? 255 : (h - rowStart);
ashleymills 0:c4a48036e46f 310 delay(500); // Need these delays else bitmap doesn't always print. ???
ashleymills 0:c4a48036e46f 311 writeBytes(18, 42);
ashleymills 0:c4a48036e46f 312 writeBytes(chunkHeight, w/8);
ashleymills 0:c4a48036e46f 313 delay(500);
ashleymills 0:c4a48036e46f 314 for (int i=0; i<((w/8)*chunkHeight); i++) {
SomeRandomBloke 2:6c38e763c285 315 PRINTER_PRINT(bitmap[(rowStart*(w/8)) + i]);
SomeRandomBloke 2:6c38e763c285 316 // PRINTER_PRINT(pgm_read_byte(bitmap + (rowStart*(w/8)) + i));
ashleymills 0:c4a48036e46f 317 }
ashleymills 0:c4a48036e46f 318 delay(500);
ashleymills 0:c4a48036e46f 319 }
ashleymills 0:c4a48036e46f 320 }
ashleymills 0:c4a48036e46f 321
SomeRandomBloke 2:6c38e763c285 322 /*
ashleymills 0:c4a48036e46f 323 void AdafruitThermal::printBitmap(int w, int h, Stream *stream) {
ashleymills 0:c4a48036e46f 324 if (w > 384) return; // maximum width of the printer
ashleymills 0:c4a48036e46f 325 for (int rowStart=0; rowStart < h; rowStart += 256) {
ashleymills 0:c4a48036e46f 326 int chunkHeight = ((h - rowStart) > 255) ? 255 : (h - rowStart);
ashleymills 0:c4a48036e46f 327 delay(500); // Need these delays else bitmap doesn't always print. ???
ashleymills 0:c4a48036e46f 328 writeBytes(18, 42);
ashleymills 0:c4a48036e46f 329 writeBytes(chunkHeight, w/8);
ashleymills 0:c4a48036e46f 330 delay(500);
ashleymills 0:c4a48036e46f 331 for (int i=0; i<((w/8)*chunkHeight); i++) {
ashleymills 0:c4a48036e46f 332 PRINTER_PRINT((uint8_t)stream->read());
ashleymills 0:c4a48036e46f 333 }
ashleymills 0:c4a48036e46f 334 delay(500);
ashleymills 0:c4a48036e46f 335 }
ashleymills 0:c4a48036e46f 336 };
ashleymills 0:c4a48036e46f 337
ashleymills 0:c4a48036e46f 338 void AdafruitThermal::printBitmap(Stream *stream) {
ashleymills 0:c4a48036e46f 339 uint8_t tmp;
ashleymills 0:c4a48036e46f 340 uint16_t width, height;
ashleymills 0:c4a48036e46f 341
ashleymills 0:c4a48036e46f 342 tmp = stream->read();
ashleymills 0:c4a48036e46f 343 width = (stream->read() << 8) + tmp;
ashleymills 0:c4a48036e46f 344
ashleymills 0:c4a48036e46f 345 tmp = stream->read();
ashleymills 0:c4a48036e46f 346 height = (stream->read() << 8) + tmp;
ashleymills 0:c4a48036e46f 347
ashleymills 0:c4a48036e46f 348 printBitmap(width, height, stream);
ashleymills 0:c4a48036e46f 349 };
ashleymills 0:c4a48036e46f 350 */
ashleymills 0:c4a48036e46f 351
ashleymills 0:c4a48036e46f 352 // Take the printer offline. Print commands sent after this will be
ashleymills 0:c4a48036e46f 353 // ignored until `online` is called
ashleymills 0:c4a48036e46f 354 void AdafruitThermal::offline(){
ashleymills 0:c4a48036e46f 355 writeBytes(27, 61, 0);
ashleymills 0:c4a48036e46f 356 }
ashleymills 0:c4a48036e46f 357
ashleymills 0:c4a48036e46f 358 // Take the printer back online. Subsequent print commands will be
ashleymills 0:c4a48036e46f 359 // obeyed.
ashleymills 0:c4a48036e46f 360 void AdafruitThermal::online(){
ashleymills 0:c4a48036e46f 361 writeBytes(27, 61, 1);
ashleymills 0:c4a48036e46f 362 }
ashleymills 0:c4a48036e46f 363
ashleymills 0:c4a48036e46f 364 // Put the printer into a low-energy state immediately
ashleymills 0:c4a48036e46f 365 void AdafruitThermal::sleep() {
ashleymills 0:c4a48036e46f 366 sleepAfter(0);
ashleymills 0:c4a48036e46f 367 }
ashleymills 0:c4a48036e46f 368
ashleymills 0:c4a48036e46f 369 // Put the printer into a low-energy state after the given number
ashleymills 0:c4a48036e46f 370 // of seconds
ashleymills 0:c4a48036e46f 371 void AdafruitThermal::sleepAfter(uint8_t seconds) {
ashleymills 0:c4a48036e46f 372 writeBytes(27, 56, seconds);
ashleymills 0:c4a48036e46f 373 }
ashleymills 0:c4a48036e46f 374
ashleymills 0:c4a48036e46f 375 // Wake the printer from a low-energy state. This command will wait
ashleymills 0:c4a48036e46f 376 // for 50ms (as directed by the datasheet) before allowing further
ashleymills 0:c4a48036e46f 377 // commands to be send.
ashleymills 0:c4a48036e46f 378 void AdafruitThermal::wake() {
ashleymills 0:c4a48036e46f 379 writeBytes(255);
ashleymills 0:c4a48036e46f 380 delay(50);
ashleymills 0:c4a48036e46f 381 }
ashleymills 0:c4a48036e46f 382
ashleymills 0:c4a48036e46f 383 ////////////////////// not working?
ashleymills 0:c4a48036e46f 384 void AdafruitThermal::tab(){
ashleymills 0:c4a48036e46f 385 PRINTER_PRINT(9);
ashleymills 0:c4a48036e46f 386 }
ashleymills 0:c4a48036e46f 387 void AdafruitThermal::setCharSpacing(int spacing) {
ashleymills 0:c4a48036e46f 388 writeBytes(27, 32, 0, 10);
ashleymills 0:c4a48036e46f 389 }
ashleymills 0:c4a48036e46f 390 void AdafruitThermal::setLineHeight(int val){
ashleymills 0:c4a48036e46f 391 writeBytes(27, 51, val); // default is 32
ashleymills 0:c4a48036e46f 392 }