Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Thermal_HelloWorld
Fork of AdafruitThermalPrinter by
AdafruitThermal.h
00001 /*************************************************** 00002 This is a library for the Adafruit Thermal Printer 00003 00004 Pick one up at --> http://www.adafruit.com/products/597 00005 These printers use TTL serial to communicate, 2 pins are required 00006 00007 Adafruit invests time and resources providing this open source code, 00008 please support Adafruit and open-source hardware by purchasing 00009 products from Adafruit! 00010 00011 Written by Limor Fried/Ladyada for Adafruit Industries. 00012 MIT license, all text above must be included in any redistribution 00013 ****************************************************/ 00014 00015 // Ported to mbed by Ashley Mills 00016 // Documentation by Andrew Ross - NOTE: printBitmap not ported, nothing tested 00017 00018 #pragma once 00019 00020 #include "mbed.h" 00021 00022 #define UPC_A 0 00023 #define UPC_E 1 00024 #define EAN13 2 00025 #define EAN8 3 00026 #define CODE39 4 00027 #define I25 5 00028 #define CODEBAR 6 00029 #define CODE93 7 00030 #define CODE128 8 00031 #define CODE11 9 00032 #define MSI 10 00033 00034 00035 #define PRINTER_PRINT(a) _printer->putc(a); 00036 #define delay(a) wait(a/1000) 00037 00038 //************************************************************************** 00039 // \class AdafruitThermal AdafruitThermal.h 00040 // \brief This is the main class. It shoud be used like this : AdafruitThermal printer(p9,p10); 00041 /** 00042 Example: 00043 * @code 00044 * // Print a char array onto the thermal paper 00045 * #include "mbed.h" 00046 * #include "AdafruitThermal.h" 00047 * 00048 * AdafruitThermal printer(p9,p10); 00049 * 00050 * int main() { 00051 * printer.begin(); 00052 * char *Text_Out = "Hello World!\n"; 00053 * printer.print(Text_Out); 00054 * } 00055 * @endcode 00056 */ 00057 00058 class AdafruitThermal { 00059 public: 00060 00061 AdafruitThermal(PinName RX_Pin, PinName TX_Pin); // constructor 00062 void begin(int heatTime=255); 00063 void reset(); 00064 00065 // General Commands ******************************************************************************* 00066 00067 /** Sets Default settings on printer*/ 00068 void setDefault(); 00069 void test(); 00070 void testPage(); 00071 00072 /** Basic function for all printing. Prints character to stream 00073 * @param char to print (see AdafruitThermal.h) 00074 */ 00075 size_t write(uint8_t c); 00076 00077 void normal(); 00078 00079 /** Inverses the printer color space*/ 00080 void inverseOn(); 00081 00082 /** Turns off inverse*/ 00083 void inverseOff(); 00084 void upsideDownOn(); 00085 void upsideDownOff(); 00086 void doubleHeightOn(); 00087 void doubleHeightOff(); 00088 void doubleWidthOn(); 00089 void doubleWidthOff(); 00090 void boldOn(); 00091 void boldOff(); 00092 void underlineOn(uint8_t weight=1); 00093 void underlineOff(); 00094 void strikeOn(); 00095 void strikeOff(); 00096 00097 /** Allows you to left, right or center justify your text 00098 * @param string containing L, R, or C for alignment 00099 */ 00100 void justify(char value); 00101 void feed(uint8_t x = 1); 00102 void feedRows(uint8_t); 00103 void flush(); 00104 void online(); 00105 void offline(); 00106 void sleep(); 00107 void sleepAfter(uint8_t seconds); 00108 void wake(); 00109 00110 /** Main function to print information 00111 * @param array of chars which is parsed by the write function 00112 */ 00113 void print(char *string); 00114 00115 void setCharSpacing(int spacing); 00116 void setSize(char value); 00117 void setLineHeight(int val = 32); 00118 00119 void printBarcode(char * text, uint8_t type); 00120 void setBarcodeHeight(int val); 00121 00122 // not ported 00123 //void printBitmap(int w, int h, const uint8_t *bitmap); 00124 //void printBitmap(int w, int h, Stream *stream); 00125 //void printBitmap(Stream *stream); 00126 00127 // ?? 00128 void tab(); 00129 00130 protected: 00131 Serial * _printer; 00132 bool linefeedneeded; 00133 00134 // little helpers to make code easier to read&use 00135 void writeBytes(uint8_t a); 00136 void writeBytes(uint8_t a, uint8_t b); 00137 void writeBytes(uint8_t a, uint8_t b, uint8_t c); 00138 void writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d); 00139 00140 int printMode; 00141 void writePrintMode(); 00142 void setPrintMode(uint8_t mask); 00143 void unsetPrintMode(uint8_t mask); 00144 00145 PinName _RX_Pin; 00146 PinName _TX_Pin; 00147 };
Generated on Sun Jul 17 2022 11:40:08 by
1.7.2

Adafruit Thermal Printer