Printer

>w## Notice > * please include the header file "mmi_printer.h" first when you want to use printer module `#include "mmi_printer.h"` ### data structure ``` /** * @brief enum definition of printer status */ typedef enum { STATUS_IDLE, STATUS_CACHING, STATUS_PRINTING, STATUS_ERROR_NO_PAPER, STATUS_ERROR_OVERHEAT, STATUS_ERROR_BMARK, STATUS_ERROR_COMM, STATUS_ERROR_LOW_BATTERY, STATUS_ERROR_NO_FONT_LIB, STATUS_ERROR_NO_CACHE_MEMORY, STATUS_MAX } te_printer_status; /** * @brief enum definition of print font size */ typedef enum { PRINT_FONT_SMALL = 16, PRINT_FONT_NORMAL = 24, PRINT_FONT_LARGE = 32 } te_printer_fontsize; /** * @brief enum definition of print effect */ typedef enum { EFFECT_NONE, EFFECT_BOLD } te_printer_effect; /** * @brief enum definition of print align mode */ typedef enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT } te_printer_align; /** * @brief enum definition of print heat point * @note larger value, print faster */ typedef enum { HEAT_POINT_MIN = 32, HEAT_POINT_48 = 48, HEAT_POINT_64 = 64, HEAT_POINT_MAX = 96 ///<recommended } te_printer_heat_point; /** * @brief struct definition of printer parameter */ typedef struct { te_printer_fontsize fontSize; ///<print font size te_printer_effect fontEffect; ///<print effect int lineSpace; ///<print line spacing (>= 0) te_printer_align printAlign; ///<print align mode int printGray; ///<print gray level(heat time.Value range:1800-5000) te_printer_heat_point printHeatpoint; ///<print heat point int printStep; ///<print step delay time(Value range:600-1200) } ts_printer_para; /** * brief enum definition of barcode type */ typedef enum { BARCODE_TYPE_ANY, ///< self-adaption BARCODE_TYPE_CODE128, ///< recommended BARCODE_TYPE_CODE39, BARCODE_TYPE_CODE93, BARCODE_TYPE_CODE11, BARCODE_TYPE_MSI, BARCODE_TYPE_I25, BARCODE_TYPE_EAN8, BARCODE_TYPE_EAN13, BARCODE_TYPE_UPCA, BARCODE_TYPE_UPCE, BARCODE_TYPE_CODABAR, } ts_barcode_type; ``` >i## printer_check ### Prototype `int printer_check(void);` ### Function * check printer state ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_open ### Prototype `int printer_open(void);` ### Function * open printer ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_get_para ### Prototype `int printer_get_para(ts_printer_para *p_printer_para);` ### Function * get printer current parameter ### Parameter |Name|Type|description| |-|-|-| |p_printer_para|ts_printer_para *|printer parameter struct| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_set_para ### Prototype `int printer_set_para(ts_printer_para *p_printer_para);` ### Function * set printer parameter ### Parameter |Name|Type|description| |-|-|-| |p_printer_para|ts_printer_para *|printer parameter struct| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_clear ### Prototype `int printer_clear(void);` ### Function * clean printer cache ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_add_text_with_param ### Prototype `int printer_add_text_with_param(const ts_printer_para *p_printer_para, const char *text);` ### Function * add text data to printer cache ### Parameter |Name|Type|description| |-|-|-| |p_printer_para|const ts_printer_para *|printer parameter| |text|const char *|text data need to print| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_add_bmp_with_param ### Prototype `int printer_add_bmp_with_param(const ts_printer_para *p_printer_para, const char *bmp_data, int bmp_data_len, int need_reverse);` ### Function * add bmp data to printer cache ### Parameter |Name|Type|description| |-|-|-| |p_printer_para|const ts_printer_para *|printer parameter| |bmp_data|const char *|bmp data need to print| |bmp_data_len|int|bmp data length| |need_reverse|int|reverse flag:1-reverse,0-no| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_add_bmp_path_with_param ### Prototype `int printer_add_bmp_path_with_param(const ts_printer_para *p_printer_para, const char *bmp_path, int need_reverse);` ### Function * add bmp file to printer cache ### Parameter |Name|Type|description| |-|-|-| |p_printer_para|const ts_printer_para *|printer parameter| |bmp_path|const char *|bmp file path| |need_reverse|int|reverse flag:1-reverse,0-no| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_add_barcode_with_param ### Prototype `int printer_add_barcode_with_param(const ts_printer_para *p_printer_para, ts_barcode_type barcode_type, int code_width, int code_height, const char *barcode_text);` ### Function * add barcode data to printer cache ### Parameter |Name|Type|description| |-|-|-| |p_printer_para|const ts_printer_para *|printer parameter| |barcode_type|ts_barcode_type|BARCODE_TYPE_ANY, BARCODE_TYPE_CODE128...| |code_width|int|barcode size of width| |code_height|int|barcode size of height| |barcode_text|const char *|barcode data| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_add_qrcode_with_param ### Prototype `int printer_add_qrcode_with_param(const ts_printer_para *p_printer_para, int code_size, const char *qrcode_text);` ### Function * add qrcode data to printer cache ### Parameter |Name|Type|description| |-|-|-| |p_printer_para|const ts_printer_para *|printer parameter| |code_size|int|qrcode size| |qrcode_text|const char *|qrcode data| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_feed ### Prototype `int printer_feed(int point_lines);` ### Function * feed paper ### Parameter |Name|Type|description| |-|-|-| |point_lines|int|feed paper of printer heat points| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_print ### Prototype `int printer_print(void);` ### Function * start printer ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >i## printer_get_status ### Prototype `te_printer_status printer_get_status(void);` ### Function * get printer state ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |printer state macro|int|printer state| >i## printer_close ### Prototype `int printer_close(void);` ### Function * close printer ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |=0|int|state normal| |!0|int|state error, see the error macro| >s## Example ``` int iRet = 0; ts_printer_para printer_para; iRet = printer_check(); ///< iRet = printer_get_status(); if (PRINTER_RET_OK != iRet) { return iRet; } iRet = printer_open(); if (PRINTER_RET_OK != iRet) { return iRet; } memset(&printer_para, 0, sizeof(ts_printer_para)); iRet = printer_get_para(&printer_para); if (PRINTER_RET_OK != iRet) { return iRet; } iRet = printer_clear(); if (PRINTER_RET_OK != iRet) { return iRet; } printer_para.fontSize = PRINT_FONT_LARGE; printer_para.printAlign = ALIGN_CENTER; printer_para.lineSpace = 8; iRet = printer_add_text_with_param(&printer_para, "smartpeak!"); if (PRINTER_RET_OK != iRet) { return iRet; } iRet = printer_add_bmp_path_with_param(&printer_para, "logo.bmp", 0); if (PRINTER_RET_OK != iRet) { return iRet; } iRet = printer_add_barcode_with_param(&printer_para, BARCODE_TYPE_ANY, 300, 60, "1234567890"); if (PRINTER_RET_OK != iRet) { return iRet; } iRet = printer_add_qrcode_with_param(&printer_para, 200, "smartpeak test"); if (PRINTER_RET_OK != iRet) { return iRet; } iRet = printer_print(); if (PRINTER_RET_OK != iRet) { return iRet; } iRet = printer_feed(64); if (PRINTER_RET_OK != iRet) { return iRet; } return printer_close(); ```