Library for Adafruit Thermal Printer. Arduino library is published here: http://www.ladyada.net/products/thermalprinter/

Dependents:   Thermal_HelloWorld

Fork of AdafruitThermalPrinter by Ashley Mills

Committer:
aross34
Date:
Wed Mar 16 19:55:29 2016 +0000
Revision:
3:1f832bfe41d1
Parent:
2:de26317d87a6
Trouble with Inverse On even following user manual strictly

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
aross34 2:de26317d87a6 15 // Ported to mbed by Ashley Mills
aross34 2:de26317d87a6 16 // Documentation by Andrew Ross - NOTE: printBitmap not ported, nothing tested
ashleymills 0:c4a48036e46f 17
ashleymills 0:c4a48036e46f 18 #pragma once
ashleymills 0:c4a48036e46f 19
ashleymills 0:c4a48036e46f 20 #include "mbed.h"
ashleymills 0:c4a48036e46f 21
ashleymills 0:c4a48036e46f 22 #define UPC_A 0
ashleymills 0:c4a48036e46f 23 #define UPC_E 1
ashleymills 0:c4a48036e46f 24 #define EAN13 2
ashleymills 0:c4a48036e46f 25 #define EAN8 3
ashleymills 0:c4a48036e46f 26 #define CODE39 4
ashleymills 0:c4a48036e46f 27 #define I25 5
ashleymills 0:c4a48036e46f 28 #define CODEBAR 6
ashleymills 0:c4a48036e46f 29 #define CODE93 7
ashleymills 0:c4a48036e46f 30 #define CODE128 8
ashleymills 0:c4a48036e46f 31 #define CODE11 9
ashleymills 0:c4a48036e46f 32 #define MSI 10
ashleymills 0:c4a48036e46f 33
ashleymills 0:c4a48036e46f 34
ashleymills 0:c4a48036e46f 35 #define PRINTER_PRINT(a) _printer->putc(a);
ashleymills 0:c4a48036e46f 36 #define delay(a) wait(a/1000)
ashleymills 0:c4a48036e46f 37
aross34 2:de26317d87a6 38 //**************************************************************************
aross34 2:de26317d87a6 39 // \class AdafruitThermal AdafruitThermal.h
aross34 2:de26317d87a6 40 // \brief This is the main class. It shoud be used like this : AdafruitThermal printer(p9,p10);
aross34 2:de26317d87a6 41 /**
aross34 2:de26317d87a6 42 Example:
aross34 2:de26317d87a6 43 * @code
aross34 2:de26317d87a6 44 * // Print a char array onto the thermal paper
aross34 2:de26317d87a6 45 * #include "mbed.h"
aross34 2:de26317d87a6 46 * #include "AdafruitThermal.h"
aross34 2:de26317d87a6 47 *
aross34 2:de26317d87a6 48 * AdafruitThermal printer(p9,p10);
aross34 2:de26317d87a6 49 *
aross34 2:de26317d87a6 50 * int main() {
aross34 2:de26317d87a6 51 * printer.begin();
aross34 2:de26317d87a6 52 * char *Text_Out = "Hello World!\n";
aross34 2:de26317d87a6 53 * printer.print(Text_Out);
aross34 2:de26317d87a6 54 * }
aross34 2:de26317d87a6 55 * @endcode
aross34 2:de26317d87a6 56 */
ashleymills 0:c4a48036e46f 57
ashleymills 0:c4a48036e46f 58 class AdafruitThermal {
ashleymills 0:c4a48036e46f 59 public:
ashleymills 0:c4a48036e46f 60
ashleymills 0:c4a48036e46f 61 AdafruitThermal(PinName RX_Pin, PinName TX_Pin); // constructor
ashleymills 0:c4a48036e46f 62 void begin(int heatTime=255);
ashleymills 0:c4a48036e46f 63 void reset();
aross34 2:de26317d87a6 64
aross34 2:de26317d87a6 65 // General Commands *******************************************************************************
aross34 2:de26317d87a6 66
aross34 2:de26317d87a6 67 /** Sets Default settings on printer*/
ashleymills 0:c4a48036e46f 68 void setDefault();
ashleymills 0:c4a48036e46f 69 void test();
ashleymills 0:c4a48036e46f 70 void testPage();
ashleymills 0:c4a48036e46f 71
aross34 2:de26317d87a6 72 /** Basic function for all printing. Prints character to stream
aross34 2:de26317d87a6 73 * @param char to print (see AdafruitThermal.h)
aross34 2:de26317d87a6 74 */
ashleymills 0:c4a48036e46f 75 size_t write(uint8_t c);
aross34 2:de26317d87a6 76
ashleymills 0:c4a48036e46f 77 void normal();
aross34 2:de26317d87a6 78
aross34 2:de26317d87a6 79 /** Inverses the printer color space*/
ashleymills 0:c4a48036e46f 80 void inverseOn();
aross34 2:de26317d87a6 81
aross34 2:de26317d87a6 82 /** Turns off inverse*/
ashleymills 0:c4a48036e46f 83 void inverseOff();
ashleymills 0:c4a48036e46f 84 void upsideDownOn();
ashleymills 0:c4a48036e46f 85 void upsideDownOff();
ashleymills 0:c4a48036e46f 86 void doubleHeightOn();
ashleymills 0:c4a48036e46f 87 void doubleHeightOff();
ashleymills 0:c4a48036e46f 88 void doubleWidthOn();
ashleymills 0:c4a48036e46f 89 void doubleWidthOff();
ashleymills 0:c4a48036e46f 90 void boldOn();
ashleymills 0:c4a48036e46f 91 void boldOff();
ashleymills 0:c4a48036e46f 92 void underlineOn(uint8_t weight=1);
ashleymills 0:c4a48036e46f 93 void underlineOff();
ashleymills 0:c4a48036e46f 94 void strikeOn();
ashleymills 0:c4a48036e46f 95 void strikeOff();
ashleymills 0:c4a48036e46f 96
aross34 2:de26317d87a6 97 /** Allows you to left, right or center justify your text
aross34 2:de26317d87a6 98 * @param string containing L, R, or C for alignment
aross34 2:de26317d87a6 99 */
ashleymills 0:c4a48036e46f 100 void justify(char value);
ashleymills 0:c4a48036e46f 101 void feed(uint8_t x = 1);
ashleymills 0:c4a48036e46f 102 void feedRows(uint8_t);
ashleymills 0:c4a48036e46f 103 void flush();
ashleymills 0:c4a48036e46f 104 void online();
ashleymills 0:c4a48036e46f 105 void offline();
ashleymills 0:c4a48036e46f 106 void sleep();
ashleymills 0:c4a48036e46f 107 void sleepAfter(uint8_t seconds);
ashleymills 0:c4a48036e46f 108 void wake();
aross34 2:de26317d87a6 109
aross34 2:de26317d87a6 110 /** Main function to print information
aross34 2:de26317d87a6 111 * @param array of chars which is parsed by the write function
aross34 2:de26317d87a6 112 */
ashleymills 0:c4a48036e46f 113 void print(char *string);
ashleymills 0:c4a48036e46f 114
ashleymills 0:c4a48036e46f 115 void setCharSpacing(int spacing);
ashleymills 0:c4a48036e46f 116 void setSize(char value);
ashleymills 0:c4a48036e46f 117 void setLineHeight(int val = 32);
ashleymills 0:c4a48036e46f 118
ashleymills 0:c4a48036e46f 119 void printBarcode(char * text, uint8_t type);
ashleymills 0:c4a48036e46f 120 void setBarcodeHeight(int val);
ashleymills 0:c4a48036e46f 121
ashleymills 1:315c49946ded 122 // not ported
ashleymills 1:315c49946ded 123 //void printBitmap(int w, int h, const uint8_t *bitmap);
ashleymills 1:315c49946ded 124 //void printBitmap(int w, int h, Stream *stream);
ashleymills 1:315c49946ded 125 //void printBitmap(Stream *stream);
ashleymills 0:c4a48036e46f 126
ashleymills 0:c4a48036e46f 127 // ??
ashleymills 0:c4a48036e46f 128 void tab();
ashleymills 0:c4a48036e46f 129
ashleymills 0:c4a48036e46f 130 protected:
ashleymills 0:c4a48036e46f 131 Serial * _printer;
ashleymills 0:c4a48036e46f 132 bool linefeedneeded;
ashleymills 0:c4a48036e46f 133
ashleymills 0:c4a48036e46f 134 // little helpers to make code easier to read&use
ashleymills 0:c4a48036e46f 135 void writeBytes(uint8_t a);
ashleymills 0:c4a48036e46f 136 void writeBytes(uint8_t a, uint8_t b);
ashleymills 0:c4a48036e46f 137 void writeBytes(uint8_t a, uint8_t b, uint8_t c);
ashleymills 0:c4a48036e46f 138 void writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d);
ashleymills 0:c4a48036e46f 139
ashleymills 0:c4a48036e46f 140 int printMode;
ashleymills 0:c4a48036e46f 141 void writePrintMode();
ashleymills 0:c4a48036e46f 142 void setPrintMode(uint8_t mask);
ashleymills 0:c4a48036e46f 143 void unsetPrintMode(uint8_t mask);
ashleymills 0:c4a48036e46f 144
ashleymills 0:c4a48036e46f 145 PinName _RX_Pin;
ashleymills 0:c4a48036e46f 146 PinName _TX_Pin;
ashleymills 0:c4a48036e46f 147 };