src/ptouch.h

Thu, 24 Sep 2009 17:18:28 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Thu, 24 Sep 2009 17:18:28 +0100
changeset 19
b7fe751ea60d
parent 16
57eff547e4f1
child 21
629637abfe1f
permissions
-rw-r--r--

Added support for separator ticks between labels

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