Permalink
Browse files

Allow printing of larger bitmaps.

The maximum number of rows that can be printed at one time is 255 (since this is the byte limit), so we can print larger bitmaps by splitting them into chunks.
  • Loading branch information...
1 parent 294d8fb commit 6010b56a01015d1674b8b12969a08f0b4706ee0c @lazyatom committed Jan 19, 2012
Showing with 16 additions and 5 deletions.
  1. +13 −4 Thermal.cpp
  2. +3 −1 Thermal.h
View
@@ -246,10 +246,19 @@ void Thermal::underlineOn() {
writeBytes(27, 45, 1);
}
-void Thermal::printBitmap(uint8_t w, uint8_t h, const uint8_t *bitmap) {
- writeBytes(18, 42, h, w/8);
- for (int i=0; i<(w/8) * h; i++) {
- PRINTER_PRINT(pgm_read_byte(bitmap + i));
+void Thermal::printBitmap(int w, int h, const uint8_t *bitmap) {
+ if (w > 384) return; // maximum width of the printer
+ for (int rowStart=0; rowStart < h; rowStart += 256) {
+ int chunkHeight = ((h - rowStart) > 255) ? 255 : (h - rowStart);
+ printBitmapChunk(w, chunkHeight, rowStart*w, bitmap);
+ }
+}
+
+void Thermal::printBitmapChunk(int w, uint8_t h, int offset, const uint8_t *bitmap) {
+ writeBytes(18, 42);
+ writeBytes(h, w/8);
+ for (int i=0; i<((w/8)*h); i++) {
+ PRINTER_PRINT(pgm_read_byte(bitmap + offset + i));
}
}
View
@@ -72,7 +72,7 @@ class Thermal : public Print {
void printBarcode(char * text, uint8_t type);
void setBarcodeHeight(int val);
- void printBitmap(uint8_t w, uint8_t h, const uint8_t *bitmap);
+ void printBitmap(int w, int h, const uint8_t *bitmap);
// ??
void tab();
@@ -92,6 +92,8 @@ class Thermal : public Print {
void setPrintMode(uint8_t mask);
void unsetPrintMode(uint8_t mask);
+ void printBitmapChunk(int w, uint8_t h, int offset, const uint8_t *bitmap);
+
int _RX_Pin;
int _TX_Pin;

0 comments on commit 6010b56

Please sign in to comment.