AS-289R2 Thermal Printer shield control library

Dependents:   AS-289R2_Hello-World AS-289R2_Hello-World-mbed-OS hybrid_image_as289r2 microbit_AS-289R2 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AS289R2.h Source File

AS289R2.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    AS289R2.h
00004  * @author  Toyomasa Watarai
00005  * @version V1.1.0
00006  * @date    20 January 2020
00007  * @brief   This file contains the class of a AS289R2 thermal control component
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * Permission is hereby granted, free of charge, to any person obtaining a copy
00012  * of this software and associated documentation files (the "Software"), to deal
00013  * in the Software without restriction, including without limitation the rights
00014  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00015  * copies of the Software, and to permit persons to whom the Software is
00016  * furnished to do so, subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be included in
00019  * all copies or substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00022  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00024  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00026  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00027  * THE SOFTWARE.
00028  */
00029 
00030 #ifndef MBED_AS289R2_H
00031 #define MBED_AS289R2_H
00032 
00033 #include "mbed.h"
00034 
00035 #if defined(__CC_ARM)
00036 // To avoid "invalid multibyte character sequence" warning
00037 #pragma diag_suppress 870
00038 #endif
00039 
00040 /**  A printer interface for driving AS-289R2 thermal printer shield of NADA Electronics, Ltd.
00041  *
00042  * @code
00043  * #include "mbed.h"
00044  * #include "AS829R2.h"
00045  *
00046  * Serial pc(USBTX, USBRX);
00047  * AS829R2 tp(D1, D0); // tx, rx, 9600bps (default)
00048  *
00049  * int main()
00050  * {
00051  *     tp.initialize();
00052  *     tp.putLineFeed(2);
00053  *
00054  *     tp.printf("** Thermal Printer Shield **\r\r");
00055  *
00056  *     tp.setDoubleSizeWidth();
00057  *     tp.printf("  AS-289R2\r\r");
00058  *     tp.clearDoubleSizeWidth();
00059  *
00060  *     tp.printf("日本語文字列の印字テスト:24x24\r");
00061  *     tp.setKanjiFont(AS289R2::KANJI_16x16);
00062  *     tp.setANKFont(AS289R2::ANK_8x16);
00063  *     tp.printf("日本語文字列の印字テスト:16x16\r\r");
00064  *
00065  *     tp.setKanjiFont(AS289R2::KANJI_DEFAULT);
00066  *     tp.setANKFont(AS289R2::ANK_DEFAULT);
00067  *     tp.setDoubleSizeWidth();
00068  *     tp.printf("ABCDEFG 0123456789\r");
00069  *     tp.clearDoubleSizeWidth();
00070  *
00071  *     tp.setDoubleSizeHeight();
00072  *     tp.printf("ABCDEFG 0123456789\r");
00073  *     tp.clearDoubleSizeHeight();
00074  *
00075  *     pc.printf("AS-289R2 thermal printer shield test\n\n");
00076  *     while(1) {
00077  *         if (pc.readable()) {
00078  *             int c = pc.getc();
00079  *             pc.putc(c);
00080  *             tp.putc(c);
00081  *         }
00082  *     }
00083  * }
00084  * 
00085  * @endcode
00086  */
00087 class AS289R2 : public Stream
00088 {
00089 public:
00090 
00091     /**
00092      * @enum Kanji_font_size
00093      * Value of Japanese Kanji font size
00094      */
00095     enum Kanji_font_size {
00096         //! 24x24 dot font
00097         KANJI_24x24 = 0x30,
00098         //! 16x16 dot font
00099         KANJI_16x16,
00100         //! Defalut font size
00101         KANJI_DEFAULT = KANJI_24x24
00102     };
00103 
00104     /**
00105      * @enum ANK_font_size
00106      * Value of ANK font size
00107      */
00108     enum ANK_font_size {
00109         //! 8x16 dot font
00110         ANK_8x16 = 0x30,
00111         //! 12x24 dot font
00112         ANK_12x24,
00113         //! 16x16 dot font
00114         ANK_16x16,
00115         //! 24x24 dot fot
00116         ANK_24x24,
00117         //! Defalut font size
00118         ANK_DEFAULT = ANK_12x24
00119     };
00120 
00121     /**
00122      * @enum QRcode_error_level
00123      * Value of CQ code error correction level
00124      */
00125     enum QRcode_error_level {
00126         //! Error correction level L (7%)
00127         QR_ERR_LVL_L = 0x4C,
00128         //! Error correction level M (15%)
00129         QR_ERR_LVL_M = 0x4D,
00130         //! Error correction level Q (25%)
00131         QR_ERR_LVL_Q = 0x51,
00132         //! Error correction level H (30%)
00133         QR_ERR_LVL_H = 0x48
00134     };
00135 
00136     /**
00137      * @enum barcode_mode
00138      * Value of barcode mode
00139      */
00140     enum barcode_mode {
00141         //!  UPC-A : 11-digit, d1-d11, C/D
00142         BCODE_UPC_A = 0x30,
00143         //! JAN13 : 12-digit, d1-d12, C/D
00144         BCODE_JAN13 = 0x32,
00145         //! JAN8 : 7-digit, d1-d7, C/D
00146         BCODE_JAN8,
00147         //! CODE39 : variable, d1-d20, C/D
00148         BCODE_CODE39,
00149         //! ITF : variable, d1-d20
00150         BCODE_ITF,
00151         //! CODABAR (NW7) : variable, d1-d20
00152         BCODE_CODABAR
00153     };
00154     
00155     /**
00156      * @enum script_mode
00157      * Value of script mode
00158      */
00159     enum script_mode {
00160         //! Cancel script mode
00161         SCRIPT_CANCEL = 0,
00162         //! Super script
00163         SCRIPT_SUPER,
00164         //! Sub script
00165         SCRIPT_SUB
00166     };
00167 
00168     /** Create a AS289R2 instance
00169      *  which is connected to specified Serial pin with specified baud rate
00170      *
00171      * @param tx Serial TX pin
00172      * @param rx Serial RX pin (dummy)
00173      * @param baud (option) serial baud rate (default: 9600bps)
00174      */
00175     AS289R2(PinName tx, PinName rx, uint32_t baud = 9600);
00176 
00177     /** Create a AS289R2 instance
00178      *  which is connected to specified Serial instance with specified baud rate
00179      *
00180      * @param serial_obj Serial object (instance)
00181      * @param baud (option) serial baud rate (default: 9600bps)
00182      */
00183     AS289R2(RawSerial &serial_obj, uint32_t baud = 9600);
00184 
00185     /** Destructor of AS289R2
00186      */
00187     virtual ~AS289R2();
00188 
00189     /** Initializa AS289R2
00190      *
00191      *  Issues initialize command for AS-289R2
00192      *
00193      */
00194     void initialize(void);
00195 
00196     /** Send line feed code
00197      *  which is connected to specified Serial pin with specified baud rate
00198      *
00199      * @param lines Number of line feed
00200      */
00201     void putLineFeed(uint32_t lines);
00202 
00203     /** Clear image buffer of the AS-289R2
00204      *
00205      */
00206     void clearBuffer(void);
00207 
00208     /** Set double height size font
00209      *
00210      */
00211     void setDoubleSizeHeight(void);
00212 
00213     /** Set normal height size font
00214      *
00215      */
00216     void clearDoubleSizeHeight(void);
00217 
00218     /** Set double width size font
00219      *
00220      */
00221     void setDoubleSizeWidth(void);
00222 
00223     /** Set normal width size font
00224      *
00225      */
00226     void clearDoubleSizeWidth(void);
00227 
00228     /** Set large size font (48x96)
00229      *
00230      */
00231     void setLargeFont(void);
00232 
00233     /** Set normal size font
00234      *
00235      */
00236     void clearLargeFont(void);
00237 
00238     /** Set ANK font
00239      *
00240      * @param font ANK font e.g. AS289R2::ANK_8x16
00241      */
00242     void setANKFont(uint32_t font);
00243 
00244     /** Set Kanji font size
00245      *
00246      * @param font Kanji font e.g. AS289R2::KANJI_16x16
00247      */
00248     void setKanjiFont(uint32_t font);
00249 
00250     /** Print QR code
00251      *
00252      * @param err QR code error correction level e.g. AS289R2::QR_ERR_LVL_M
00253      * @param buf Data to be printed
00254      */
00255     void printQRCode(uint32_t err, const char* buf);
00256 
00257     /** Print Bar code
00258      *
00259      * @param code Type of Bar code e.g. AS289R2::JAN13
00260      * @param buf Data to be printed
00261      */
00262     void printBarCode(uint32_t code, const char* param);
00263 
00264     /** Print bitmap image
00265      *
00266      * @param cmd Type of operation mode, 0x61: print image buffer, 0x62: register image buffer, 0x63: register -> print, 0x64: print -> register, 0x65: line print
00267      * @param lines Number of print line
00268      * @param image Data to be printed
00269      */
00270     void printBitmapImage(uint32_t cmd, uint16_t lines, const uint8_t * image);
00271 
00272     /** Set Line Spaceing
00273      *
00274      * @param space line spacing
00275      */
00276     void setLineSpaceing(uint32_t space);
00277 
00278     /** Set as default Line Spaceing
00279      *
00280      */
00281     void defaultLineSpaceing(void);
00282 
00283     /** Set Print Direction
00284      *
00285      * @param direction Print direction, 0: lister, 1: texter
00286      */
00287     void setPrintDirection(uint32_t direction);
00288 
00289     /** Send feed code
00290      *
00291      * @param space Paper feed
00292      */
00293     void putPaperFeed(uint32_t space);
00294 
00295     /** Set Inter Character Space
00296      *
00297      * @param space inter-character space
00298      */
00299     void setInterCharacterSpace(uint32_t space);
00300 
00301     /** Set as default Inter Character Space
00302      *
00303      */
00304     void defaultInterCharacterSpace(void);
00305 
00306     /** Send Print Position
00307      *
00308      * @param position Print position
00309      */
00310     void putPrintPosition(uint32_t position);
00311 
00312     /** Set Script
00313      *
00314      * @param script mode e.g. AS289R2::SCRIPT_SUPER
00315      */
00316     void setScript(script_mode script);
00317 
00318     /** Clear Script
00319      *
00320      */
00321     void clearScript(void);
00322 
00323     /** Set Quadruple size
00324      *
00325      */
00326     void setQuadrupleSize(void);
00327 
00328     /** Clear Quadruple size
00329      *
00330      */
00331     void clearQuadrupleSize(void);
00332 
00333     /** Set Enlargement size
00334      *
00335      * @param width enlargement
00336      * @param height enlargement
00337      */
00338     void setEnlargement(uint32_t width, uint32_t height);
00339 
00340     /** Clear Enlargement size
00341      *
00342      */
00343     void clearEnlargement(void);
00344 
00345     /** Set BarCode Height size
00346      *
00347      * @param height Bar height
00348      */
00349     void setBarCodeHeight(uint32_t height);
00350 
00351     /** Set as default BarCode Height size
00352      *
00353      */
00354     void defaultBarCodeHeight(void);
00355 
00356     /** Set BarCode Bar size
00357      *
00358      * @param narrowbar narrow bars size
00359      * @param widebar wide bars size
00360      */
00361     void setBarCodeBarSize(uint32_t narrowbar, uint32_t widebar);
00362 
00363     /** Set as default BarCode Bar size
00364      *
00365      */
00366     void defaultBarCodeBarSize(void);
00367 
00368 private:
00369     RawSerial *_serial_p;
00370     RawSerial &_serial;
00371 
00372 protected:
00373     // Stream implementation functions
00374     virtual int _putc(int value);
00375     virtual int _getc();
00376 };
00377 
00378 #endif