src/ptouch.h

Wed, 05 Aug 2009 15:04:55 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 05 Aug 2009 15:04:55 +0100
changeset 14
088286f9e1e4
parent 9
ebce4a7615e9
child 16
57eff547e4f1
permissions
-rw-r--r--

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.

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@9 21 * by the printer driver.
philpem@9 22 */
philpem@3 23 typedef struct {
philpem@9 24 /// Reference to the printer device
philpem@3 25 FILE *fp;
philpem@9 26 /// Error information
philpem@9 27 int errorInfo[2];
philpem@9 28 /// Label width, type and length
philpem@3 29 int mediaWidth, mediaType, mediaLength;
philpem@9 30 /// Label width in pixels
philpem@9 31 int pixelWidth;
philpem@9 32 /// Status type, phase type, and phase number
philpem@3 33 int statusType, phaseType, phaseHi, phaseLo;
philpem@9 34 /// Notification number
philpem@3 35 int notification;
philpem@9 36
philpem@9 37 /// Print parameter: autocutter enable
philpem@9 38 int autocut;
philpem@9 39 /// Print parameter: mirror printing enable
philpem@9 40 int mirror;
philpem@9 41 /// Print parameter: half-cut enable
philpem@9 42 /// Print parameter: chainprint enable
philpem@9 43 /// Print parameter: label end cut
philpem@3 44 } pt_Device;
philpem@3 45
philpem@9 46 /*
philpem@9 47 * Function return codes
philpem@9 48 */
philpem@9 49 enum {
philpem@9 50 /// Operation completed successfully
philpem@9 51 PT_ERR_SUCCESS = 0,
philpem@9 52
philpem@9 53 /// Data transfer timed out
philpem@9 54 PT_ERR_TIMEOUT = -1,
philpem@9 55
philpem@9 56 /// Invalid parameter
philpem@9 57 PT_ERR_BAD_PARAMETER = -2,
philpem@9 58
philpem@9 59 /// Label image is too large for this label tape
philpem@9 60 PT_ERR_LABEL_TOO_WIDE = -3,
philpem@9 61
philpem@14 62 /// Label has a length of zero
philpem@14 63 PT_ERR_LABEL_ZERO_LENGTH = -4,
philpem@14 64
philpem@9 65 /// Printer is not ready
philpem@14 66 PT_ERR_PRINTER_NOT_READY = -5
philpem@9 67 };
philpem@9 68
philpem@14 69 /*
philpem@14 70 * Job options
philpem@14 71 */
philpem@14 72 typedef enum {
philpem@14 73 /// Mirror -- mirror the printed label along the long edge
philpem@14 74 PT_OPTION_MIRROR,
philpem@14 75 /// Auto-cutter -- enable or disable automatic label cutting
philpem@14 76 PT_OPTION_AUTOCUT
philpem@14 77 } PT_E_OPTION;
philpem@9 78
philpem@9 79 /**
philpem@14 80 * @brief Initialise the printer.
philpem@9 81 *
philpem@9 82 * Initialises the printer and returns a pointer to a pt_Device struct
philpem@9 83 * describing it.
philpem@9 84 *
philpem@9 85 * @param path Path to the printer device file (e.g. /dev/usb/lp0)
philpem@9 86 * @return On success, a pt_Device struct referring to the printer.
philpem@9 87 * On failure, NULL.
philpem@9 88 */
philpem@3 89 pt_Device *pt_Initialise(char *path);
philpem@9 90
philpem@9 91 /**
philpem@14 92 * @brief Close a printer device.
philpem@9 93 *
philpem@9 94 * Closes the connection to the printer, and destroys the pt_Device struct.
philpem@9 95 *
philpem@9 96 * @param dev A pt_Device struct created by pt_Initialise.
philpem@9 97 */
philpem@3 98 void pt_Close(pt_Device *dev);
philpem@3 99
philpem@9 100 /**
philpem@14 101 * @brief Get the current status of the printer.
philpem@9 102 *
philpem@9 103 * Queries the printer for its current status, then returns the result.
philpem@9 104 *
philpem@9 105 * @param dev A pt_Device struct created by pt_Initialise.
philpem@9 106 * @return Any valid PT_ERR_* constant. The pt_Device struct passed in
philpem@9 107 * is also updated with the current status of the printer.
philpem@9 108 */
philpem@9 109 int pt_GetStatus(pt_Device *dev);
philpem@9 110
philpem@9 111 /**
philpem@14 112 * @brief Set a job option for the next print job.
philpem@14 113 *
philpem@14 114 * Sets a job option (specified by <b>option</b>) for the next print job.
philpem@14 115 * These options include printer features like auto-cutting and mirroring
philpem@14 116 * of the label image.
philpem@14 117 *
philpem@14 118 * @param dev A pt_Device struct created by pt_Initialise.
philpem@14 119 * @param option One of the PT_OPTION_* constants specifying the parameter
philpem@14 120 * that is to be set.
philpem@14 121 * @param value The value to assign to the job option.
philpem@14 122 * @return <b>PT_ERR_BAD_PARAMETER:</b> Either <b>dev</b> was equal to NULL,
philpem@14 123 * or the option value specified in <b>option</b> was invalid.<br>
philpem@14 124 * <b>PT_ERR_SUCCESS:</b> Operation completed successfully, the current value
philpem@14 125 * of the option parameter is now set to the contents of <b>value</b>.
philpem@14 126 */
philpem@14 127 int pt_SetOption(pt_Device *dev, PT_E_OPTION option, int value);
philpem@14 128
philpem@14 129 /**
philpem@14 130 * @brief Get the current value of a job option for the next print job.
philpem@14 131 *
philpem@14 132 * Returns the current value of a job option (specified by <b>option</b>)
philpem@14 133 * for the next print job.
philpem@14 134 * These options include printer features like auto-cutting and mirroring
philpem@14 135 * of the label image.
philpem@14 136 *
philpem@14 137 * @param dev A pt_Device struct created by pt_Initialise.
philpem@14 138 * @param option One of the PT_OPTION_* constants specifying the parameter
philpem@14 139 * that is to be returned.
philpem@14 140 * @param value A pointer to an <b>int</b> that will contain the value
philpem@14 141 * of the job option.
philpem@14 142 * @return <b>PT_ERR_BAD_PARAMETER:</b> Either <b>dev</b> or <b>value</b> was
philpem@14 143 * equal to NULL, or the option value specified in <b>option</b> was invalid.<br>
philpem@14 144 * <b>PT_ERR_SUCCESS:</b> Operation completed successfully, the current value
philpem@14 145 * of the option parameter is now stored in <b>value</b>.
philpem@14 146 */
philpem@14 147 int pt_GetOption(pt_Device *dev, PT_E_OPTION option, int *value);
philpem@14 148
philpem@14 149 /**
philpem@14 150 * @brief Print one or more labels.
philpem@9 151 *
philpem@9 152 * Takes a pointer to an array of Libgd images, and prints each of them.
philpem@9 153 *
philpem@9 154 * @param dev A pt_Device struct created by pt_Initialise.
philpem@9 155 * @param labels A pointer to an array of gdImagePtr objects containing
philpem@9 156 * the labels to be printed.
philpem@9 157 * @param count The number of labels to be printed.
philpem@9 158 * @return Any valid PT_ERR_* constant.
philpem@9 159 */
philpem@9 160 int pt_Print(pt_Device *dev, gdImagePtr *labels, int count);
philpem@9 161
philpem@3 162 #endif // PTOUCH_H