Tue, 18 Mar 2014 01:27:15 +0000
Update PTdecode to handle output from other Ptouch drivers
philpem@3 | 1 | /**************************************************************************** |
philpem@3 | 2 | * Project: P-touch printer driver library |
philpem@3 | 3 | * Developer: Philip Pemberton |
philpem@3 | 4 | * Purpose: Make Brother P-touch (PT-series) printers do something besides |
philpem@3 | 5 | * gather dust. |
philpem@3 | 6 | * |
philpem@3 | 7 | * Currently supports: |
philpem@3 | 8 | * PT-2450DX |
philpem@3 | 9 | ****************************************************************************/ |
philpem@3 | 10 | |
philpem@3 | 11 | #ifndef PTOUCH_H |
philpem@3 | 12 | #define PTOUCH_H |
philpem@3 | 13 | |
philpem@9 | 14 | #include <gd.h> |
philpem@9 | 15 | |
philpem@9 | 16 | /** |
philpem@9 | 17 | * @brief Device information structure |
philpem@9 | 18 | * |
philpem@9 | 19 | * This is used to store the state of the printer as of the last call to |
philpem@9 | 20 | * pt_GetStatus(), the current job settings, and other details required |
philpem@16 | 21 | * by the printer driver. User code should not change any parameters inside |
philpem@16 | 22 | * a pt_Device struct under any circumstances. For further information on |
philpem@16 | 23 | * the various fields, see the Brother PT-9500PC Command Reference. |
philpem@9 | 24 | */ |
philpem@3 | 25 | typedef struct { |
philpem@9 | 26 | /// Reference to the printer device |
philpem@3 | 27 | FILE *fp; |
philpem@9 | 28 | /// Error information |
philpem@9 | 29 | int errorInfo[2]; |
philpem@16 | 30 | /// Label width (in millimetres) |
philpem@16 | 31 | int mediaWidth; |
philpem@16 | 32 | /// Label type |
philpem@16 | 33 | int mediaType; |
philpem@16 | 34 | /// Label length (in millimetres) |
philpem@16 | 35 | int mediaLength; |
philpem@9 | 36 | /// Label width in pixels |
philpem@9 | 37 | int pixelWidth; |
philpem@16 | 38 | /// Printer status type |
philpem@16 | 39 | int statusType; |
philpem@16 | 40 | /// Printing phase type |
philpem@16 | 41 | int phaseType; |
philpem@16 | 42 | /// Printing phase, high byte |
philpem@16 | 43 | int phaseHi; |
philpem@16 | 44 | /// Printing phase, low byte |
philpem@16 | 45 | int phaseLo; |
philpem@9 | 46 | /// Notification number |
philpem@3 | 47 | int notification; |
philpem@9 | 48 | |
philpem@21 | 49 | /// Dots per inch -- print head |
philpem@21 | 50 | int dpiPrinthead; |
philpem@21 | 51 | /// Dots per inch -- "label length" direction |
philpem@21 | 52 | int dpiLabel; |
philpem@21 | 53 | |
philpem@9 | 54 | /// Print parameter: autocutter enable |
philpem@9 | 55 | int autocut; |
philpem@9 | 56 | /// Print parameter: mirror printing enable |
philpem@9 | 57 | int mirror; |
philpem@19 | 58 | /// Print parameter: print separator line |
philpem@19 | 59 | int separator; |
philpem@16 | 60 | // TODO: add support for half-cut (when I get a printer that supports it) |
philpem@3 | 61 | } pt_Device; |
philpem@3 | 62 | |
philpem@9 | 63 | /* |
philpem@9 | 64 | * Function return codes |
philpem@9 | 65 | */ |
philpem@9 | 66 | enum { |
philpem@9 | 67 | /// Operation completed successfully |
philpem@9 | 68 | PT_ERR_SUCCESS = 0, |
philpem@9 | 69 | |
philpem@9 | 70 | /// Data transfer timed out |
philpem@9 | 71 | PT_ERR_TIMEOUT = -1, |
philpem@9 | 72 | |
philpem@9 | 73 | /// Invalid parameter |
philpem@9 | 74 | PT_ERR_BAD_PARAMETER = -2, |
philpem@9 | 75 | |
philpem@9 | 76 | /// Label image is too large for this label tape |
philpem@9 | 77 | PT_ERR_LABEL_TOO_WIDE = -3, |
philpem@9 | 78 | |
philpem@14 | 79 | /// Label has a length of zero |
philpem@14 | 80 | PT_ERR_LABEL_ZERO_LENGTH = -4, |
philpem@14 | 81 | |
philpem@9 | 82 | /// Printer is not ready |
philpem@14 | 83 | PT_ERR_PRINTER_NOT_READY = -5 |
philpem@9 | 84 | }; |
philpem@9 | 85 | |
philpem@14 | 86 | /* |
philpem@14 | 87 | * Job options |
philpem@14 | 88 | */ |
philpem@14 | 89 | typedef enum { |
philpem@16 | 90 | /// Mirror -- mirror the printed label vertically |
philpem@14 | 91 | PT_OPTION_MIRROR, |
philpem@14 | 92 | /// Auto-cutter -- enable or disable automatic label cutting |
philpem@19 | 93 | PT_OPTION_AUTOCUT, |
philpem@19 | 94 | /// Separator -- prints tick marks between each label |
philpem@19 | 95 | PT_OPTION_SEPARATOR |
philpem@14 | 96 | } PT_E_OPTION; |
philpem@9 | 97 | |
philpem@9 | 98 | /** |
philpem@14 | 99 | * @brief Initialise the printer. |
philpem@9 | 100 | * |
philpem@9 | 101 | * Initialises the printer and returns a pointer to a pt_Device struct |
philpem@9 | 102 | * describing it. |
philpem@9 | 103 | * |
philpem@9 | 104 | * @param path Path to the printer device file (e.g. /dev/usb/lp0) |
philpem@9 | 105 | * @return On success, a pt_Device struct referring to the printer. |
philpem@9 | 106 | * On failure, NULL. |
philpem@9 | 107 | */ |
philpem@3 | 108 | pt_Device *pt_Initialise(char *path); |
philpem@9 | 109 | |
philpem@9 | 110 | /** |
philpem@14 | 111 | * @brief Close a printer device. |
philpem@9 | 112 | * |
philpem@9 | 113 | * Closes the connection to the printer, and destroys the pt_Device struct. |
philpem@9 | 114 | * |
philpem@9 | 115 | * @param dev A pt_Device struct created by pt_Initialise. |
philpem@9 | 116 | */ |
philpem@3 | 117 | void pt_Close(pt_Device *dev); |
philpem@3 | 118 | |
philpem@9 | 119 | /** |
philpem@14 | 120 | * @brief Get the current status of the printer. |
philpem@9 | 121 | * |
philpem@9 | 122 | * Queries the printer for its current status, then returns the result. |
philpem@9 | 123 | * |
philpem@9 | 124 | * @param dev A pt_Device struct created by pt_Initialise. |
philpem@9 | 125 | * @return Any valid PT_ERR_* constant. The pt_Device struct passed in |
philpem@9 | 126 | * is also updated with the current status of the printer. |
philpem@9 | 127 | */ |
philpem@9 | 128 | int pt_GetStatus(pt_Device *dev); |
philpem@9 | 129 | |
philpem@9 | 130 | /** |
philpem@14 | 131 | * @brief Set a job option for the next print job. |
philpem@14 | 132 | * |
philpem@14 | 133 | * Sets a job option (specified by <b>option</b>) for the next print job. |
philpem@14 | 134 | * These options include printer features like auto-cutting and mirroring |
philpem@14 | 135 | * of the label image. |
philpem@14 | 136 | * |
philpem@14 | 137 | * @param dev A pt_Device struct created by pt_Initialise. |
philpem@14 | 138 | * @param option One of the PT_OPTION_* constants specifying the parameter |
philpem@14 | 139 | * that is to be set. |
philpem@14 | 140 | * @param value The value to assign to the job option. |
philpem@14 | 141 | * @return <b>PT_ERR_BAD_PARAMETER:</b> Either <b>dev</b> was equal to NULL, |
philpem@14 | 142 | * or the option value specified in <b>option</b> was invalid.<br> |
philpem@14 | 143 | * <b>PT_ERR_SUCCESS:</b> Operation completed successfully, the current value |
philpem@14 | 144 | * of the option parameter is now set to the contents of <b>value</b>. |
philpem@14 | 145 | */ |
philpem@14 | 146 | int pt_SetOption(pt_Device *dev, PT_E_OPTION option, int value); |
philpem@14 | 147 | |
philpem@14 | 148 | /** |
philpem@14 | 149 | * @brief Get the current value of a job option for the next print job. |
philpem@14 | 150 | * |
philpem@14 | 151 | * Returns the current value of a job option (specified by <b>option</b>) |
philpem@14 | 152 | * for the next print job. |
philpem@14 | 153 | * These options include printer features like auto-cutting and mirroring |
philpem@14 | 154 | * of the label image. |
philpem@14 | 155 | * |
philpem@14 | 156 | * @param dev A pt_Device struct created by pt_Initialise. |
philpem@14 | 157 | * @param option One of the PT_OPTION_* constants specifying the parameter |
philpem@14 | 158 | * that is to be returned. |
philpem@14 | 159 | * @param value A pointer to an <b>int</b> that will contain the value |
philpem@14 | 160 | * of the job option. |
philpem@14 | 161 | * @return <b>PT_ERR_BAD_PARAMETER:</b> Either <b>dev</b> or <b>value</b> was |
philpem@14 | 162 | * equal to NULL, or the option value specified in <b>option</b> was invalid.<br> |
philpem@14 | 163 | * <b>PT_ERR_SUCCESS:</b> Operation completed successfully, the current value |
philpem@14 | 164 | * of the option parameter is now stored in <b>value</b>. |
philpem@14 | 165 | */ |
philpem@14 | 166 | int pt_GetOption(pt_Device *dev, PT_E_OPTION option, int *value); |
philpem@14 | 167 | |
philpem@14 | 168 | /** |
philpem@14 | 169 | * @brief Print one or more labels. |
philpem@9 | 170 | * |
philpem@9 | 171 | * Takes a pointer to an array of Libgd images, and prints each of them. |
philpem@9 | 172 | * |
philpem@9 | 173 | * @param dev A pt_Device struct created by pt_Initialise. |
philpem@9 | 174 | * @param labels A pointer to an array of gdImagePtr objects containing |
philpem@9 | 175 | * the labels to be printed. |
philpem@9 | 176 | * @param count The number of labels to be printed. |
philpem@9 | 177 | * @return Any valid PT_ERR_* constant. |
philpem@9 | 178 | */ |
philpem@9 | 179 | int pt_Print(pt_Device *dev, gdImagePtr *labels, int count); |
philpem@9 | 180 | |
philpem@3 | 181 | #endif // PTOUCH_H |