AS-289R2 Thermal Printer Shield Sample Program.

Dependencies:   AS289R2

Fork of AS-289R2_Hello-mbed-OS-World by Toyomasa Watarai

Committer:
takehiro
Date:
Sat Mar 11 09:11:46 2017 +0000
Revision:
29:fcc6a8b31944
Parent:
27:faf0cd600205
Fixed : suoerscript and subscript

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takehiro 27:faf0cd600205 1 /* Sample program
takehiro 27:faf0cd600205 2 * AS-289R2 Thermal Printer Shield
takehiro 27:faf0cd600205 3 * NADA ELECTRONICS, LTD.
takehiro 27:faf0cd600205 4 * Copyright (c) 2017 Takehiro Yamaguchi, MIT License
MACRUM 24:d961f2e3f167 5 *
takehiro 27:faf0cd600205 6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
takehiro 27:faf0cd600205 7 * and associated documentation files (the "Software"), to deal in the Software without restriction,
takehiro 27:faf0cd600205 8 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
takehiro 27:faf0cd600205 9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
MACRUM 24:d961f2e3f167 10 * furnished to do so, subject to the following conditions:
MACRUM 24:d961f2e3f167 11 *
takehiro 27:faf0cd600205 12 * The above copyright notice and this permission notice shall be included in all copies or
takehiro 27:faf0cd600205 13 * substantial portions of the Software.
MACRUM 24:d961f2e3f167 14 *
takehiro 27:faf0cd600205 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
takehiro 27:faf0cd600205 16 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
takehiro 27:faf0cd600205 17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
takehiro 27:faf0cd600205 18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
takehiro 27:faf0cd600205 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MACRUM 24:d961f2e3f167 20 */
MACRUM 24:d961f2e3f167 21
Jonathan Austin 0:2757d7abb7d9 22 #include "mbed.h"
MACRUM 24:d961f2e3f167 23 #include "AS289R2.h"
takehiro 27:faf0cd600205 24 #include "image.h" // MonochromeBitmap to cpp : http://www.nada.co.jp/as289r2/en/ex_bitmap.html
Jonathan Austin 0:2757d7abb7d9 25
MACRUM 24:d961f2e3f167 26 AS289R2 tp(D1);
takehiro 27:faf0cd600205 27 DigitalOut led1(LED1);
MACRUM 25:9fe4286c3515 28
MACRUM 24:d961f2e3f167 29 void AS289R2_demo()
MACRUM 24:d961f2e3f167 30 {
takehiro 27:faf0cd600205 31 /* initialize */
MACRUM 24:d961f2e3f167 32 tp.initialize();
takehiro 27:faf0cd600205 33
takehiro 27:faf0cd600205 34 tp.putLineFeed(2);
takehiro 27:faf0cd600205 35
takehiro 27:faf0cd600205 36 /* Print Text Message */
takehiro 27:faf0cd600205 37 tp.printf("Thermal Printer Shield\r");
takehiro 27:faf0cd600205 38 tp.printf("Model:AS-289R2\r");
takehiro 27:faf0cd600205 39
takehiro 27:faf0cd600205 40 tp.putLineFeed(2);
takehiro 27:faf0cd600205 41
takehiro 27:faf0cd600205 42 /* Change ANK Font size */
takehiro 27:faf0cd600205 43 tp.setANKFont(AS289R2::ANK_8x16);
takehiro 27:faf0cd600205 44 tp.printf("Font8x16\rABCDEF012345アイウエオ\r\r");
takehiro 27:faf0cd600205 45 tp.setANKFont(AS289R2::ANK_16x16);
takehiro 27:faf0cd600205 46 tp.printf("Font16x16\rABCDEF012345アイウエオ\r\r");
takehiro 27:faf0cd600205 47 tp.setANKFont(AS289R2::ANK_12x24);
takehiro 27:faf0cd600205 48 tp.printf("Font12x24\rABCDEF012345アイウエオ\r\r");
takehiro 27:faf0cd600205 49 tp.setANKFont(AS289R2::ANK_24x24);
takehiro 27:faf0cd600205 50 tp.printf("Font24x24\rABCDEF012345アイウエオ\r\r");
takehiro 27:faf0cd600205 51
MACRUM 24:d961f2e3f167 52 tp.putLineFeed(2);
MACRUM 25:9fe4286c3515 53
takehiro 27:faf0cd600205 54 /* Change font width and height */
takehiro 27:faf0cd600205 55 tp.setANKFont(AS289R2::ANK_12x24);
takehiro 27:faf0cd600205 56 tp.printf("AS-289R2\r");
MACRUM 24:d961f2e3f167 57 tp.setDoubleSizeWidth();
takehiro 27:faf0cd600205 58 tp.printf("AS-289R2\r");
MACRUM 24:d961f2e3f167 59 tp.clearDoubleSizeWidth();
takehiro 27:faf0cd600205 60 tp.setDoubleSizeHeight();
takehiro 27:faf0cd600205 61 tp.printf("AS-289R2\r");
takehiro 27:faf0cd600205 62 tp.clearDoubleSizeHeight();
takehiro 27:faf0cd600205 63 tp.setQuadrupleSize();
takehiro 27:faf0cd600205 64 tp.printf("AS-289R2\r");
takehiro 27:faf0cd600205 65 tp.clearQuadrupleSize();
takehiro 27:faf0cd600205 66 tp.setEnlargement(3, 3);
takehiro 27:faf0cd600205 67 tp.printf("AS-289R2\r");
takehiro 27:faf0cd600205 68 tp.clearEnlargement();
MACRUM 25:9fe4286c3515 69
takehiro 27:faf0cd600205 70 tp.putLineFeed(2);
takehiro 27:faf0cd600205 71
takehiro 27:faf0cd600205 72 /* Print KANJI HIRAGANA KATAKANA */
MACRUM 24:d961f2e3f167 73 tp.setANKFont(AS289R2::ANK_8x16);
takehiro 27:faf0cd600205 74 tp.setKanjiFont(AS289R2::KANJI_16x16);
takehiro 27:faf0cd600205 75 tp.printf("Japanese\r");
takehiro 27:faf0cd600205 76 tp.printf("16x16: 漢字ひらがなカタカナ\r");
takehiro 27:faf0cd600205 77 tp.setANKFont(AS289R2::ANK_12x24);
takehiro 27:faf0cd600205 78 tp.setKanjiFont(AS289R2::KANJI_24x24);
takehiro 27:faf0cd600205 79 tp.printf("24x24: 漢字ひらがなカタカナ\r");
takehiro 27:faf0cd600205 80
takehiro 27:faf0cd600205 81 tp.putLineFeed(2);
MACRUM 25:9fe4286c3515 82
takehiro 27:faf0cd600205 83 /* Barcode */
takehiro 27:faf0cd600205 84 tp.printf("Barcode UPC-A\r");
takehiro 27:faf0cd600205 85 tp.printBarCode(AS289R2::BCODE_UPC_A, "12345678901");
takehiro 27:faf0cd600205 86 tp.printf("Barcode JAN13\r");
takehiro 27:faf0cd600205 87 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012");
takehiro 27:faf0cd600205 88 tp.printf("Barcode JAN8\r");
takehiro 27:faf0cd600205 89 tp.printBarCode(AS289R2::BCODE_JAN8, "1234567");
takehiro 27:faf0cd600205 90 tp.printf("Barcode CODE39\r");
takehiro 27:faf0cd600205 91 tp.printBarCode(AS289R2::BCODE_CODE39, "123456");
takehiro 27:faf0cd600205 92 tp.printf("Barcode ITF\r");
takehiro 27:faf0cd600205 93 tp.printBarCode(AS289R2::BCODE_ITF, "01234567890123");
takehiro 27:faf0cd600205 94 tp.printf("Barcode CODABAR(NW7)\r");
takehiro 27:faf0cd600205 95 tp.printBarCode(AS289R2::BCODE_CODABAR, "A0123456789A");
MACRUM 25:9fe4286c3515 96
MACRUM 24:d961f2e3f167 97 tp.putLineFeed(2);
MACRUM 25:9fe4286c3515 98
takehiro 27:faf0cd600205 99 /* Barcode height */
takehiro 27:faf0cd600205 100 tp.printf("Barcode height\r");
takehiro 27:faf0cd600205 101 tp.setBarCodeHeight(10);
takehiro 27:faf0cd600205 102 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012");
takehiro 27:faf0cd600205 103 tp.setBarCodeHeight(20);
takehiro 27:faf0cd600205 104 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012");
takehiro 27:faf0cd600205 105 tp.setBarCodeHeight(30);
takehiro 27:faf0cd600205 106 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012");
takehiro 27:faf0cd600205 107 tp.defaultBarCodeHeight();
takehiro 27:faf0cd600205 108 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012");
MACRUM 25:9fe4286c3515 109
MACRUM 24:d961f2e3f167 110 tp.putLineFeed(2);
MACRUM 25:9fe4286c3515 111
takehiro 27:faf0cd600205 112 /* Barcode-bar size */
takehiro 27:faf0cd600205 113 tp.printf("Barcode bar size\r");
MACRUM 25:9fe4286c3515 114 tp.setBarCodeBarSize(3,5);
MACRUM 25:9fe4286c3515 115 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012");
MACRUM 25:9fe4286c3515 116 tp.defaultBarCodeBarSize();
MACRUM 25:9fe4286c3515 117 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012");
takehiro 27:faf0cd600205 118
takehiro 27:faf0cd600205 119 tp.putLineFeed(2);
takehiro 27:faf0cd600205 120
takehiro 27:faf0cd600205 121 /* QR code */
takehiro 27:faf0cd600205 122 char url[] = "https://developer.mbed.org/components/AS-289R2-Thermal-Printer-Shield/";
takehiro 27:faf0cd600205 123 tp.printQRCode(AS289R2::QR_ERR_LVL_M, url);
takehiro 27:faf0cd600205 124 tp.printf("\r");
takehiro 27:faf0cd600205 125 //tp.printf(url);
takehiro 27:faf0cd600205 126
takehiro 27:faf0cd600205 127 tp.putLineFeed(2);
takehiro 27:faf0cd600205 128
takehiro 27:faf0cd600205 129 /* Image : The city of Kobe Japan */
takehiro 27:faf0cd600205 130 int lines = sample_image_len / 48;
takehiro 27:faf0cd600205 131 tp.printBitmapImage(0x63, lines, sample_image);
takehiro 27:faf0cd600205 132
takehiro 27:faf0cd600205 133 tp.putLineFeed(2);
takehiro 27:faf0cd600205 134
takehiro 27:faf0cd600205 135 /* Print Direction */
takehiro 27:faf0cd600205 136 tp.setPrintDirection(1); // Prints from the bottom
takehiro 27:faf0cd600205 137 tp.printf("test\r");
takehiro 27:faf0cd600205 138 tp.setPrintDirection(0); // Prints from the top
takehiro 27:faf0cd600205 139 tp.printf("test\r");
takehiro 27:faf0cd600205 140
takehiro 27:faf0cd600205 141 tp.putLineFeed(2);
takehiro 27:faf0cd600205 142
takehiro 27:faf0cd600205 143 /* Inter-Character Spacing */
takehiro 27:faf0cd600205 144 tp.setInterCharacterSpace(0);
takehiro 27:faf0cd600205 145 tp.printf("test\r");
takehiro 27:faf0cd600205 146 tp.setInterCharacterSpace(3);
takehiro 27:faf0cd600205 147 tp.printf("test\r");
takehiro 27:faf0cd600205 148 tp.setInterCharacterSpace(6);
takehiro 27:faf0cd600205 149 tp.printf("test\r");
takehiro 27:faf0cd600205 150 tp.setInterCharacterSpace(9);
takehiro 27:faf0cd600205 151 tp.printf("test\r");
takehiro 27:faf0cd600205 152 tp.defaultInterCharacterSpace();
takehiro 27:faf0cd600205 153
takehiro 27:faf0cd600205 154 tp.putLineFeed(2);
takehiro 27:faf0cd600205 155
takehiro 27:faf0cd600205 156 /* Line and Character Spacing */
takehiro 27:faf0cd600205 157 tp.setLineSpaceing(0);
takehiro 27:faf0cd600205 158 tp.printf("test\r");
takehiro 27:faf0cd600205 159 tp.setLineSpaceing(5);
takehiro 27:faf0cd600205 160 tp.printf("test\r");
takehiro 27:faf0cd600205 161 tp.setLineSpaceing(10);
takehiro 27:faf0cd600205 162 tp.printf("test\r");
takehiro 27:faf0cd600205 163 tp.setLineSpaceing(15);
takehiro 27:faf0cd600205 164 tp.printf("test\r");
takehiro 27:faf0cd600205 165 tp.defaultLineSpaceing();
takehiro 27:faf0cd600205 166
takehiro 27:faf0cd600205 167 tp.putLineFeed(2);
takehiro 27:faf0cd600205 168
takehiro 27:faf0cd600205 169 /* Print Position */
takehiro 27:faf0cd600205 170 tp.putPrintPosition(10);
takehiro 27:faf0cd600205 171 tp.printf("test\r");
takehiro 27:faf0cd600205 172 tp.putPrintPosition(15);
takehiro 27:faf0cd600205 173 tp.printf("test\r");
takehiro 27:faf0cd600205 174 tp.putPrintPosition(20);
takehiro 27:faf0cd600205 175 tp.printf("test\r");
takehiro 27:faf0cd600205 176
takehiro 27:faf0cd600205 177 tp.putLineFeed(2);
takehiro 27:faf0cd600205 178
takehiro 27:faf0cd600205 179 /* Superscript */
takehiro 27:faf0cd600205 180 tp.printf("1cm");
takehiro 29:fcc6a8b31944 181 tp.setScript(AS289R2::SCRIPT_SUPER);
takehiro 27:faf0cd600205 182 tp.printf("3");
takehiro 27:faf0cd600205 183 tp.printf("\r");
takehiro 29:fcc6a8b31944 184 tp.setScript(AS289R2::SCRIPT_CANCEL);
takehiro 27:faf0cd600205 185
takehiro 27:faf0cd600205 186 /* Subscript */
takehiro 27:faf0cd600205 187 tp.printf("H");
takehiro 29:fcc6a8b31944 188 tp.setScript(AS289R2::SCRIPT_SUB);
takehiro 27:faf0cd600205 189 tp.printf("2");
takehiro 29:fcc6a8b31944 190 tp.setScript(AS289R2::SCRIPT_CANCEL);
takehiro 27:faf0cd600205 191 tp.printf("O\r");
takehiro 27:faf0cd600205 192
takehiro 27:faf0cd600205 193 /* PaperFeed */
takehiro 27:faf0cd600205 194 tp.putPaperFeed(200);
MACRUM 24:d961f2e3f167 195 }
MACRUM 24:d961f2e3f167 196
MACRUM 25:9fe4286c3515 197 int main()
MACRUM 25:9fe4286c3515 198 {
MACRUM 24:d961f2e3f167 199 AS289R2_demo();
Jonathan Austin 0:2757d7abb7d9 200 while (true) {
Jonathan Austin 0:2757d7abb7d9 201 led1 = !led1;
mbed_official 22:af9dcf379926 202 wait(0.5);
Jonathan Austin 0:2757d7abb7d9 203 }
Jonathan Austin 0:2757d7abb7d9 204 }