diff options
author | Dominic Radermacher <dominic@familie-radermacher.ch> | 2023-10-13 12:30:33 +0200 |
---|---|---|
committer | Dominic Radermacher <dominic@familie-radermacher.ch> | 2023-10-13 12:30:33 +0200 |
commit | f22e844eed773cc8e9ac876ad102d58dc972bb38 (patch) | |
tree | 4b08f113db156a28c79932810a2587d994f684a8 | |
parent | 8b631a7996c0c2e33a55dc8f645792693217f4be (diff) |
add (untested) support for PT-D460BT thanks to ccfreak2k
-rw-r--r-- | include/ptouch.h | 6 | ||||
-rw-r--r-- | src/libptouch.c | 33 | ||||
-rw-r--r-- | src/ptouch-print.c | 12 |
3 files changed, 50 insertions, 1 deletions
diff --git a/include/ptouch.h b/include/ptouch.h index d33c2b9..c38a20a 100644 --- a/include/ptouch.h +++ b/include/ptouch.h @@ -1,7 +1,7 @@ /* ptouch-print - Print labels with images or text on a Brother P-Touch - Copyright (C) 2015-2021 Dominic Radermacher <dominic@familie-radermacher.ch> + Copyright (C) 2015-2023 Dominic Radermacher <dominic@familie-radermacher.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 @@ -32,6 +32,8 @@ struct _pt_tape_info { #define FLAG_PLITE (1 << 2) #define FLAG_P700_INIT (1 << 3) #define FLAG_USE_INFO_CMD (1 << 4) +#define FLAG_HAS_PRECUT (1 << 5) +#define FLAG_D460BT_MAGIC (1 << 6) typedef enum _pt_page_flags { FEED_NONE = 0x0, @@ -102,8 +104,10 @@ int ptouch_page_flags(ptouch_dev ptdev, uint8_t page_flags); int ptouch_eject(ptouch_dev ptdev); int ptouch_getstatus(ptouch_dev ptdev); int ptouch_getmaxwidth(ptouch_dev ptdev); +int ptouch_send_d460bt_magic(ptouch_dev ptdev); int ptouch_enable_packbits(ptouch_dev ptdev); int ptouch_info_cmd(ptouch_dev ptdev, int size_x); +int ptouch_send_precut_cmd(ptouch_dev ptdev, int precut); int ptouch_rasterstart(ptouch_dev ptdev); int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len); void ptouch_rawstatus(uint8_t raw[32]); diff --git a/src/libptouch.c b/src/libptouch.c index 24d684a..6f9d73d 100644 --- a/src/libptouch.c +++ b/src/libptouch.c @@ -71,6 +71,7 @@ struct _pt_dev_info ptdevs[] = { {0x04f9, 0x2065, "PT-P750W (PLite Mode)", 128, 180, FLAG_PLITE}, {0x04f9, 0x2073, "PT-D450", 128, 180, FLAG_USE_INFO_CMD}, /* Notes about the PT-D450: I'm unsure if print width really is 128px */ + {0x04f9, 0x20e0, "PT-D460BT", 128, 180, FLAG_P700_INIT|FLAG_USE_INFO_CMD|FLAG_HAS_PRECUT|FLAG_D460BT_MAGIC}, {0x04f9, 0x2074, "PT-D600", 128, 180, FLAG_RASTER_PACKBITS}, /* PT-D600 was reported to work, but with some quirks (premature cutting of tape, printing maximum of 73mm length) */ @@ -192,6 +193,21 @@ int ptouch_init(ptouch_dev ptdev) return ptouch_send(ptdev, (uint8_t *)cmd, sizeof(cmd)); } +/* Sends some magic commands to make prints work on the PT-D460BT. + These should go out after info_cmd and right before the raster data. */ +int ptouch_send_d460bt_magic(ptouch_dev ptdev) +{ + /* 1B 69 64 {n1} {n2} {n3} {n4} */ + uint8_t cmd[7]; + /* n1 and n2 are the length margin/spacing, in px? (uint16_t value, little endian) */ + /* A value of 0x06 is equivalent to the width margin on 6mm tape */ + /* The default for P-Touch software is 0x0e */ + /* n3 must be 0x4D or the print gets corrupted! */ + /* n4 seems to be ignored or reserved. */ + memcpy(cmd, "\x1b\x69\x64\x0e\x00\x4d\x00", 7); + return ptouch_send(ptdev, (uint8_t *)cmd, sizeof(cmd)); +} + int ptouch_enable_packbits(ptouch_dev ptdev) { /* 4D 00 = disable compression */ char cmd[] = "M\x02"; /* 4D 02 = enable packbits compression mode */ @@ -216,6 +232,23 @@ int ptouch_info_cmd(ptouch_dev ptdev, int size_x) cmd[8] = (uint8_t) (size_x >> 8) & 0xff; cmd[9] = (uint8_t) (size_x >> 16) & 0xff; cmd[10] = (uint8_t) (size_x >> 24) & 0xff; + if ((ptdev->devinfo->flags & FLAG_D460BT_MAGIC) == FLAG_D460BT_MAGIC) { + /* n9 is set to 2 in order to feed the last of the label and properly stop printing. */ + cmd[11] = (uint8_t) 0x02; + } + return ptouch_send(ptdev, cmd, sizeof(cmd)-1); +} + +/* If set, printer will prompt to cut blank tape before finishing the print. + If not set, printer will print normally with a big blank space on the label. + The printer ignores this value if the print is very short. */ +/* 0x80 horizontally mirrors the print */ +int ptouch_send_precut_cmd(ptouch_dev ptdev, int precut) +{ + char cmd[] = "\x1b\x69\x4d\x00"; + if (precut) { + cmd[3] = 0x40; + } return ptouch_send(ptdev, cmd, sizeof(cmd)-1); } diff --git a/src/ptouch-print.c b/src/ptouch-print.c index 647c644..a0e0804 100644 --- a/src/ptouch-print.c +++ b/src/ptouch-print.c @@ -109,6 +109,18 @@ int print_img(ptouch_dev ptdev, gdImage *im) printf(_("send print information command\n")); } } + if ((ptdev->devinfo->flags & FLAG_D460BT_MAGIC) == FLAG_D460BT_MAGIC) { + ptouch_send_d460bt_magic(ptdev); + if (debug) { + printf(_("send PT-D460BT magic commands\n")); + } + } + if ((ptdev->devinfo->flags & FLAG_HAS_PRECUT) == FLAG_HAS_PRECUT) { + ptouch_send_precut_cmd(ptdev, 1); + if (debug) { + printf(_("send precut command\n")); + } + } for (k=0; k<gdImageSX(im); k+=1) { memset(rasterline, 0, sizeof(rasterline)); for (i=0; i<gdImageSY(im); i+=1) { |