diff options
Diffstat (limited to 'src/cups/shinko_s2145_print.c')
-rw-r--r-- | src/cups/shinko_s2145_print.c | 344 |
1 files changed, 99 insertions, 245 deletions
diff --git a/src/cups/shinko_s2145_print.c b/src/cups/shinko_s2145_print.c index 5196528..c6fd88f 100644 --- a/src/cups/shinko_s2145_print.c +++ b/src/cups/shinko_s2145_print.c @@ -39,8 +39,9 @@ #include <fcntl.h> #include <signal.h> -#include "backend_common.h" +#define BACKEND shinkos2145_backend +#include "backend_common.h" enum { S_IDLE = 0, @@ -53,7 +54,7 @@ enum { struct s2145_printjob_hdr { uint32_t len1; /* Fixed at 0x10 */ uint32_t model; /* Equal to the printer model (eg '2145' or '1245' decimal) */ - uint32_t med_type; /* 6145 only, media type */ + uint32_t unk2; uint32_t unk3; /* Fixed at 0x01 */ uint32_t len2; /* Fixed at 0x64 */ @@ -61,9 +62,9 @@ struct s2145_printjob_hdr { uint32_t media; uint32_t unk6; - uint32_t method; /* Method for 2145, 0x00 for 6245, multicut for 6145 */ - uint32_t mode; /* Mode for 2145, 0x00 for 6245, quality for 6145 */ - uint32_t oc_mode; /* 6145/6245 only, Matte/Glossy/None */ + uint32_t method; + uint32_t mode; + uint32_t unk7; uint32_t unk8; uint32_t unk9; @@ -94,13 +95,12 @@ struct shinkos2145_ctx { struct libusb_device_handle *dev; uint8_t endp_up; uint8_t endp_down; + int type; + uint8_t jobid; - uint8_t fast_return; struct s2145_printjob_hdr hdr; - uint32_t model; - uint8_t *databuf; int datalen; }; @@ -684,11 +684,11 @@ struct s2145_status_resp { static char *bank_statuses(uint8_t v) { switch (v) { - case 0: + case BANK_STATUS_FREE: return "Free"; - case 1: + case BANK_STATUS_XFER: return "Xfer"; - case 2: + case BANK_STATUS_FULL: return "Full"; default: return "Unknown"; @@ -723,7 +723,7 @@ struct s2145_mediainfo_item { uint16_t columns; uint16_t rows; uint8_t media_type; - uint8_t print_type; + uint8_t print_type; /* The same as the "print method" */ uint8_t reserved[3]; } __attribute__((packed)); @@ -900,7 +900,7 @@ static int get_fwinfo(struct shinkos2145_ctx *ctx) (uint8_t*)&cmd, sizeof(cmd), sizeof(*resp), &num)) < 0) { - ERROR("Failed to execute %s command\n", cmd_names(cmd.hdr.cmd)); + ERROR("Failed to execute %s command (%d)\n", cmd_names(cmd.hdr.cmd), ret); continue; } @@ -1136,7 +1136,7 @@ static int get_tonecurve(struct shinkos2145_ctx *ctx, int type, char *fname) int ret, num = 0; uint8_t *data; - uint16_t curves[768]; + uint16_t curves[UPDATE_SIZE] = { 0 } ; int i,j; @@ -1161,6 +1161,7 @@ static int get_tonecurve(struct shinkos2145_ctx *ctx, int type, char *fname) if (!data) { ERROR("Memory allocation failure! (%d bytes)\n", resp->total_size * 2); + return -1; } i = 0; @@ -1189,11 +1190,11 @@ static int get_tonecurve(struct shinkos2145_ctx *ctx, int type, char *fname) goto done; } - for (i = 0 ; i < 768; i++) { + for (i = 0 ; i < UPDATE_SIZE; i++) { /* Byteswap appropriately */ curves[i] = cpu_to_be16(le16_to_cpu(curves[i])); - write(tc_fd, &curves[i], sizeof(uint16_t)); } + write(tc_fd, curves, UPDATE_SIZE * sizeof(uint16_t)); close(tc_fd); } @@ -1210,11 +1211,12 @@ static int set_tonecurve(struct shinkos2145_ctx *ctx, int target, char *fname) INFO("Set %s Tone Curve from '%s'\n", update_targets(target), fname); - uint16_t *data = malloc(UPDATE_SIZE); + uint16_t *data = malloc(UPDATE_SIZE * sizeof(uint16_t)); if (!data) { ERROR("Memory allocation failure! (%d bytes)\n", UPDATE_SIZE); + return -1; } /* Read in file */ @@ -1223,26 +1225,26 @@ static int set_tonecurve(struct shinkos2145_ctx *ctx, int target, char *fname) ret = -1; goto done; } - if (read(tc_fd, data, UPDATE_SIZE) != UPDATE_SIZE) { + if (read(tc_fd, data, UPDATE_SIZE * sizeof(uint16_t)) != (UPDATE_SIZE * sizeof(uint16_t))) { ret = -2; goto done; } close(tc_fd); /* Byteswap data to local CPU.. */ - for (ret = 0; ret < UPDATE_SIZE ; ret+=2) { + for (ret = 0; ret < UPDATE_SIZE ; ret++) { data[ret] = be16_to_cpu(data[ret]); } /* Set up command */ cmd.target = target; cmd.reserved = 0; - cmd.size = cpu_to_le32(UPDATE_SIZE); + cmd.size = cpu_to_le32(UPDATE_SIZE * sizeof(uint16_t)); cmd.hdr.cmd = cpu_to_le16(S2145_CMD_UPDATE); cmd.hdr.len = cpu_to_le16(sizeof(struct s2145_update_cmd)-sizeof(cmd.hdr)); /* Byteswap data to format printer is expecting.. */ - for (ret = 0; ret < UPDATE_SIZE ; ret+=2) { + for (ret = 0; ret < UPDATE_SIZE ; ret++) { data[ret] = cpu_to_le16(data[ret]); } @@ -1256,7 +1258,7 @@ static int set_tonecurve(struct shinkos2145_ctx *ctx, int target, char *fname) /* Sent transfer */ if ((ret = send_data(ctx->dev, ctx->endp_down, - (uint8_t *) data, UPDATE_SIZE))) { + (uint8_t *) data, UPDATE_SIZE * sizeof(uint16_t)))) { goto done; } @@ -1274,10 +1276,10 @@ static void shinkos2145_cmdline(void) DEBUG("\t\t[ -e ] # Query error log\n"); DEBUG("\t\t[ -f ] # Use fast return mode\n"); DEBUG("\t\t[ -F ] # Flash Printer LED\n"); + DEBUG("\t\t[ -i ] # Query printer info\n"); DEBUG("\t\t[ -l filename ] # Get current tone curve\n"); DEBUG("\t\t[ -L filename ] # Set current tone curve\n"); DEBUG("\t\t[ -m ] # Query media\n"); - DEBUG("\t\t[ -i ] # Query printer info\n"); DEBUG("\t\t[ -r ] # Reset user/NV tone curve\n"); DEBUG("\t\t[ -R ] # Reset printer to factory defaults\n"); DEBUG("\t\t[ -s ] # Query status\n"); @@ -1291,112 +1293,65 @@ int shinkos2145_cmdline_arg(void *vctx, int argc, char **argv) struct shinkos2145_ctx *ctx = vctx; int i, j = 0; + if (!ctx) + return -1; + /* Reset arg parsing */ optind = 1; opterr = 0; - while ((i = getopt(argc, argv, "b:c:C:efFil:L:mr:R:suU:X:")) >= 0) { + while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "b:c:C:eFil:L:mr:R:suU:X:")) >= 0) { switch(i) { + GETOPT_PROCESS_GLOBAL case 'b': - if (ctx) { - if (optarg[0] == '1') - j = button_set(ctx, BUTTON_ENABLED); - else if (optarg[0] == '0') - j = button_set(ctx, BUTTON_DISABLED); - else - return -1; - break; - } - return 1; + if (optarg[0] == '1') + j = button_set(ctx, BUTTON_ENABLED); + else if (optarg[0] == '0') + j = button_set(ctx, BUTTON_DISABLED); + else + return -1; + break; case 'c': - if (ctx) { - j = get_tonecurve(ctx, TONECURVE_USER, optarg); - break; - } - return 1; + j = get_tonecurve(ctx, TONECURVE_USER, optarg); + break; case 'C': - if (ctx) { - j = set_tonecurve(ctx, TONECURVE_USER, optarg); - break; - } - return 1; + j = set_tonecurve(ctx, TONECURVE_USER, optarg); + break; case 'e': - if (ctx) { - j = get_errorlog(ctx); - break; - } - return 1; - case 'f': - if (ctx) { - ctx->fast_return = 1; - break; - } - return 1; + j = get_errorlog(ctx); + break; case 'F': - if (ctx) { - j = flash_led(ctx); - break; - } - return 1; + j = flash_led(ctx); + break; case 'i': - if (ctx) { - j = get_fwinfo(ctx); - break; - } - return 1; + j = get_fwinfo(ctx); + break; case 'l': - if (ctx) { - j = get_tonecurve(ctx, TONECURVE_CURRENT, optarg); - break; - } - return 1; + j = get_tonecurve(ctx, TONECURVE_CURRENT, optarg); + break; case 'L': - if (ctx) { - j = set_tonecurve(ctx, TONECURVE_CURRENT, optarg); - break; - } - return 1; + j = set_tonecurve(ctx, TONECURVE_CURRENT, optarg); + break; case 'm': - if (ctx) { - j = get_mediainfo(ctx); - break; - } - return 1; + j = get_mediainfo(ctx); + break; case 'r': - if (ctx) { - j = reset_curve(ctx, RESET_USER_CURVE); - break; - } - return 1; + j = reset_curve(ctx, RESET_USER_CURVE); + break; case 'R': - if (ctx) { - j = reset_curve(ctx, RESET_PRINTER); - break; - } - return 1; + j = reset_curve(ctx, RESET_PRINTER); + break; case 's': - if (ctx) { - j = get_status(ctx); - break; - } - return 1; + j = get_status(ctx); + break; case 'u': - if (ctx) { - j = get_user_string(ctx); - break; - } - return 1; + j = get_user_string(ctx); + break; case 'U': - if (ctx) { - j = set_user_string(ctx, optarg); - break; - } - return 1; + j = set_user_string(ctx, optarg); + break; case 'X': - if (ctx) { - j = cancel_job(ctx, optarg); - break; - } - return 1; + j = cancel_job(ctx, optarg); + break; default: break; /* Ignore completely */ } @@ -1418,10 +1373,6 @@ static void *shinkos2145_init(void) } memset(ctx, 0, sizeof(struct shinkos2145_ctx)); - /* Use Fast return by default in CUPS mode */ - if (getenv("DEVICE_URI") || getenv("FAST_RETURN")) - ctx->fast_return = 1; - return ctx; } @@ -1429,16 +1380,23 @@ static void shinkos2145_attach(void *vctx, struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, uint8_t jobid) { struct shinkos2145_ctx *ctx = vctx; + struct libusb_device *device; + struct libusb_device_descriptor desc; ctx->dev = dev; ctx->endp_up = endp_up; ctx->endp_down = endp_down; + device = libusb_get_device(dev); + libusb_get_device_descriptor(device, &desc); + + ctx->type = lookup_printer_type(&shinkos2145_backend, + desc.idVendor, desc.idProduct); + /* Ensure jobid is sane */ ctx->jobid = (jobid & 0x7f) + 1; } - static void shinkos2145_teardown(void *vctx) { struct shinkos2145_ctx *ctx = vctx; @@ -1451,18 +1409,19 @@ static void shinkos2145_teardown(void *vctx) { free(ctx); } -static int shinkos2145_early_parse(void *vctx, int data_fd) { +static int shinkos2145_read_parse(void *vctx, int data_fd) { struct shinkos2145_ctx *ctx = vctx; - int printer_type, ret; + int ret; + uint8_t tmpbuf[4]; if (!ctx) - return -1; + return CUPS_BACKEND_FAILED; /* Read in then validate header */ ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr)); if (ret < 0 || ret != sizeof(ctx->hdr)) { if (ret == 0) - return -1; /* deliberate */ + return CUPS_BACKEND_CANCEL; ERROR("Read failed (%d/%d/%d)\n", ret, 0, (int)sizeof(ctx->hdr)); perror("ERROR: Read failed"); @@ -1473,42 +1432,20 @@ static int shinkos2145_early_parse(void *vctx, int data_fd) { le32_to_cpu(ctx->hdr.len2) != 0x64 || le32_to_cpu(ctx->hdr.dpi) != 300) { ERROR("Unrecognized header data format!\n"); - return -1; + return CUPS_BACKEND_CANCEL; } - ctx->model = le32_to_cpu(ctx->hdr.model); - - switch(ctx->model) { - case 2145: - printer_type = P_SHINKO_S2145; - break; - case 6145: - case 6245: - default: + if (le32_to_cpu(ctx->hdr.model) != 2145) { ERROR("Unrecognized printer (%d)!\n", le32_to_cpu(ctx->hdr.model)); - return -1; + return CUPS_BACKEND_CANCEL; } - INFO("File intended for an S%d printer\n", ctx->model); - - return printer_type; -} - -static int shinkos2145_read_parse(void *vctx, int data_fd) { - struct shinkos2145_ctx *ctx = vctx; - int ret; - uint8_t tmpbuf[4]; - - if (!ctx) - return CUPS_BACKEND_FAILED; - if (ctx->databuf) { free(ctx->databuf); ctx->databuf = NULL; } - ctx->datalen = le32_to_cpu(ctx->hdr.rows) * le32_to_cpu(ctx->hdr.columns) * 3; ctx->databuf = malloc(ctx->datalen); if (!ctx->databuf) { @@ -1585,7 +1522,8 @@ static int shinkos2145_main_loop(void *vctx, int copies) { for (i = 0; i < media->count ; i++) { /* Look for matching media */ if (le16_to_cpu(media->items[i].columns) == cpu_to_le16(le32_to_cpu(ctx->hdr.columns)) && - le16_to_cpu(media->items[i].rows) == cpu_to_le16(le32_to_cpu(ctx->hdr.rows))) + le16_to_cpu(media->items[i].rows) == cpu_to_le16(le32_to_cpu(ctx->hdr.rows)) && + media->items[i].print_type == le32_to_cpu(ctx->hdr.method)) break; } if (i == media->count) { @@ -1593,7 +1531,9 @@ static int shinkos2145_main_loop(void *vctx, int copies) { return CUPS_BACKEND_HOLD; } - top: + // XXX check copies against remaining media! + +top: if (state != last_state) { if (dyesub_debug) DEBUG("last_state %d new %d\n", last_state, state); @@ -1645,19 +1585,13 @@ static int shinkos2145_main_loop(void *vctx, int copies) { print->hdr.cmd = cpu_to_le16(S2145_CMD_PRINTJOB); print->hdr.len = cpu_to_le16(sizeof (*print) - sizeof(*cmd)); - if (ctx->model == 2145) { - print->id = ctx->jobid; - print->count = cpu_to_le16(copies); - print->columns = cpu_to_le16(le32_to_cpu(ctx->hdr.columns)); - print->rows = cpu_to_le16(le32_to_cpu(ctx->hdr.rows)); - print->media = le32_to_cpu(ctx->hdr.media); - print->mode = le32_to_cpu(ctx->hdr.mode); - print->method = le32_to_cpu(ctx->hdr.method); - } else { - // s6145, s6245 use different fields - ERROR("Don't know how to initiate print on non-2145 models!\n"); - return CUPS_BACKEND_FAILED; - } + print->id = ctx->jobid; + print->count = cpu_to_le16(copies); + print->columns = cpu_to_le16(le32_to_cpu(ctx->hdr.columns)); + print->rows = cpu_to_le16(le32_to_cpu(ctx->hdr.rows)); + print->media = le32_to_cpu(ctx->hdr.media); + print->mode = le32_to_cpu(ctx->hdr.mode); + print->method = le32_to_cpu(ctx->hdr.method); if ((ret = s2145_do_cmd(ctx, cmdbuf, sizeof(*print), @@ -1671,6 +1605,9 @@ static int shinkos2145_main_loop(void *vctx, int copies) { if (sts->hdr.error == ERROR_BUFFER_FULL) { INFO("Printer Buffers full, retrying\n"); break; + } else if ((sts->hdr.status & 0xf0) == 0x30 || sts->hdr.status == 0x21) { + INFO("Printer busy (%s), retrying\n", status_str(sts->hdr.status)); + break; } else if (sts->hdr.status != ERROR_NONE) goto printer_error; } @@ -1685,7 +1622,7 @@ static int shinkos2145_main_loop(void *vctx, int copies) { state = S_PRINTER_SENT_DATA; break; case S_PRINTER_SENT_DATA: - if (ctx->fast_return) { + if (fast_return) { INFO("Fast return mode enabled.\n"); state = S_FINISHED; } else if (sts->hdr.status == STATUS_READY || @@ -1700,19 +1637,7 @@ static int shinkos2145_main_loop(void *vctx, int copies) { if (state != S_FINISHED) goto top; - /* This printer handles copies internally */ - copies = 1; - - /* Clean up */ - if (terminate) - copies = 1; - - INFO("Print complete (%d copies remaining)\n", copies - 1); - - if (copies && --copies) { - state = S_IDLE; - goto top; - } + INFO("Print complete\n"); return CUPS_BACKEND_OK; @@ -1764,29 +1689,21 @@ static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t end /* Exported */ #define USB_VID_SHINKO 0x10CE #define USB_PID_SHINKO_S2145 0x000E -#define USB_PID_SHINKO_S6145 0x0019 -#define USB_PID_SHINKO_S6245 0x001D -//#define USB_VID_CIAAT xxxxxx -//#define USB_PID_CIAAT_BRAVA21 xxxxx struct dyesub_backend shinkos2145_backend = { .name = "Shinko/Sinfonia CHC-S2145", - .version = "0.40", + .version = "0.46", .uri_prefix = "shinkos2145", .cmdline_usage = shinkos2145_cmdline, .cmdline_arg = shinkos2145_cmdline_arg, .init = shinkos2145_init, .attach = shinkos2145_attach, .teardown = shinkos2145_teardown, - .early_parse = shinkos2145_early_parse, .read_parse = shinkos2145_read_parse, .main_loop = shinkos2145_main_loop, .query_serno = shinkos2145_query_serno, .devices = { { USB_VID_SHINKO, USB_PID_SHINKO_S2145, P_SHINKO_S2145, ""}, -// { USB_VID_SHINKO, USB_PID_SHINKO_S6145, P_SHINKO_S2145, ""}, -// { USB_VID_SHINKO, USB_PID_SHINKO_S6245, P_SHINKO_S2145, ""}, -// { USB_VID_CIAAT, USB_PID_CIAAT_BRAVA21, P_SHINKO_S2145, ""}, { 0, 0, 0, ""} } }; @@ -1810,67 +1727,4 @@ struct dyesub_backend shinkos2145_backend = { 04 03 02 01 [[ footer ]] - * CHC-S6245 data format - - Spool file consists of an 116-byte header, followed by RGB-packed data, - followed by a 4-byte footer. Header appears to consist of a series of - 4-byte Little Endian words. - - 10 00 00 00 MM MM 00 00 01 00 00 00 01 00 00 00 MM == Model (ie 6245d) - 64 00 00 00 00 00 00 00 TT 00 00 00 00 00 00 00 TT == 0x20 8x4, 0x21 8x5, 0x22 8x6, 0x23 8x8, 0x10 8x10, 0x11 8x12 - 00 00 00 00 00 00 00 00 XX 00 00 00 00 00 00 00 XX == 0x03 matte, 0x02 glossy, 0x01 no coat - 00 00 00 00 WW WW 00 00 HH HH 00 00 NN 00 00 00 WW/HH Width, Height (LE), NN == Copies - 00 00 00 00 00 00 00 00 00 00 00 00 ce ff ff ff - 00 00 00 00 ce ff ff ff QQ QQ 00 00 ce ff ff ff QQ == DPI (300) - 00 00 00 00 ce ff ff ff 00 00 00 00 00 00 00 00 - 00 00 00 00 - - [[Packed RGB payload of WW*HH*3 bytes]] - - 04 03 02 01 [[ footer ]] - - * CHC-S6145 data format - - Spool file consists of an 116-byte header, followed by RGB-packed data, - followed by a 4-byte footer. Header appears to consist of a series of - 4-byte Little Endian words. - - 10 00 00 00 MM MM 00 00 HH 00 00 00 01 00 00 00 MM == Model (ie 6145d), HH == 0x02 (5" media), 0x03 (6" media) - 64 00 00 00 00 00 00 00 TT 00 00 00 00 00 00 00 TT == 0x08 5x5, 0x03 5x7, 0x07 2x6, 0x00 4x6, 0x06 6x6/6x6+6x2/6x8 - UU 00 00 00 ZZ 00 00 00 XX 00 00 00 00 00 00 00 XX == 0x00 default, 0x02 glossy, 0x03 matte, ZZ == 0x00 default, 0x01 == std qual; UU == 0x00 normal, 0x04 2x6*2, 0x05 6x6+2x6 - 00 00 00 00 WW WW 00 00 HH HH 00 00 NN 00 00 00 WW/HH Width, Height (LE), NN == Copies - 00 00 00 00 00 00 00 00 00 00 00 00 ce ff ff ff - 00 00 00 00 ce ff ff ff QQ QQ 00 00 ce ff ff ff QQ == DPI (300) - 00 00 00 00 ce ff ff ff 00 00 00 00 00 00 00 00 - 00 00 00 00 - - [[Packed RGB payload of WW*HH*3 bytes]] - - 04 03 02 01 [[ footer ]] - - * CIAAT Brava 21 data format - - This printer is supposed to be a variant of the S6145, but uses a - different spool format -- but seems to use the same command language. - - 01 40 12 00 01 NN 00 YY YY XX XX TT 00 00 00 00 00 00 01 MM QQ 00 - - NN == copies - YY YY == Columns (LE) - XX XX == Rows (LE) - MM == Overcoat (02 = glossy, 03 = matte, 01 = none) - QQ == Multicut (00 = normal, 01 = none, 02 = 2*4x6, - 04 = 2*2x6, 80 = 4x6-notrim) - TT == Type (00 = 4x6, 03 = 5x7, 06 = 8x6, 07 = 2x6) - - 1844*2434 8x6 - 1844*2492 4x6*2 - 1548*2140 5x7 - 1844*1240 4x6 (and 2x6*2) - 1844*1210 4x6-notrim (WTF?) - 1844*634 2x6 - - - [[ Followed by XX*YY*3 bytes of image data, RGB ]] - */ |