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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AdafruitThermal.h Source File

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 hastily to mbed by Ashley Mills - NOTE: printBitmap not ported, nothing tested **/
00016 
00017 #pragma once
00018 
00019 #include "mbed.h"
00020 #include "rtos.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 PRINTER_PRINT(a) directPutc(a);
00037 //#define delay(a) wait(a/1000)
00038 #define delay(a) Thread::wait(a)
00039 
00040 
00041 
00042 class AdafruitThermal {
00043   public:
00044 
00045   AdafruitThermal(PinName RX_Pin, PinName TX_Pin);  // constructor
00046     void begin(int heatTime=255);
00047     void reset();
00048     void setDefault();
00049     void test();
00050     void testPage();
00051 
00052     void directPutc( uint8_t c );
00053     size_t write(uint8_t c);
00054 
00055 
00056     void normal();
00057     void inverseOn();
00058     void inverseOff();
00059     void upsideDownOn();
00060     void upsideDownOff();
00061     void doubleHeightOn();
00062     void doubleHeightOff();
00063     void doubleWidthOn();
00064     void doubleWidthOff();
00065     void boldOn();
00066     void boldOff();
00067     void underlineOn(uint8_t weight=1);
00068     void underlineOff();
00069     void strikeOn();
00070     void strikeOff();
00071 
00072     void justify(char value);
00073     void feed(uint8_t x = 1);
00074     void feedRows(uint8_t);
00075     void flush();
00076     void online();
00077     void offline();
00078     void sleep();
00079     void sleepAfter(uint8_t seconds);
00080     void wake();
00081     void print(char *string);
00082 
00083     void setCharSpacing(int spacing);
00084     void setSize(char value);
00085     void setLineHeight(int val = 32);
00086 
00087     void printBarcode(char * text, uint8_t type);
00088     void setBarcodeHeight(int val);
00089 
00090     // not ported
00091     void printBitmap(int w, int h, const uint8_t *bitmap);
00092 //    void printBitmap(int w, int h, Stream *stream);
00093 //    void printBitmap(Stream *stream);
00094 
00095     // ??
00096     void tab();
00097 
00098   protected:
00099     Serial * _printer;
00100     bool linefeedneeded;
00101 
00102     // little helpers to make code easier to read&use
00103     void writeBytes(uint8_t a);
00104     void writeBytes(uint8_t a, uint8_t b);
00105     void writeBytes(uint8_t a, uint8_t b, uint8_t c);
00106     void writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d);
00107 
00108     int printMode;
00109     void writePrintMode();
00110     void setPrintMode(uint8_t mask);
00111     void unsetPrintMode(uint8_t mask);
00112 
00113     PinName _RX_Pin;
00114     PinName _TX_Pin;
00115 };