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
AdafruitThermal.h@4:871ca02007be, 2013-01-18 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Fri Jan 18 08:38:24 2013 +0000
- Revision:
- 4:871ca02007be
- Parent:
- 3:0e12bed6b295
update
Who changed what in which revision?
User | Revision | Line number | New 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 | |
ashleymills | 0:c4a48036e46f | 17 | #pragma once |
ashleymills | 0:c4a48036e46f | 18 | |
ashleymills | 0:c4a48036e46f | 19 | #include "mbed.h" |
SomeRandomBloke | 3:0e12bed6b295 | 20 | #include "rtos.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 | |
SomeRandomBloke | 3:0e12bed6b295 | 35 | //#define PRINTER_PRINT(a) _printer->putc(a); |
SomeRandomBloke | 3:0e12bed6b295 | 36 | #define PRINTER_PRINT(a) directPutc(a); |
SomeRandomBloke | 3:0e12bed6b295 | 37 | //#define delay(a) wait(a/1000) |
SomeRandomBloke | 3:0e12bed6b295 | 38 | #define delay(a) Thread::wait(a) |
ashleymills | 0:c4a48036e46f | 39 | |
ashleymills | 0:c4a48036e46f | 40 | |
ashleymills | 0:c4a48036e46f | 41 | |
ashleymills | 0:c4a48036e46f | 42 | class AdafruitThermal { |
ashleymills | 0:c4a48036e46f | 43 | public: |
ashleymills | 0:c4a48036e46f | 44 | |
ashleymills | 0:c4a48036e46f | 45 | AdafruitThermal(PinName RX_Pin, PinName TX_Pin); // constructor |
ashleymills | 0:c4a48036e46f | 46 | void begin(int heatTime=255); |
ashleymills | 0:c4a48036e46f | 47 | void reset(); |
ashleymills | 0:c4a48036e46f | 48 | void setDefault(); |
ashleymills | 0:c4a48036e46f | 49 | void test(); |
ashleymills | 0:c4a48036e46f | 50 | void testPage(); |
ashleymills | 0:c4a48036e46f | 51 | |
SomeRandomBloke | 3:0e12bed6b295 | 52 | void directPutc( uint8_t c ); |
ashleymills | 0:c4a48036e46f | 53 | size_t write(uint8_t c); |
ashleymills | 0:c4a48036e46f | 54 | |
ashleymills | 0:c4a48036e46f | 55 | |
ashleymills | 0:c4a48036e46f | 56 | void normal(); |
ashleymills | 0:c4a48036e46f | 57 | void inverseOn(); |
ashleymills | 0:c4a48036e46f | 58 | void inverseOff(); |
ashleymills | 0:c4a48036e46f | 59 | void upsideDownOn(); |
ashleymills | 0:c4a48036e46f | 60 | void upsideDownOff(); |
ashleymills | 0:c4a48036e46f | 61 | void doubleHeightOn(); |
ashleymills | 0:c4a48036e46f | 62 | void doubleHeightOff(); |
ashleymills | 0:c4a48036e46f | 63 | void doubleWidthOn(); |
ashleymills | 0:c4a48036e46f | 64 | void doubleWidthOff(); |
ashleymills | 0:c4a48036e46f | 65 | void boldOn(); |
ashleymills | 0:c4a48036e46f | 66 | void boldOff(); |
ashleymills | 0:c4a48036e46f | 67 | void underlineOn(uint8_t weight=1); |
ashleymills | 0:c4a48036e46f | 68 | void underlineOff(); |
ashleymills | 0:c4a48036e46f | 69 | void strikeOn(); |
ashleymills | 0:c4a48036e46f | 70 | void strikeOff(); |
ashleymills | 0:c4a48036e46f | 71 | |
ashleymills | 0:c4a48036e46f | 72 | void justify(char value); |
ashleymills | 0:c4a48036e46f | 73 | void feed(uint8_t x = 1); |
ashleymills | 0:c4a48036e46f | 74 | void feedRows(uint8_t); |
ashleymills | 0:c4a48036e46f | 75 | void flush(); |
ashleymills | 0:c4a48036e46f | 76 | void online(); |
ashleymills | 0:c4a48036e46f | 77 | void offline(); |
ashleymills | 0:c4a48036e46f | 78 | void sleep(); |
ashleymills | 0:c4a48036e46f | 79 | void sleepAfter(uint8_t seconds); |
ashleymills | 0:c4a48036e46f | 80 | void wake(); |
ashleymills | 0:c4a48036e46f | 81 | void print(char *string); |
ashleymills | 0:c4a48036e46f | 82 | |
ashleymills | 0:c4a48036e46f | 83 | void setCharSpacing(int spacing); |
ashleymills | 0:c4a48036e46f | 84 | void setSize(char value); |
ashleymills | 0:c4a48036e46f | 85 | void setLineHeight(int val = 32); |
ashleymills | 0:c4a48036e46f | 86 | |
ashleymills | 0:c4a48036e46f | 87 | void printBarcode(char * text, uint8_t type); |
ashleymills | 0:c4a48036e46f | 88 | void setBarcodeHeight(int val); |
ashleymills | 0:c4a48036e46f | 89 | |
ashleymills | 1:315c49946ded | 90 | // not ported |
SomeRandomBloke | 2:6c38e763c285 | 91 | void printBitmap(int w, int h, const uint8_t *bitmap); |
SomeRandomBloke | 2:6c38e763c285 | 92 | // void printBitmap(int w, int h, Stream *stream); |
SomeRandomBloke | 2:6c38e763c285 | 93 | // void printBitmap(Stream *stream); |
ashleymills | 0:c4a48036e46f | 94 | |
ashleymills | 0:c4a48036e46f | 95 | // ?? |
ashleymills | 0:c4a48036e46f | 96 | void tab(); |
ashleymills | 0:c4a48036e46f | 97 | |
ashleymills | 0:c4a48036e46f | 98 | protected: |
ashleymills | 0:c4a48036e46f | 99 | Serial * _printer; |
ashleymills | 0:c4a48036e46f | 100 | bool linefeedneeded; |
ashleymills | 0:c4a48036e46f | 101 | |
ashleymills | 0:c4a48036e46f | 102 | // little helpers to make code easier to read&use |
ashleymills | 0:c4a48036e46f | 103 | void writeBytes(uint8_t a); |
ashleymills | 0:c4a48036e46f | 104 | void writeBytes(uint8_t a, uint8_t b); |
ashleymills | 0:c4a48036e46f | 105 | void writeBytes(uint8_t a, uint8_t b, uint8_t c); |
ashleymills | 0:c4a48036e46f | 106 | void writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d); |
ashleymills | 0:c4a48036e46f | 107 | |
ashleymills | 0:c4a48036e46f | 108 | int printMode; |
ashleymills | 0:c4a48036e46f | 109 | void writePrintMode(); |
ashleymills | 0:c4a48036e46f | 110 | void setPrintMode(uint8_t mask); |
ashleymills | 0:c4a48036e46f | 111 | void unsetPrintMode(uint8_t mask); |
ashleymills | 0:c4a48036e46f | 112 | |
ashleymills | 0:c4a48036e46f | 113 | PinName _RX_Pin; |
ashleymills | 0:c4a48036e46f | 114 | PinName _TX_Pin; |
ashleymills | 0:c4a48036e46f | 115 | }; |