src/main.c

changeset 3
4aec27d9d4da
parent 0
0eef8cf74b80
child 8
a2989aa17d21
     1.1 diff -r 81b0d2551776 -r 4aec27d9d4da src/main.c
     1.2 --- a/src/main.c	Sat Aug 01 12:41:12 2009 +0100
     1.3 +++ b/src/main.c	Sat Aug 01 12:42:34 2009 +0100
     1.4 @@ -1,12 +1,49 @@
     1.5 +/**************************
     1.6 + * P-Touch PT-2450DX printer driver
     1.7 + *
     1.8 + * P. Pemberton, 2009
     1.9 + *
    1.10 + * Specs:
    1.11 + *   Printer head is 128 dots, 180dpi, for a total print area of ~18mm vertical
    1.12 + *   by however long your TZ label tape is.
    1.13 + *   Printhead size is (128/180)=0.711[.] inches, or 18.0622[.] mm
    1.14 + *   Each dot is (18.062/128) = 0.1411[.] mm
    1.15 + *   Printable area is (numdots * 0.1411) mm
    1.16 + *
    1.17 + *     Tape width   Margins      Printable area
    1.18 + *     mm    dots   mm     dots  mm    dots
    1.19 + *      6mm   42    1.0mm     7   4mm   28
    1.20 + *      9mm   63    1.0mm     7   7mm   49
    1.21 + *     12mm   85    2.0mm    14   8mm   57
    1.22 + *     18mm  127    3.0mm    21  12mm   85
    1.23 + *     24mm  170    3.0mm   128  18mm  128 ***
    1.24 + *
    1.25 + *   24mm is slightly odd. Because the printhead is only 128 dots (18mm), the
    1.26 + *   margins are enforced by this, and not the driver software. It is impossible
    1.27 + *   to print right to the edge of a 24mm label in a PT-2450DX.
    1.28 + *
    1.29 + **************************/
    1.30 +
    1.31  #include <stdio.h>
    1.32  #include <stdlib.h>
    1.33 -#include "hexdump.h"
    1.34 +#include "ptouch.h"
    1.35 +#include "pt_image.h"
    1.36  
    1.37 -#define ESC 0x1b
    1.38 +/****************************************************************************/
    1.39  
    1.40  int main(int argc, char **argv)
    1.41  {
    1.42 -	FILE *prn;
    1.43 +	pt_Device *dev;
    1.44 +
    1.45 +	pt_Image *im;
    1.46 +
    1.47 +	printf("create image\n");
    1.48 +	im = ptimage_Create(123, 456);
    1.49 +
    1.50 +	printf("delete image\n");
    1.51 +	ptimage_Free(im);
    1.52 +
    1.53 +	return 0;
    1.54  
    1.55  	// check command line args
    1.56  	if (argc < 2) {
    1.57 @@ -14,34 +51,16 @@
    1.58  		return -1;
    1.59  	}
    1.60  
    1.61 -	// open printer device
    1.62 -	if ((prn = fopen(argv[1], "r+b")) == NULL) {
    1.63 -		printf("ERROR: couldn't open printer device '%s'\n", argv[1]);
    1.64 +	// Open and initialise the printer
    1.65 +	dev = pt_Initialise(argv[1]);
    1.66 +
    1.67 +	if (dev == NULL) {
    1.68 +		printf("Error opening printer device.\n");
    1.69  		return -1;
    1.70  	}
    1.71  
    1.72 -	// INITIALISE
    1.73 -	fprintf(prn, "%c%c", ESC, '@');
    1.74 -
    1.75 -	// REQUEST STATUS
    1.76 -	fprintf(prn, "%c%c%c", ESC, 'i', 'S');
    1.77 +	// Close the printer device
    1.78 +	pt_Close(dev);
    1.79  
    1.80 -	// Read status buffer from printer
    1.81 -	unsigned char buf[32];
    1.82 -	int timeout = 128;
    1.83 -	do {
    1.84 -		fread(buf, 1, 32, prn);
    1.85 -	} while ((buf[0] != 0x80) && (timeout-- > 0));
    1.86 -
    1.87 -	if (timeout > 0) {
    1.88 -		printf("Printer status:\n");
    1.89 -		hex_dump(buf, 32);
    1.90 -	} else {
    1.91 -		printf("TIMEOUT\n");
    1.92 -		return -1;
    1.93 -	}
    1.94 -
    1.95 -	// Close the printer stream
    1.96 -	fclose(prn);
    1.97  	return 0;
    1.98  }