AS-289R2 library test code for mbed OS 5
Fork of mbed-os-example-mbed5-blinky by
main.cpp
00001 /* AS289R2 library test program for mbed OS 00002 * Copyright (c) 2016-2020, Toyomasa Watarai 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 * THE SOFTWARE. 00021 */ 00022 00023 #include "mbed.h" 00024 #include "AS289R2.h" 00025 00026 DigitalOut led1(LED1); 00027 AS289R2 tp(AS289R2_TX, AS289R2_RX); 00028 00029 const char url[] = "https://os.mbed.com/components/AS-289R2-Thermal-Printer-Shield/"; 00030 00031 void AS289R2_demo() 00032 { 00033 tp.initialize(); 00034 tp.putLineFeed(2); 00035 00036 tp.printf("** Thermal Printer Shield v1.0 **\r\r"); 00037 00038 tp.setDoubleSizeWidth(); 00039 tp.printf(" AS-289R2\r\r"); 00040 tp.clearDoubleSizeWidth(); 00041 00042 tp.printf("日本語文字列の印字テスト:24x24\r"); 00043 tp.setKanjiFont(AS289R2::KANJI_16x16); 00044 tp.setANKFont(AS289R2::ANK_8x16); 00045 tp.printf("日本語文字列の印字テスト:16x16\r\r"); 00046 00047 tp.setKanjiFont(AS289R2::KANJI_DEFAULT); 00048 tp.setANKFont(AS289R2::ANK_DEFAULT); 00049 tp.setDoubleSizeWidth(); 00050 tp.printf("ABCDEFG 0123456789\r"); 00051 tp.clearDoubleSizeWidth(); 00052 00053 tp.setDoubleSizeHeight(); 00054 tp.printf("ABCDEFG 0123456789\r"); 00055 tp.clearDoubleSizeHeight(); 00056 00057 tp.putLineFeed(2); 00058 00059 tp.setANKFont(AS289R2::ANK_8x16); 00060 tp.printf("8x16: Test 012345 アイウエオ\r\r"); 00061 tp.setANKFont(AS289R2::ANK_12x24); 00062 tp.printf("12x24: Test 012345 アイウエオ\r\r"); 00063 tp.setANKFont(AS289R2::ANK_16x16); 00064 tp.printf("16x16: Test 012345 アイウエオ\r\r"); 00065 tp.setANKFont(AS289R2::ANK_24x24); 00066 tp.printf("24x24: Test 012345 アイウエオ\r\r"); 00067 tp.putLineFeed(1); 00068 00069 tp.setANKFont(AS289R2::ANK_8x16); 00070 tp.printf("QR\r"); 00071 tp.printQRCode(AS289R2::QR_ERR_LVL_M, url); 00072 tp.printf("\r%s\r", url); 00073 tp.putLineFeed(2); 00074 00075 tp.printf("UPC-A\r"); 00076 tp.printBarCode(AS289R2::BCODE_UPC_A, "01234567890"); 00077 tp.putLineFeed(4); 00078 00079 #if 0 00080 // LineSpaceing 00081 tp.printf("ABCDE\r"); 00082 tp.printf("ABCDE\r"); 00083 tp.printf("ABCDE\r"); 00084 tp.setLineSpaceing(20); 00085 tp.printf("ABCDE\r"); 00086 tp.printf("ABCDE\r"); 00087 tp.printf("ABCDE\r"); 00088 tp.defaultLineSpaceing(); 00089 tp.printf("ABCDE\r"); 00090 tp.printf("ABCDE\r"); 00091 tp.printf("ABCDE\r"); 00092 tp.putLineFeed(4); 00093 00094 // PrintDirection 00095 tp.setPrintDirection(1); 00096 tp.printf("ABCDE\r"); 00097 tp.printf("ABCDE\r"); 00098 tp.printf("ABCDE\r"); 00099 tp.setPrintDirection(0); 00100 tp.printf("ABCDE\r"); 00101 tp.printf("ABCDE\r"); 00102 tp.printf("ABCDE\r"); 00103 00104 // PaperFeed 00105 tp.putPaperFeed(200); 00106 00107 // InterCharacterSpace 00108 tp.printf("ABCDE\r"); 00109 tp.printf("ABCDE\r"); 00110 tp.printf("ABCDE\r"); 00111 tp.setInterCharacterSpace(8); 00112 tp.printf("ABCDE\r"); 00113 tp.printf("ABCDE\r"); 00114 tp.printf("ABCDE\r"); 00115 tp.defaultInterCharacterSpace(); 00116 tp.printf("ABCDE\r"); 00117 tp.printf("ABCDE\r"); 00118 tp.printf("ABCDE\r"); 00119 tp.putLineFeed(4); 00120 00121 // PrintPosition 00122 tp.printf("ABCDE\r"); 00123 tp.putPrintPosition(5); 00124 tp.printf("ABCDE\r"); 00125 tp.putPrintPosition(15); 00126 tp.printf("ABCDE\r"); 00127 tp.putPrintPosition(25); 00128 tp.printf("ABCDE\r"); 00129 tp.printf("ABCDE\r"); 00130 tp.putLineFeed(4); 00131 00132 // Script 00133 tp.printf("123cm"); 00134 tp.setScript((AS289R2::script_mode)1); 00135 tp.printf("2"); 00136 tp.clearScript(); 00137 tp.printf("\r"); 00138 tp.printf("123cm"); 00139 tp.setScript((AS289R2::script_mode)2); 00140 tp.printf("5"); 00141 tp.clearScript(); 00142 tp.printf("\r"); 00143 tp.putLineFeed(4); 00144 00145 // QuadrupleSize 00146 tp.setQuadrupleSize(); 00147 tp.printf("ABCDE\r"); 00148 tp.clearQuadrupleSize(); 00149 tp.printf("ABCDE\r"); 00150 00151 // Enlargement 00152 tp.setEnlargement(1, 4); 00153 tp.printf("ABCDE\r"); 00154 tp.setEnlargement(2, 4); 00155 tp.printf("ABCDE\r"); 00156 tp.setEnlargement(3, 4); 00157 tp.printf("ABCDE\r"); 00158 tp.setEnlargement(4, 4); 00159 tp.printf("ABCDE\r"); 00160 tp.clearEnlargement(); 00161 tp.printf("ABCDE\r"); 00162 00163 // BarCodeHeight 00164 tp.setBarCodeHeight(10); 00165 tp.printf("JAN13\r"); 00166 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012"); 00167 tp.setBarCodeHeight(20); 00168 tp.printf("JAN13\r"); 00169 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012"); 00170 tp.defaultBarCodeHeight(); 00171 tp.printf("JAN13\r"); 00172 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012"); 00173 tp.putLineFeed(4); 00174 00175 // BarCodeBarSize 00176 tp.setBarCodeBarSize(3,5); 00177 tp.printf("JAN13\r"); 00178 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012"); 00179 tp.defaultBarCodeBarSize(); 00180 tp.printBarCode(AS289R2::BCODE_JAN13, "123456789012"); 00181 tp.putLineFeed(4); 00182 #endif 00183 } 00184 00185 00186 int main() 00187 { 00188 AS289R2_demo(); 00189 while (true) { 00190 led1 = !led1; 00191 thread_sleep_for(500); 00192 } 00193 }
Generated on Tue Jul 19 2022 16:06:46 by 1.7.2