/*
libptouch - functions to help accessing a brother ptouch
-
- Copyright (C) 2013 Dominic Radermacher <dominic.radermacher@gmail.com>
-
+
+ Copyright (C) 2013-2017 Dominic Radermacher <blip@mockmoon-cybernetics.ch>
+
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation
-
+
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#define _POSIX_C_SOURCE 199309L /* needed for nanosleep() when using -std=c11 */
+
#include <stdio.h>
#include <stdlib.h> /* malloc() */
#include <string.h> /* memcmp() */
#define _(s) gettext(s)
-struct _pt_tape_info tape_info[5]= {
- {9, 52}, /* 9mm tape is 52px wide? works for me ;-) */
- {12,76}, /* and 76px work for me on a 12mm tape - maybe its only 64px */
- {18,120},
- {24,128},
- {0,0} /* terminating entry */
+/* Print area width in 180 DPI pixels */
+struct _pt_tape_info tape_info[]= {
+ { 6, 32}, /* 6 mm tape */
+ { 9, 52}, /* 9 mm tape */
+ {12, 76}, /* 12 mm tape */
+ {18, 120}, /* 18 mm tape */
+ {24, 128}, /* 24 mm tape */
+ {36, 192}, /* 36 mm tape */
+ { 0, 0} /* terminating entry */
};
struct _pt_dev_info ptdevs[] = {
- {0x04f9, 0x202d, "PT-2430PC", 128, 0}, /* 180dpi, maximum 128px */
- {0x04f9, 0x202c, "PT-1230PC", 76, 0}, /* 180dpi, supports tapes up to 12mm - I don't know how much pixels it can print! */
+ {0x04f9, 0x202d, "PT-2430PC", 128, FLAG_NONE}, /* 180dpi, maximum 128px */
+ {0x04f9, 0x2007, "PT-2420PC", 128, FLAG_FORCE_TIFF}, /* 180dpi, 128px, maximum tape width 24mm, must send TIFF compressed pixel data */
+ {0x04f9, 0x202c, "PT-1230PC", 76, FLAG_NONE}, /* 180dpi, supports tapes up to 12mm - I don't know how much pixels it can print! */
+ {0x04f9, 0x2061, "PT-P700", 120, FLAG_UNSUP_RASTER}, /* DOES NOT WORK */
+ {0x04f9, 0x2073, "PT-D450VP", 120, FLAG_UNSUP_RASTER}, /* DOES NOT WORK */
+ /* Notes about the PT-D450VP: Tape detecting works, but printing does
+ not. The tape is just blank. I assume, the printer does not understand
+ the sent rasterdata. I'm also unsure about how many dots width we have */
+ {0x04f9, 0x2041, "PT-2730PC", 128, FLAG_NONE}, /* 180dpi, maximum 128px, max tape width 24mm - reported to work with some quirks */
+ /* Notes about the PT-2730PC: was reported to need 48px whitespace
+ within png-images before content is actually printed - can not check this */
{0,0,"",0,0}
};
struct libusb_device_descriptor desc;
ssize_t cnt;
int r,i=0;
-
+
if ((*ptdev=malloc(sizeof(struct _ptouch_dev))) == NULL) {
fprintf(stderr, _("out of memory\n"));
return -1;
}
+ if (((*ptdev)->devinfo=malloc(sizeof(struct _pt_dev_info))) == NULL) {
+ fprintf(stderr, _("out of memory\n"));
+ return -1;
+ }
if ((libusb_init(NULL)) < 0) {
fprintf(stderr, _("libusb_init() failed\n"));
return -1;
return -1;
}
(*ptdev)->h=handle;
+ (*ptdev)->devinfo->max_px=ptdevs[k].max_px;
+ (*ptdev)->devinfo->flags=ptdevs[k].flags;
return 0;
}
}
int ptouch_send(ptouch_dev ptdev, uint8_t *data, int len)
{
int r,tx;
-
+
if (ptdev == NULL) {
return -1;
}
int ptouch_rasterstart(ptouch_dev ptdev)
{
- char cmd[]="\x1b\x69\x52\x01"; /* 1B 69 52 01 = RASTER DATA */
+ char cmd[] = "\x1b\x69\x52\x01"; /* 1B 69 52 01 = Select graphics transfer mode = Raster */
return ptouch_send(ptdev, (uint8_t *)cmd, strlen(cmd));
}
int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, int len)
{
- uint8_t buf[32];
+ uint8_t buf[70];
+ int rc;
+
+ if (len > ptdev->devinfo->max_px / 8) {
+ return -1;
+ }
- if (len > 16) { /* PT-2430PC can not print more than 128 px */
- return -1; /* as we support more devices, we need to check */
- } /* how much pixels each device support */
buf[0]=0x47;
- buf[1]=len;
- buf[2]=0;
- memcpy(buf+3, data, len);
- return ptouch_send(ptdev, buf, len+3);
+ if (ptdev->devinfo->flags & FLAG_FORCE_TIFF) {
+ /* Fake compression by encoding a single uncompressed run */
+ buf[1] = len + 1;
+ buf[2] = 0;
+ buf[3] = len - 1;
+ memcpy(buf + 4, data, len);
+ rc = ptouch_send(ptdev, buf, len + 4);
+ } else {
+ buf[1] = len;
+ buf[2] = 0;
+ memcpy(buf + 3, data, len);
+ rc = ptouch_send(ptdev, buf, len + 3);
+ }
+ return rc;
}