Wed, 05 Aug 2009 15:04:55 +0100
Fixed printing so uncompressed mode is no longer used; now sends an uncompressed Packbits stream instead.
Added SetOption and GetOption, so can now turn autocut and mirror on and off. Defaults to both off after init.
1 /****************************************************************************
2 * Project: P-touch printer driver library
3 * Developer: Philip Pemberton
4 * Purpose: Make Brother P-touch (PT-series) printers do something besides
5 * gather dust.
6 *
7 * Currently supports:
8 * PT-2450DX
9 ****************************************************************************/
11 #ifndef PTOUCH_H
12 #define PTOUCH_H
14 #include <gd.h>
16 /**
17 * @brief Device information structure
18 *
19 * This is used to store the state of the printer as of the last call to
20 * pt_GetStatus(), the current job settings, and other details required
21 * by the printer driver.
22 */
23 typedef struct {
24 /// Reference to the printer device
25 FILE *fp;
26 /// Error information
27 int errorInfo[2];
28 /// Label width, type and length
29 int mediaWidth, mediaType, mediaLength;
30 /// Label width in pixels
31 int pixelWidth;
32 /// Status type, phase type, and phase number
33 int statusType, phaseType, phaseHi, phaseLo;
34 /// Notification number
35 int notification;
37 /// Print parameter: autocutter enable
38 int autocut;
39 /// Print parameter: mirror printing enable
40 int mirror;
41 /// Print parameter: half-cut enable
42 /// Print parameter: chainprint enable
43 /// Print parameter: label end cut
44 } pt_Device;
46 /*
47 * Function return codes
48 */
49 enum {
50 /// Operation completed successfully
51 PT_ERR_SUCCESS = 0,
53 /// Data transfer timed out
54 PT_ERR_TIMEOUT = -1,
56 /// Invalid parameter
57 PT_ERR_BAD_PARAMETER = -2,
59 /// Label image is too large for this label tape
60 PT_ERR_LABEL_TOO_WIDE = -3,
62 /// Label has a length of zero
63 PT_ERR_LABEL_ZERO_LENGTH = -4,
65 /// Printer is not ready
66 PT_ERR_PRINTER_NOT_READY = -5
67 };
69 /*
70 * Job options
71 */
72 typedef enum {
73 /// Mirror -- mirror the printed label along the long edge
74 PT_OPTION_MIRROR,
75 /// Auto-cutter -- enable or disable automatic label cutting
76 PT_OPTION_AUTOCUT
77 } PT_E_OPTION;
79 /**
80 * @brief Initialise the printer.
81 *
82 * Initialises the printer and returns a pointer to a pt_Device struct
83 * describing it.
84 *
85 * @param path Path to the printer device file (e.g. /dev/usb/lp0)
86 * @return On success, a pt_Device struct referring to the printer.
87 * On failure, NULL.
88 */
89 pt_Device *pt_Initialise(char *path);
91 /**
92 * @brief Close a printer device.
93 *
94 * Closes the connection to the printer, and destroys the pt_Device struct.
95 *
96 * @param dev A pt_Device struct created by pt_Initialise.
97 */
98 void pt_Close(pt_Device *dev);
100 /**
101 * @brief Get the current status of the printer.
102 *
103 * Queries the printer for its current status, then returns the result.
104 *
105 * @param dev A pt_Device struct created by pt_Initialise.
106 * @return Any valid PT_ERR_* constant. The pt_Device struct passed in
107 * is also updated with the current status of the printer.
108 */
109 int pt_GetStatus(pt_Device *dev);
111 /**
112 * @brief Set a job option for the next print job.
113 *
114 * Sets a job option (specified by <b>option</b>) for the next print job.
115 * These options include printer features like auto-cutting and mirroring
116 * of the label image.
117 *
118 * @param dev A pt_Device struct created by pt_Initialise.
119 * @param option One of the PT_OPTION_* constants specifying the parameter
120 * that is to be set.
121 * @param value The value to assign to the job option.
122 * @return <b>PT_ERR_BAD_PARAMETER:</b> Either <b>dev</b> was equal to NULL,
123 * or the option value specified in <b>option</b> was invalid.<br>
124 * <b>PT_ERR_SUCCESS:</b> Operation completed successfully, the current value
125 * of the option parameter is now set to the contents of <b>value</b>.
126 */
127 int pt_SetOption(pt_Device *dev, PT_E_OPTION option, int value);
129 /**
130 * @brief Get the current value of a job option for the next print job.
131 *
132 * Returns the current value of a job option (specified by <b>option</b>)
133 * for the next print job.
134 * These options include printer features like auto-cutting and mirroring
135 * of the label image.
136 *
137 * @param dev A pt_Device struct created by pt_Initialise.
138 * @param option One of the PT_OPTION_* constants specifying the parameter
139 * that is to be returned.
140 * @param value A pointer to an <b>int</b> that will contain the value
141 * of the job option.
142 * @return <b>PT_ERR_BAD_PARAMETER:</b> Either <b>dev</b> or <b>value</b> was
143 * equal to NULL, or the option value specified in <b>option</b> was invalid.<br>
144 * <b>PT_ERR_SUCCESS:</b> Operation completed successfully, the current value
145 * of the option parameter is now stored in <b>value</b>.
146 */
147 int pt_GetOption(pt_Device *dev, PT_E_OPTION option, int *value);
149 /**
150 * @brief Print one or more labels.
151 *
152 * Takes a pointer to an array of Libgd images, and prints each of them.
153 *
154 * @param dev A pt_Device struct created by pt_Initialise.
155 * @param labels A pointer to an array of gdImagePtr objects containing
156 * the labels to be printed.
157 * @param count The number of labels to be printed.
158 * @return Any valid PT_ERR_* constant.
159 */
160 int pt_Print(pt_Device *dev, gdImagePtr *labels, int count);
162 #endif // PTOUCH_H