hacky modifications to support KL-P350W printer

This commit is contained in:
Sebastien Bourdeauducq 2021-01-13 15:36:23 +08:00
parent 2411abc3f4
commit efc8e52655
1 changed files with 8 additions and 43 deletions

51
klg2.c
View File

@ -27,7 +27,7 @@
/* USB constants */ /* USB constants */
const uint16_t KLG2_VID = 0x07CF; const uint16_t KLG2_VID = 0x07CF;
const uint16_t KLG2_PID = 0x4112; const uint16_t KLG2_PID = 0x4204;
const uint8_t KLG2_IFACE = 0; const uint8_t KLG2_IFACE = 0;
const uint8_t KLG2_EPOUT = 0x01; const uint8_t KLG2_EPOUT = 0x01;
const uint8_t KLG2_EPIN = 0x82; const uint8_t KLG2_EPIN = 0x82;
@ -95,7 +95,7 @@ enum OPERMODE_T {
libusb_device_handle *devhnd; libusb_device_handle *devhnd;
/* Image buffer */ /* Image buffer */
#define IMAGE_ROWS 128 #define IMAGE_ROWS 32
unsigned image_w; unsigned image_w;
uint8_t *image_stripes[IMAGE_ROWS]; uint8_t *image_stripes[IMAGE_ROWS];
@ -191,7 +191,7 @@ int printer_check_status(void)
return 1; return 1;
} }
if (rsp[0] != PRINTER_STX || rsp[1] != 0x80 || rsp[2] != 0x02 || if (rsp[0] != PRINTER_STX || rsp[1] != 0x80 || rsp[2] != 0x02 ||
rsp[3] != 0x00 || rsp[4] != 0x00 || rsp[5] != 0xa6) { rsp[3] != 0x00 || rsp[4] != 0x00 || rsp[5] != 0xc8) {
fputs("Status response mismatch\n", stderr); fputs("Status response mismatch\n", stderr);
return 1; return 1;
} }
@ -274,45 +274,13 @@ int printer_cancel_job(void)
return 0; return 0;
} }
/*======================================================================
Pre-print config (no idea of what it does)
*/
int printer_prejob(void)
{
static const uint8_t cfg1[] = {
PRINTER_STX, 0x02, 0x04, 0x00, 0x00, 0x09, 0x09, 0x01
};
send_to_printer(cfg1, 8, EPSIZE_16);
if (printer_recv_ack("Prejob failed\n")) {
return 1;
}
static const uint8_t cfg2[] = {
PRINTER_STX, 0x82
};
send_to_printer(cfg2, 2, EPSIZE_16);
uint8_t rsp[KLG2_EPSIZE];
int rc = recv_from_printer(rsp);
if (rc != 5) {
fprintf(stderr, "Unexpected response length (%d)\n", rc);
return 1;
}
if (rsp[0] != PRINTER_STX || rsp[1] != 0x80 || rsp[2] != 0x01 ||
rsp[3] != 0x00 || rsp[4] != 0x01) {
fputs("Response mismatch\n", stderr);
return 1;
}
return 0;
}
/*====================================================================== /*======================================================================
Printer Speed Adjust Printer Speed Adjust
*/ */
int printer_set_speed(void) int printer_set_speed(void)
{ {
static const uint8_t psa[] = { static const uint8_t psa[] = {
PRINTER_STX, 0x1C, 0x01, 0x00, 0x00 PRINTER_STX, 0x1C, 0x01, 0x00, 0x01
}; };
send_to_printer(psa, 5, EPSIZE_16); send_to_printer(psa, 5, EPSIZE_16);
return printer_recv_ack("Speed adjust failed\n"); return printer_recv_ack("Speed adjust failed\n");
@ -340,7 +308,7 @@ int printer_check_tape(enum TAPECODE_T tapeid)
int printer_set_margin(enum MARGINCODE_T marginid) int printer_set_margin(enum MARGINCODE_T marginid)
{ {
static uint8_t afs[] = { static uint8_t afs[] = {
PRINTER_STX, 0x0d, 0x01, 0x00, 0x00 PRINTER_STX, 0x0d, 0x01, 0x00, 0x40
}; };
afs[4] = marginid; afs[4] = marginid;
send_to_printer(afs, 5, EPSIZE_16); send_to_printer(afs, 5, EPSIZE_16);
@ -353,11 +321,10 @@ int printer_set_margin(enum MARGINCODE_T marginid)
int printer_set_density(enum DENSITYCODE_T densityid) int printer_set_density(enum DENSITYCODE_T densityid)
{ {
static uint8_t dms[] = { static uint8_t dms[] = {
PRINTER_STX, 0x09, 0x06, 0x00, PRINTER_STX, 0x09, 0x07, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x01, 0x00, 0x00, 0x00
}; };
dms[8] = densityid; dms[8] = densityid; // ?
send_to_printer(dms, 10, EPSIZE_16); send_to_printer(dms, 11, EPSIZE_16);
return printer_recv_ack("Print density select failed\n"); return printer_recv_ack("Print density select failed\n");
} }
@ -718,8 +685,6 @@ int main(int argc, char **argv)
if (rc) if (rc)
return 1; return 1;
if (!need_cancel)
need_cancel = printer_prejob();
if (!need_cancel) if (!need_cancel)
need_cancel = printer_check_tape(opt_tape); need_cancel = printer_check_tape(opt_tape);
if (!need_cancel) if (!need_cancel)