Skip to content

Commit f877224

Browse files
Laurence BankLaurence Bank
authored andcommitted
Merge branch 'Experimental'
2 parents 7b45e78 + e64f29f commit f877224

File tree

9 files changed

+7433
-86
lines changed

9 files changed

+7433
-86
lines changed

examples/custom_font/FreeSerif12pt7b.h

Lines changed: 258 additions & 0 deletions
Large diffs are not rendered by default.

examples/custom_font/OpenSansBold64.h

Lines changed: 200 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// Custom Font Demo
3+
//
4+
// Print Adafruit_GFX bitmap fonts on inexpensive thermal printers
5+
// as line-at-a-time graphics output which doesn't require any bitmap buffers
6+
//
7+
// written by Larry Bank
8+
// Copyright (c) 2021 BitBank Software, Inc.
9+
//
10+
// This program is free software: you can redistribute it and/or modify
11+
// it under the terms of the GNU General Public License as published by
12+
// the Free Software Foundation, either version 3 of the License, or
13+
// (at your option) any later version.
14+
//
15+
// This program is distributed in the hope that it will be useful,
16+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
// GNU General Public License for more details.
19+
//
20+
// You should have received a copy of the GNU General Public License
21+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
//
23+
24+
#include <Thermal_Printer.h>
25+
#include "FreeSerif12pt7b.h"
26+
#include "OpenSansBold64.h"
27+
28+
void setup() {
29+
int iWidth;
30+
// put your setup code here, to run once:
31+
Serial.begin(115200);
32+
while (!Serial);
33+
Serial.println((char *)"Scanning for BLE printer");
34+
if (tpScan()) // Scan for any supported printer name
35+
{
36+
Serial.println((char *)"Found a printer!, connecting...");
37+
if (tpConnect())
38+
{
39+
char *szName = tpGetName();
40+
Serial.println((char *)"Connected!");
41+
iWidth = tpGetWidth();
42+
Serial.print("Printer pixel width = ");
43+
Serial.println(iWidth, DEC);
44+
Serial.print("Reported printer name = ");
45+
Serial.println(szName);
46+
// optionally speed up BLE data throughput if your MCU supports it
47+
// tpSetWriteMode(MODE_WITHOUT_RESPONSE);
48+
// Draw text with a custom proportional font
49+
Serial.println("Printing custom fonts");
50+
// You can use the tpDrawCustomText to draw these same fonts
51+
// into your graphics buffer instead of sending directly to the printer
52+
tpPrintCustomText((GFXfont *)&FreeSerif12pt7b, 0, (char *)"You too can print nice looking fonts");
53+
tpPrintCustomText((GFXfont *)&FreeSerif12pt7b, 0, (char *)"with Adafruit_GFX bitmap format.");
54+
tpPrintCustomText((GFXfont *)&Open_Sans_Bold_64, 0, (char *)"Huge fonts!");
55+
tpFeed(48); // feed the paper out a little from the print head to see what was printed
56+
Serial.println((char *)"Disconnecting");
57+
tpDisconnect();
58+
Serial.println((char *)"Done!");
59+
while (1) {};
60+
} // if connected
61+
} // successful scan
62+
else
63+
{
64+
Serial.println((char *)"Didn't find a printer :( ");
65+
}
66+
} /* setup() */
67+
68+
void loop() {
69+
// nothing going on here :)
70+
}

examples/print_photo/dog_384.h

Lines changed: 3615 additions & 0 deletions
Large diffs are not rendered by default.

examples/print_photo/eagle_576.h

Lines changed: 2533 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <Thermal_Printer.h>
2+
#include <JPEGDEC.h>
3+
4+
#include "eagle_576.h"
5+
#include "dog_384.h"
6+
7+
uint8_t ucDither[576 * 16]; // buffer for the dithered pixel output
8+
JPEGDEC jpg;
9+
static int iWidth;
10+
11+
int JPEGDraw(JPEGDRAW *pDraw)
12+
{
13+
int i, iCount;
14+
uint8_t *s = (uint8_t *)pDraw->pPixels;
15+
16+
tpSetBackBuffer((uint8_t *)pDraw->pPixels, pDraw->iWidth, pDraw->iHeight);
17+
// The output is inverted, so flip the bits
18+
iCount = (pDraw->iWidth * pDraw->iHeight)/8;
19+
for (i=0; i<iCount; i++)
20+
s[i] = ~s[i];
21+
22+
tpPrintBuffer(); // Print this block of pixels
23+
return 1; // Continue decode
24+
} /* JPEGDraw() */
25+
26+
void setup() {
27+
Serial.begin(115200);
28+
while (!Serial);
29+
Serial.println((char *)"Scanning for BLE printer");
30+
if (tpScan()) // Scan for any supported printer name
31+
{
32+
Serial.println((char *)"Found a printer!, connecting...");
33+
if (tpConnect())
34+
{
35+
Serial.println("Connected!");
36+
tpSetWriteMode(MODE_WITHOUT_RESPONSE);
37+
}
38+
else
39+
{
40+
Serial.println("Failed to connected :(");
41+
while (1) {};
42+
}
43+
} // if scan
44+
else
45+
{
46+
Serial.println((char *)"Didn't find a printer :( ");
47+
while (1) {};
48+
}
49+
} /* setup () */
50+
51+
void loop() {
52+
uint8_t *pImage;
53+
int iImageSize;
54+
55+
iWidth = tpGetWidth(); // get the width of the printer in pixels
56+
if (iWidth == 384) {
57+
pImage = (uint8_t *)dog_384;
58+
iImageSize = (int)sizeof(dog_384);
59+
} else { // assume 576
60+
pImage = (uint8_t *)eagle_576;
61+
iImageSize = (int)sizeof(eagle_576);
62+
}
63+
if (jpg.openFLASH(pImage, iImageSize, JPEGDraw)) {
64+
jpg.setPixelType(ONE_BIT_DITHERED);
65+
jpg.decodeDither(ucDither, 0);
66+
}
67+
tpFeed(32); // advance the paper 32 scan lines
68+
tpDisconnect();
69+
Serial.println("Finished printing!");
70+
while (1) {};
71+
} /* loop() */

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Thermal Printer Library
2-
version=1.1.2
2+
version=2.0.0
33
author=Larry Bank
44
maintainer=Larry Bank <[email protected]>
55
sentence=Bluetooth Low Energy Thermal Printer Library
6-
paragraph=BLE thermal printer library allows you to easily scan, connect and print graphics plus text.
6+
paragraph=BLE thermal printer library allows you to easily scan, connect and print graphics plus text on a variety of supported printers.
77
category=Device Control
88
url=https://github.com/bitbank2/Thermal_Printer
99
architectures=nrf52,esp32

0 commit comments

Comments
 (0)