1.1 --- a/src/ptouch.h Mon Aug 03 16:14:35 2009 +0100 1.2 +++ b/src/ptouch.h Mon Aug 03 17:23:54 2009 +0100 1.3 @@ -11,17 +11,102 @@ 1.4 #ifndef PTOUCH_H 1.5 #define PTOUCH_H 1.6 1.7 +#include <gd.h> 1.8 + 1.9 +/** 1.10 + * @brief Device information structure 1.11 + * 1.12 + * This is used to store the state of the printer as of the last call to 1.13 + * pt_GetStatus(), the current job settings, and other details required 1.14 + * by the printer driver. 1.15 + */ 1.16 typedef struct { 1.17 + /// Reference to the printer device 1.18 FILE *fp; 1.19 - int headMark, size, errorInfo[2]; 1.20 + /// Error information 1.21 + int errorInfo[2]; 1.22 + /// Label width, type and length 1.23 int mediaWidth, mediaType, mediaLength; 1.24 + /// Label width in pixels 1.25 + int pixelWidth; 1.26 + /// Status type, phase type, and phase number 1.27 int statusType, phaseType, phaseHi, phaseLo; 1.28 + /// Notification number 1.29 int notification; 1.30 + 1.31 + /// Print parameter: autocutter enable 1.32 + int autocut; 1.33 + /// Print parameter: mirror printing enable 1.34 + int mirror; 1.35 + /// Print parameter: half-cut enable 1.36 + /// Print parameter: chainprint enable 1.37 + /// Print parameter: label end cut 1.38 } pt_Device; 1.39 1.40 -// printer functions 1.41 +/* 1.42 + * Function return codes 1.43 + */ 1.44 +enum { 1.45 +/// Operation completed successfully 1.46 + PT_ERR_SUCCESS = 0, 1.47 + 1.48 +/// Data transfer timed out 1.49 + PT_ERR_TIMEOUT = -1, 1.50 + 1.51 +/// Invalid parameter 1.52 + PT_ERR_BAD_PARAMETER = -2, 1.53 + 1.54 +/// Label image is too large for this label tape 1.55 + PT_ERR_LABEL_TOO_WIDE = -3, 1.56 + 1.57 +/// Printer is not ready 1.58 + PT_ERR_PRINTER_NOT_READY = -4 1.59 +}; 1.60 + 1.61 + 1.62 +/** 1.63 + * @brief Initialise the printer 1.64 + * 1.65 + * Initialises the printer and returns a pointer to a pt_Device struct 1.66 + * describing it. 1.67 + * 1.68 + * @param path Path to the printer device file (e.g. /dev/usb/lp0) 1.69 + * @return On success, a pt_Device struct referring to the printer. 1.70 + * On failure, NULL. 1.71 + */ 1.72 pt_Device *pt_Initialise(char *path); 1.73 -int pt_GetStatus(pt_Device *dev); 1.74 + 1.75 +/** 1.76 + * @brief Close a printer device 1.77 + * 1.78 + * Closes the connection to the printer, and destroys the pt_Device struct. 1.79 + * 1.80 + * @param dev A pt_Device struct created by pt_Initialise. 1.81 + */ 1.82 void pt_Close(pt_Device *dev); 1.83 1.84 +/** 1.85 + * @brief Get the current status of the printer 1.86 + * 1.87 + * Queries the printer for its current status, then returns the result. 1.88 + * 1.89 + * @param dev A pt_Device struct created by pt_Initialise. 1.90 + * @return Any valid PT_ERR_* constant. The pt_Device struct passed in 1.91 + * is also updated with the current status of the printer. 1.92 + */ 1.93 +int pt_GetStatus(pt_Device *dev); 1.94 + 1.95 +/** 1.96 + * @brief Print one or more labels 1.97 + * 1.98 + * Takes a pointer to an array of Libgd images, and prints each of them. 1.99 + * 1.100 + * @param dev A pt_Device struct created by pt_Initialise. 1.101 + * @param labels A pointer to an array of gdImagePtr objects containing 1.102 + * the labels to be printed. 1.103 + * @param count The number of labels to be printed. 1.104 + * @return Any valid PT_ERR_* constant. 1.105 + */ 1.106 +int pt_Print(pt_Device *dev, gdImagePtr *labels, int count); 1.107 + 1.108 #endif // PTOUCH_H