Library for Adafruit Thermal Printer. Arduino library is published here: http://www.ladyada.net/products/thermalprinter/
Dependents: Thermal_HelloWorld
Fork of AdafruitThermalPrinter by
Revision 2:de26317d87a6, committed 2016-03-16
- Comitter:
- aross34
- Date:
- Wed Mar 16 01:40:10 2016 +0000
- Parent:
- 1:315c49946ded
- Child:
- 3:1f832bfe41d1
- Commit message:
- Hello world program for Adafruit nano thermal printer. Added library documentation.
Changed in this revision
| AdafruitThermal.cpp | Show annotated file Show diff for this revision Revisions of this file |
| AdafruitThermal.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/AdafruitThermal.cpp Fri Jun 29 08:42:23 2012 +0000
+++ b/AdafruitThermal.cpp Wed Mar 16 01:40:10 2016 +0000
@@ -12,7 +12,9 @@
MIT license, all text above must be included in any redistribution
****************************************************/
-/** Ported hastily to mbed by Ashley Mills - NOTE: printBitmap not ported, nothing tested **/
+// Ported to mbed by Ashley Mills
+/** Documentation by Andrew Ross - NOTE: printBitmap not ported, nothing tested **/
+
#include "mbed.h"
#include "AdafruitThermal.h"
@@ -24,7 +26,7 @@
void AdafruitThermal::begin(int heatTime) {
_printer = new Serial(_RX_Pin, _TX_Pin);
- _printer->baud(19200);
+ _printer->baud(9600);
// The printer can't start receiving data immediately
// upon power up -- needs a moment to initialize. If
@@ -106,6 +108,7 @@
write(*string);
string++;
}
+ feed(2);
}
void AdafruitThermal::testPage() {
@@ -203,11 +206,13 @@
}
void AdafruitThermal::inverseOn(){
- setPrintMode(INVERSE_MASK);
+ //setPrintMode(INVERSE_MASK);
+ writeBytes(29, 'B', 1);
}
void AdafruitThermal::inverseOff(){
- unsetPrintMode(INVERSE_MASK);
+ //unsetPrintMode(INVERSE_MASK);
+ writeBytes(29, 'B', 0, 10);
}
void AdafruitThermal::upsideDownOn(){
@@ -247,7 +252,12 @@
}
void AdafruitThermal::boldOff(){
- unsetPrintMode(BOLD_MASK);
+ //unsetPrintMode(BOLD_MASK);
+ //writeBytes(27, 69, 0);
+ // if (linefeedneeded)
+ // feed();
+
+ //linefeedneeded = false;
}
void AdafruitThermal::justify(char value){
@@ -300,6 +310,8 @@
void AdafruitThermal::underlineOff() {
underlineOn(0);
+ //writeBytes(27, 45, 0, 10);
+ //Writing text with underline will work but seems to be a problem printing after turning off underline
}
/*
--- a/AdafruitThermal.h Fri Jun 29 08:42:23 2012 +0000
+++ b/AdafruitThermal.h Wed Mar 16 01:40:10 2016 +0000
@@ -12,7 +12,8 @@
MIT license, all text above must be included in any redistribution
****************************************************/
-/** Ported hastily to mbed by Ashley Mills - NOTE: printBitmap not ported, nothing tested **/
+// Ported to mbed by Ashley Mills
+// Documentation by Andrew Ross - NOTE: printBitmap not ported, nothing tested
#pragma once
@@ -34,7 +35,25 @@
#define PRINTER_PRINT(a) _printer->putc(a);
#define delay(a) wait(a/1000)
-
+//**************************************************************************
+// \class AdafruitThermal AdafruitThermal.h
+// \brief This is the main class. It shoud be used like this : AdafruitThermal printer(p9,p10);
+/**
+Example:
+* @code
+* // Print a char array onto the thermal paper
+* #include "mbed.h"
+* #include "AdafruitThermal.h"
+*
+* AdafruitThermal printer(p9,p10);
+*
+* int main() {
+* printer.begin();
+* char *Text_Out = "Hello World!\n";
+* printer.print(Text_Out);
+* }
+* @endcode
+*/
class AdafruitThermal {
public:
@@ -42,15 +61,25 @@
AdafruitThermal(PinName RX_Pin, PinName TX_Pin); // constructor
void begin(int heatTime=255);
void reset();
+
+ // General Commands *******************************************************************************
+
+ /** Sets Default settings on printer*/
void setDefault();
void test();
void testPage();
+ /** Basic function for all printing. Prints character to stream
+ * @param char to print (see AdafruitThermal.h)
+ */
size_t write(uint8_t c);
-
-
+
void normal();
+
+ /** Inverses the printer color space*/
void inverseOn();
+
+ /** Turns off inverse*/
void inverseOff();
void upsideDownOn();
void upsideDownOff();
@@ -65,6 +94,9 @@
void strikeOn();
void strikeOff();
+ /** Allows you to left, right or center justify your text
+ * @param string containing L, R, or C for alignment
+ */
void justify(char value);
void feed(uint8_t x = 1);
void feedRows(uint8_t);
@@ -74,6 +106,10 @@
void sleep();
void sleepAfter(uint8_t seconds);
void wake();
+
+ /** Main function to print information
+ * @param array of chars which is parsed by the write function
+ */
void print(char *string);
void setCharSpacing(int spacing);

Adafruit Thermal Printer