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
AS289R2.h
- Committer:
- MACRUM
- Date:
- 2016-09-19
- Revision:
- 3:f3dfeb7ccb22
- Parent:
- 2:ce25d0949cbd
- Child:
- 4:a2e0373a9cd1
File content as of revision 3:f3dfeb7ccb22:
/* AS289R2 Library, for a Thermal Printer Shield AS-289R2 * Copyright (c) 2016, Toyomasa Watarai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #ifndef MBED_AS289R2_H #define MBED_AS289R2_H #include "mbed.h" #if defined(__CC_ARM) // To avoid "invalid multibyte character sequence" warning #pragma diag_suppress 870 #endif /** A thermal printer interface for driving AS-289R2 thermal printer shield * * @code * #include "mbed.h" * #include "AS829R2.h" * * AS829R2 tp(D1); // tx, 9600bps * * int main() { * tp.printf("Hello World!\r"); * } * @endcode */ class AS289R2 : public Stream { public: enum Kanji_font_size { KANJI_24x24 = 0x30, KANJI_16x16, KANJI_DEFAULT = KANJI_24x24 }; enum ANK_font_size { ANK_8x16 = 0x30, ANK_12x24, ANK_16x16, ANK_24x24, ANK_DEFAULT = ANK_12x24 }; enum QRcode_error_level { QR_ERR_LVL_L = 0x4C, QR_ERR_LVL_M = 0x4D, QR_ERR_LVL_Q = 0x51, QR_ERR_LVL_H = 0x48 }; enum Barcode_mode { BCODE_UPC_A = 0x30, _UNUSED_, BCODE_JAN13, BCODE_JAN8, BCODE_CODE39, BCODE_ITF, BCODE_CODABAR }; /** Create a AS289R2 instance * which is connected to specified Serial pin with specified baud rate * * @param tx Serial TX pin * @param baud (option) serial baud rate (default: 9600bps) */ AS289R2(PinName tx, uint32_t baud = 9600); /** Create a AS289R2 instance * which is connected to specified Serial instance with specified baud rate * * @param serial_obj Serial object (instance) * @param baud (option) serial baud rate (default: 9600bps) */ AS289R2(Serial &serial_obj, uint32_t baud = 9600); /** Destructor of AS289R2 */ virtual ~AS289R2(); /** Initializa AS289R2 * * Issues initialize command for AS-289R2 * */ void initialize(void); /** Send line feed code * which is connected to specified Serial pin with specified baud rate * * @param lines Number of line feed */ void putLineFeed(uint32_t lines); /** Clear image buffer of the AS-289R2 * */ void clearBuffer(void); /** Set double height size font * */ void setDoubleSizeHeight(void); /** Set normal height size font * */ void clearDoubleSizeHeight(void); /** Set double width size font * */ void setDoubleSizeWidth(void); /** Set normal width size font * */ void clearDoubleSizeWidth(void); /** Set large size font (48x96) * */ void setLargeFont(void); /** Set normal size font * */ void clearLargeFont(void); /** Set ANK font * * @param font ANK font e.g. AS289R2::ANK_8x16 */ void setANKFont(uint32_t font); /** Set Kanji font size * * @param font Kanji font e.g. AS289R2::KANJI_16x16 */ void setKanjiFont(uint32_t font); /** Print QR code * * @param err QR code error correction level e.g. AS289R2::QR_ERR_LVL_M * @param buf Data to be printed */ void printQRCode(uint32_t err, const char* buf); /** Print Bar code * * @param code Type of Bar code e.g. AS289R2::JAN13 * @param buf Data to be printed */ void printBarCode(uint32_t code, const char* param); /** Print bitmap image * * @param cmd Type of operation mode e.g. 0x61 * @param lines Number of print line * @param image Data to be printed */ void printBitmapImage(uint32_t cmd, uint16_t lines, const char * image); private: Serial *_serial_p; Serial &_serial; protected: // Stream implementation functions virtual int _putc(int value); virtual int _getc(); }; #endif