|
| 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 | +} |
0 commit comments