From a359fa17c478b91bead49f9bd9c8a724eafb51f6 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sat, 8 Feb 2014 14:45:55 -0500 Subject: [PATCH] canonselphy: Split the CP790 and ES40 handling apart. They share nothing beyond a common spool file format: * Different readbacks (though the necessary parts are unique) * Different error codes * Different media reporting system and identifiers --- backend_canonselphy.c | 106 ++++++++++++++++++++++++++++++------------ backend_common.h | 2 + 2 files changed, 78 insertions(+), 30 deletions(-) diff --git a/backend_canonselphy.c b/backend_canonselphy.c index 0e8ba98..4a4c159 100644 --- a/backend_canonselphy.c +++ b/backend_canonselphy.c @@ -139,20 +139,22 @@ static int es3_error_detect(uint8_t *rdbuf) static int es40_error_detect(uint8_t *rdbuf) { - if (!rdbuf[4] && !rdbuf[5]) { - /* ES40 */ - if (!rdbuf[3]) - return 0; + /* ES40 */ + if (!rdbuf[3]) + return 0; + + if (rdbuf[3] == 0x01) + ERROR("Generic communication error\n"); + else if (rdbuf[3] == 0x32) + ERROR("Cover open or media empty!\n"); + else + ERROR("Unknown error - %02x\n", rdbuf[3]); - if (rdbuf[3] == 0x01) - ERROR("Generic communication error\n"); - else if (rdbuf[3] == 0x32) - ERROR("Cover open or media empty!\n"); - else - ERROR("Unknown error - %02x\n", rdbuf[3]); - return 1; - } + return 1; +} +static int cp790_error_detect(uint8_t *rdbuf) +{ /* CP790 */ if (rdbuf[4] == 0x10 && rdbuf[5] == 0xff) { ERROR("No ribbon loaded!\n"); @@ -174,6 +176,7 @@ static int es40_error_detect(uint8_t *rdbuf) return 0; } + static int cp10_error_detect(uint8_t *rdbuf) { if (!rdbuf[2]) @@ -252,21 +255,43 @@ static struct printer_data selphy_printers[] = { .paper_code_offset = -1, .error_detect = es3_error_detect, }, + /* PLACEHOLDER FOR DETECTION PURPOSES ONLY */ { .type = P_ES40_CP790, .model = "SELPHY ES40/CP790", .init_length = 16, .foot_length = 12, - .init_readback = { 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, - .ready_y_readback = { 0x00, 0x01, 0x01, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, - .ready_m_readback = { 0x00, 0x03, 0x02, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, - .ready_c_readback = { 0x00, 0x05, 0x03, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, - .done_c_readback = { 0x00, 0x00, 0x10, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + .pgcode_offset = 2, + }, + { .type = P_ES40, + .model = "SELPHY ES40", + .init_length = 16, + .foot_length = 12, + .init_readback = { 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + .ready_y_readback = { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + .ready_m_readback = { 0x00, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + .ready_c_readback = { 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + .done_c_readback = { 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, // .clear_error + clear_error_len // .paper_codes .pgcode_offset = 2, - .paper_code_offset = 11, // XXX ES40 only, CP790 doesn't use this. + .paper_code_offset = 11, .error_detect = es40_error_detect, }, + { .type = P_CP790, + .model = "SELPHY CP790", + .init_length = 16, + .foot_length = 12, + .init_readback = { 0x00, 0x00, -1, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + .ready_y_readback = { 0x00, 0x01, 0x01, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + .ready_m_readback = { 0x00, 0x03, 0x02, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + .ready_c_readback = { 0x00, 0x05, 0x03, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + .done_c_readback = { 0x00, 0x00, 0x10, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, + // .clear_error + clear_error_len + // .paper_codes + .pgcode_offset = 2, + .paper_code_offset = -1, // XXX 11? + .error_detect = cp790_error_detect, + }, { .type = P_CP_XXX, .model = "SELPHY CP Series (!CP-10/CP790)", .init_length = 12, @@ -331,12 +356,18 @@ static void setup_paper_codes(void) case P_ES3_30: /* N/A, printer does not report types */ break; - case P_ES40_CP790: // ? guess + case P_ES40: selphy_printers[i].paper_codes[0x00] = 0x11; selphy_printers[i].paper_codes[0x01] = 0x22; selphy_printers[i].paper_codes[0x02] = 0x33; selphy_printers[i].paper_codes[0x03] = 0x44; break; + case P_CP790: // XXX guess? + selphy_printers[i].paper_codes[0x00] = 0x01; + selphy_printers[i].paper_codes[0x01] = 0x02; + selphy_printers[i].paper_codes[0x02] = 0x03; + selphy_printers[i].paper_codes[0x03] = 0x04; + break; case P_CP_XXX: selphy_printers[i].paper_codes[0x01] = 0x11; selphy_printers[i].paper_codes[0x02] = 0x22; @@ -483,6 +514,32 @@ static void canonselphy_attach(void *vctx, struct libusb_device_handle *dev, ctx->dev = dev; ctx->endp_up = endp_up; ctx->endp_down = endp_down; + + /* Special cases for some models */ + if (ctx->printer->type == P_ES40_CP790) { + struct libusb_device *device; + struct libusb_device_descriptor desc; + int i; + int printer_type; + + device = libusb_get_device(dev); + libusb_get_device_descriptor(device, &desc); + +#define USB_PID_CANON_CP790 0x31E7 +#define USB_PID_CANON_ES40 0x31EE + + if (desc.idProduct == USB_PID_CANON_CP790) + printer_type = P_CP790; + else if (desc.idProduct == USB_PID_CANON_ES40) + printer_type = P_ES40; + + for (i = 0; selphy_printers[i].type != -1; i++) { + if (selphy_printers[i].type == printer_type) { + ctx->printer = &selphy_printers[i]; + break; + } + } + } } static void canonselphy_teardown(void *vctx) { @@ -717,17 +774,6 @@ top: return 4; } } - } else if (ctx->printer->type == P_ES40_CP790) { - -#if 0 - if ((rdbuf[ctx->printer->paper_code_offset] & 0x0f) != - (ctx->paper_code & 0x0f)) { - ERROR("Incorrect media/ribbon loaded (%02x vs %02x), aborting job!\n", - ctx->paper_code, - rdbuf[ctx->printer->paper_code_offset]); - return 3; /* Hold this job, don't stop queue */ -#endif - } } else { if (rdbuf[ctx->printer->paper_code_offset] != ctx->paper_code) { diff --git a/backend_common.h b/backend_common.h index c811aa6..8ac96b6 100644 --- a/backend_common.h +++ b/backend_common.h @@ -88,6 +88,8 @@ enum { P_ES2_20, P_ES3_30, P_ES40_CP790, + P_ES40, + P_CP790, P_CP_XXX, P_CP10, P_KODAK_6800,