Thu, 24 Sep 2009 17:18:28 +0100
Added support for separator ticks between labels
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 /// Print parameter: autocutter enable
50 int autocut;
51 /// Print parameter: mirror printing enable
52 int mirror;
53 /// Print parameter: print separator line
54 int separator;
55 // TODO: add support for half-cut (when I get a printer that supports it)
56 } pt_Device;
58 /*
59 * Function return codes
60 */
61 enum {
62 /// Operation completed successfully
63 PT_ERR_SUCCESS = 0,
65 /// Data transfer timed out
66 PT_ERR_TIMEOUT = -1,
68 /// Invalid parameter
69 PT_ERR_BAD_PARAMETER = -2,
71 /// Label image is too large for this label tape
72 PT_ERR_LABEL_TOO_WIDE = -3,
74 /// Label has a length of zero
75 PT_ERR_LABEL_ZERO_LENGTH = -4,
77 /// Printer is not ready
78 PT_ERR_PRINTER_NOT_READY = -5
79 };
81 /*
82 * Job options
83 */
84 typedef enum {
85 /// Mirror -- mirror the printed label vertically
86 PT_OPTION_MIRROR,
87 /// Auto-cutter -- enable or disable automatic label cutting
88 PT_OPTION_AUTOCUT,
89 /// Separator -- prints tick marks between each label
90 PT_OPTION_SEPARATOR
91 } PT_E_OPTION;
93 /**
94 * @brief Initialise the printer.
95 *
96 * Initialises the printer and returns a pointer to a pt_Device struct
97 * describing it.
98 *
99 * @param path Path to the printer device file (e.g. /dev/usb/lp0)
100 * @return On success, a pt_Device struct referring to the printer.
101 * On failure, NULL.
102 */
103 pt_Device *pt_Initialise(char *path);
105 /**
106 * @brief Close a printer device.
107 *
108 * Closes the connection to the printer, and destroys the pt_Device struct.
109 *
110 * @param dev A pt_Device struct created by pt_Initialise.
111 */
112 void pt_Close(pt_Device *dev);
114 /**
115 * @brief Get the current status of the printer.
116 *
117 * Queries the printer for its current status, then returns the result.
118 *
119 * @param dev A pt_Device struct created by pt_Initialise.
120 * @return Any valid PT_ERR_* constant. The pt_Device struct passed in
121 * is also updated with the current status of the printer.
122 */
123 int pt_GetStatus(pt_Device *dev);
125 /**
126 * @brief Set a job option for the next print job.
127 *
128 * Sets a job option (specified by <b>option</b>) for the next print job.
129 * These options include printer features like auto-cutting and mirroring
130 * of the label image.
131 *
132 * @param dev A pt_Device struct created by pt_Initialise.
133 * @param option One of the PT_OPTION_* constants specifying the parameter
134 * that is to be set.
135 * @param value The value to assign to the job option.
136 * @return <b>PT_ERR_BAD_PARAMETER:</b> Either <b>dev</b> was equal to NULL,
137 * or the option value specified in <b>option</b> was invalid.<br>
138 * <b>PT_ERR_SUCCESS:</b> Operation completed successfully, the current value
139 * of the option parameter is now set to the contents of <b>value</b>.
140 */
141 int pt_SetOption(pt_Device *dev, PT_E_OPTION option, int value);
143 /**
144 * @brief Get the current value of a job option for the next print job.
145 *
146 * Returns the current value of a job option (specified by <b>option</b>)
147 * for the next print job.
148 * These options include printer features like auto-cutting and mirroring
149 * of the label image.
150 *
151 * @param dev A pt_Device struct created by pt_Initialise.
152 * @param option One of the PT_OPTION_* constants specifying the parameter
153 * that is to be returned.
154 * @param value A pointer to an <b>int</b> that will contain the value
155 * of the job option.
156 * @return <b>PT_ERR_BAD_PARAMETER:</b> Either <b>dev</b> or <b>value</b> was
157 * equal to NULL, or the option value specified in <b>option</b> was invalid.<br>
158 * <b>PT_ERR_SUCCESS:</b> Operation completed successfully, the current value
159 * of the option parameter is now stored in <b>value</b>.
160 */
161 int pt_GetOption(pt_Device *dev, PT_E_OPTION option, int *value);
163 /**
164 * @brief Print one or more labels.
165 *
166 * Takes a pointer to an array of Libgd images, and prints each of them.
167 *
168 * @param dev A pt_Device struct created by pt_Initialise.
169 * @param labels A pointer to an array of gdImagePtr objects containing
170 * the labels to be printed.
171 * @param count The number of labels to be printed.
172 * @return Any valid PT_ERR_* constant.
173 */
174 int pt_Print(pt_Device *dev, gdImagePtr *labels, int count);
176 #endif // PTOUCH_H