src/ptouch.h

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