src/ptouch.h

Wed, 05 Aug 2009 17:32:05 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 05 Aug 2009 17:32:05 +0100
changeset 18
fd1c6f6066da
parent 16
57eff547e4f1
child 19
b7fe751ea60d
permissions
-rw-r--r--

updated README

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