[libusb] Better support the CP-10.

This commit is contained in:
Solomon Peachy 2012-12-11 14:05:38 -05:00
parent c4d5b80bd8
commit 109dfacbd3
3 changed files with 43 additions and 14 deletions

View File

@ -293,13 +293,14 @@
01 00 00 00 [ss] 00 [pg] 00 00 00 00 [xx] [idle, waiting for init]
02 00 [rr] 00 00 00 [pg] 00 00 00 00 [xx] [init sent, paper feeding]
02 00 [rr] 00 10 00 [pg] 00 00 00 00 [xx] [init sent, paper feeding]
02 00 [rr] 00 70 00 [pg] 00 00 00 00 [xx] [waiting for Y data]
02 00 [rr] 00 [qq] 00 [pg] 00 00 00 00 [xx] [waiting for Y data]
04 00 00 00 00 00 [pg] 00 00 00 00 [xx] [waiting for M data]
08 00 00 00 00 00 [pg] 00 00 00 00 [xx] [waiting for C data]
10 00 00 00 00 00 [pg] 00 00 00 00 [xx] [C done, waiting]
20 00 00 00 00 00 [pg] 00 00 00 00 [xx] [All done]
[xx] is 0x01 on the CP780/CP800/CP900, 0x00 on all others.
[qq] is 0x00 on CP-10, 0x70 on all others.
[rr] is error code:
0x00 no error

View File

@ -121,7 +121,7 @@ static int dump_data_libusb(int remaining, int present, int data_fd,
static int find_and_enumerate(struct libusb_context *ctx,
struct libusb_device ***list,
char *match_serno,
int printer_type,
int *printer_type,
int scan_only)
{
int num;
@ -146,29 +146,35 @@ static int find_and_enumerate(struct libusb_context *ctx,
switch(desc.idProduct) {
case USB_PID_CANON_ES1: // "Canon SELPHY ES1"
if (printer_type == P_ES1)
if (*printer_type == P_ES1)
found = i;
valid = 1;
break;
case USB_PID_CANON_ES2: // "Canon SELPHY ES2"
case USB_PID_CANON_ES20: // "Canon SELPHY ES20"
if (printer_type == P_ES2_20)
if (*printer_type == P_ES2_20)
found = i;
valid = 1;
break;
case USB_PID_CANON_ES3: // "Canon SELPHY ES3"
case USB_PID_CANON_ES30: // "Canon SELPHY ES30"
if (printer_type == P_ES3_30)
if (*printer_type == P_ES3_30)
found = i;
valid = 1;
break;
case USB_PID_CANON_ES40: // "Canon SELPHY ES40"
case USB_PID_CANON_CP790:
if (printer_type == P_ES40_CP790)
if (*printer_type == P_ES40_CP790)
found = i;
valid = 1;
break;
case USB_PID_CANON_CP10: // "Canon CP-10"
if (*printer_type == P_CP_XXX) {
found = i;
*printer_type = P_CP10;
}
valid = 1;
break;
case USB_PID_CANON_CP100: // "Canon CP-100"
case USB_PID_CANON_CP200: // "Canon CP-200"
case USB_PID_CANON_CP220: // "Canon CP-220"
@ -191,7 +197,7 @@ static int find_and_enumerate(struct libusb_context *ctx,
case USB_PID_CANON_CP800: // "Canon SELPHY CP800"
case USB_PID_CANON_CP810: // "Canon SELPHY CP810"
case USB_PID_CANON_CP900: // "Canon SELPHY CP900"
if (printer_type == P_CP_XXX)
if (*printer_type == P_CP_XXX)
found = i;
valid = 1;
break;
@ -202,7 +208,7 @@ static int find_and_enumerate(struct libusb_context *ctx,
int type = atoi(getenv("SELPHY_TYPE"));
if (pid == desc.idProduct) {
valid = 1;
if (printer_type == type) {
if (*printer_type == type) {
found = i;
}
}
@ -306,7 +312,7 @@ int main (int argc, char **argv)
VERSION,
argv[0], argv[0]);
libusb_init(&ctx);
find_and_enumerate(ctx, &list, NULL, printer_type, 1);
find_and_enumerate(ctx, &list, NULL, &printer_type, 1);
libusb_free_device_list(list, 1);
libusb_exit(ctx);
exit(1);
@ -355,15 +361,16 @@ int main (int argc, char **argv)
DEBUG("%sFile intended for a '%s' printer\n", bw_mode? "B/W " : "", printers[printer_type].model);
plane_len += 12; /* Add in plane header */
/* Libusb setup */
libusb_init(&ctx);
found = find_and_enumerate(ctx, &list, use_serno, &printer_type, 0);
/* Compute offsets and other such things */
plane_len += 12; /* Plane header length */
paper_code_offset = printers[printer_type].paper_code_offset;
if (printers[printer_type].pgcode_offset != -1)
paper_code = printers[printer_type].paper_codes[buffer[printers[printer_type].pgcode_offset]];
/* Libusb setup */
libusb_init(&ctx);
found = find_and_enumerate(ctx, &list, use_serno, printer_type, 0);
if (found == -1) {
ERROR("No suitable printers found!\n");
ret = 3;

View File

@ -69,6 +69,7 @@ enum {
P_ES3_30,
P_ES40_CP790,
P_CP_XXX,
P_CP10,
P_END
};
@ -143,6 +144,20 @@ struct printer_data printers[P_END] = {
.paper_code_offset = 6,
.error_offset = 2,
},
{ .type = P_CP10,
.model = "SELPHY CP-10",
.init_length = 12,
.foot_length = 0,
.init_readback = { 0x01, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 },
.ready_y_readback = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 },
.ready_m_readback = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 },
.ready_c_readback = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 },
.done_c_readback = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 },
// .paper_codes
.pgcode_offset = 3,
.paper_code_offset = 6,
.error_offset = 2,
},
};
#define MAX_HEADER 28
@ -184,6 +199,12 @@ static void setup_paper_codes(void)
printers[P_CP_XXX].paper_codes[0x02] = 0x22;
printers[P_CP_XXX].paper_codes[0x03] = 0x33;
printers[P_CP_XXX].paper_codes[0x04] = 0x44;
/* SELPHY CP-10 paper codes */
printers[P_CP10].paper_codes[0x01] = -1;
printers[P_CP10].paper_codes[0x02] = -1;
printers[P_CP10].paper_codes[0x03] = 0x00;
printers[P_CP10].paper_codes[0x04] = -1;
}
#define INCORRECT_PAPER -999