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