AS-289R2 library test code for mbed 2 (classic)

Dependencies:   AS289R2 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* AS289R2 library test program
00002  * Copyright (c) 2016, 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 #include "mbed.h"
00023 #include "AS289R2.h"
00024 
00025 Serial pc(USBTX, USBRX);
00026 AS289R2 tp(D1);
00027 
00028 const char url[] = "https://developer.mbed.org/components/AS-289R2-Thermal-Printer-Shield/";
00029 
00030 int main()
00031 {
00032     tp.initialize();
00033     tp.putLineFeed(2);
00034 
00035     tp.printf("** Thermal Printer Shield **\r\r");
00036 
00037     tp.setDoubleSizeWidth();
00038     tp.printf("  AS-289R2\r\r");
00039     tp.clearDoubleSizeWidth();
00040 
00041     tp.printf("日本語文字列の印字テスト:24x24\r");
00042     tp.setKanjiFont(AS289R2::KANJI_16x16);
00043     tp.setANKFont(AS289R2::ANK_8x16);
00044     tp.printf("日本語文字列の印字テスト:16x16\r\r");
00045 
00046     tp.setKanjiFont(AS289R2::KANJI_DEFAULT);
00047     tp.setANKFont(AS289R2::ANK_DEFAULT);
00048     tp.setDoubleSizeWidth();
00049     tp.printf("ABCDEFG 0123456789\r");
00050     tp.clearDoubleSizeWidth();
00051 
00052     tp.setDoubleSizeHeight();
00053     tp.printf("ABCDEFG 0123456789\r");
00054     tp.clearDoubleSizeHeight();
00055 
00056     tp.putLineFeed(2);
00057 
00058     tp.setANKFont(AS289R2::ANK_8x16);
00059     tp.printf("8x16: Test 012345 アイウエオ\r\r");
00060     tp.setANKFont(AS289R2::ANK_12x24);
00061     tp.printf("12x24: Test 012345 アイウエオ\r\r");
00062     tp.setANKFont(AS289R2::ANK_16x16);
00063     tp.printf("16x16: Test 012345 アイウエオ\r\r");
00064     tp.setANKFont(AS289R2::ANK_24x24);
00065     tp.printf("24x24: Test 012345 アイウエオ\r\r");
00066     tp.putLineFeed(1);
00067 
00068     tp.setANKFont(AS289R2::ANK_8x16);
00069     tp.printf("QR\r");
00070     tp.printQRCode(AS289R2::QR_ERR_LVL_M, url);
00071     tp.printf("\r%s\r", url);
00072     tp.putLineFeed(2);
00073 
00074     tp.printf("UPC-A\r");
00075     tp.printBarCode(AS289R2::BCODE_UPC_A, "01234567890");
00076     tp.putLineFeed(4);
00077 
00078     pc.printf("AS-289R2 thermal printer shield test\n\n");
00079     while(1) {
00080         if (pc.readable()) {
00081             int c = pc.getc();
00082             pc.putc(c);
00083             tp.putc(c);
00084         }
00085     }
00086 
00087 }