selphy_print/backend_canonselphy.c

1155 lines
34 KiB
C
Raw Normal View History

2012-10-26 22:06:47 -04:00
/*
* Canon SELPHY ES/CP series CUPS backend -- libusb-1.0 version
2012-10-26 22:06:47 -04:00
*
* (c) 2007-2014 Solomon Peachy <pizza@shaftnet.org>
2012-10-26 22:06:47 -04:00
*
* The latest version of this program can be found at:
2013-05-02 11:32:15 -04:00
*
* http://git.shaftnet.org/cgit/selphy_print.git
2013-05-02 11:32:15 -04:00
*
2012-10-26 22:06:47 -04:00
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* [http://www.gnu.org/licenses/gpl-3.0.html]
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include "backend_common.h"
#define READBACK_LEN 12
struct printer_data {
int type; /* P_??? */
char *model; /* eg "SELPHY ES1" */
int init_length;
int foot_length;
int16_t init_readback[READBACK_LEN];
int16_t ready_y_readback[READBACK_LEN];
int16_t ready_m_readback[READBACK_LEN];
int16_t ready_c_readback[READBACK_LEN];
int16_t done_c_readback[READBACK_LEN];
int16_t clear_error[READBACK_LEN];
int16_t paper_codes[256];
int16_t pgcode_offset; /* Offset into printjob for paper type */
int16_t paper_code_offset; /* Offset in readback for paper type */
int (*error_detect)(uint8_t *rdbuf);
};
static int es1_error_detect(uint8_t *rdbuf)
{
if (rdbuf[1] == 0x01) {
if (rdbuf[9] == 0x00) {
ERROR("Cover open!\n");
} else {
ERROR("Unknown error %02x\n", rdbuf[9]);
}
return 1;
} else if (rdbuf[4] == 0x01 && rdbuf[5] == 0xff &&
rdbuf[6] == 0xff && rdbuf[7] == 0xff) {
ERROR("No media loaded!\n");
return 1;
}
return 0;
}
static int es2_error_detect(uint8_t *rdbuf)
{
if (rdbuf[0] == 0x16 &&
rdbuf[1] == 0x01) {
ERROR("Cover open!\n");
return 1;
}
if (rdbuf[0] == 0x02 &&
rdbuf[4] == 0x05 &&
rdbuf[5] == 0x05 &&
rdbuf[6] == 0x02) {
ERROR("No media loaded!\n");
return 1;
}
if (rdbuf[0] == 0x14) {
ERROR("Out of media!\n");
return 1;
}
return 0;
}
static int es3_error_detect(uint8_t *rdbuf)
{
if (rdbuf[8] == 0x01) {
if (rdbuf[10] == 0x0f) {
ERROR("Communications Error\n");
} else if (rdbuf[10] == 0x01) {
ERROR("No media/ribbon loaded!\n");
} else {
ERROR("Unknown error - %02x + %02x\n",
rdbuf[8], rdbuf[10]);
}
return 1;
} else if (rdbuf[8] == 0x03 &&
rdbuf[10] == 0x02) {
ERROR("No media!\n");
return 1;
} else if (rdbuf[8] == 0x08 &&
rdbuf[10] == 0x04) {
ERROR("Cover open!\n");
return 1;
}
if (rdbuf[8] || rdbuf[10]) {
ERROR("Unknown error - %02x + %02x\n",
rdbuf[8], rdbuf[10]);
}
return 0;
}
static int es40_error_detect(uint8_t *rdbuf)
{
if (!rdbuf[4] && !rdbuf[5]) {
/* 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]);
return 1;
}
/* CP790 */
if (rdbuf[4] == 0x10 && rdbuf[5] == 0xff) {
ERROR("No ribbon!\n");
return 1;
} else if (rdbuf[4] == 0xff && rdbuf[5] == 0x01) {
ERROR("No media loaded!\n");
return 1;
}
return 0;
}
static int cp10_error_detect(uint8_t *rdbuf)
{
if (!rdbuf[2])
return 0;
if (rdbuf[2] == 0x80)
ERROR("No ribbon\n");
else if (rdbuf[2] == 0x01)
ERROR("No media!\n");
else
ERROR("Unknown error - %02x\n", rdbuf[2]);
return 1;
}
static int cpxxx_error_detect(uint8_t *rdbuf)
{
if (!rdbuf[2])
return 0;
if (rdbuf[2] == 0x01)
ERROR("Out of paper!\n");
else if (rdbuf[2] == 0x04)
ERROR("Ribbon problem!\n");
else if (rdbuf[2] == 0x08)
ERROR("Ribbon depleted!\n");
else
ERROR("Unknown error - %02x\n", rdbuf[2]);
return 1;
}
static struct printer_data selphy_printers[] = {
{ .type = P_ES1,
.model = "SELPHY ES1",
.init_length = 12,
.foot_length = 0,
.init_readback = { 0x02, 0x00, 0x00, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
.ready_y_readback = { 0x04, 0x00, 0x01, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
.ready_m_readback = { 0x04, 0x00, 0x03, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
.ready_c_readback = { 0x04, 0x00, 0x07, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
.done_c_readback = { 0x04, 0x00, 0x00, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
// .clear_error
// .paper_codes
.pgcode_offset = 3,
.paper_code_offset = 6,
.error_detect = es1_error_detect,
},
{ .type = P_ES2_20,
.model = "SELPHY ES2/ES20",
.init_length = 16,
.foot_length = 0,
.init_readback = { 0x02, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
.ready_y_readback = { 0x03, 0x00, 0x01, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
.ready_m_readback = { 0x06, 0x00, 0x03, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
.ready_c_readback = { 0x09, 0x00, 0x07, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
.done_c_readback = { 0x09, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
// .clear_error
// .paper_codes
.pgcode_offset = 2,
.paper_code_offset = 4,
.error_detect = es2_error_detect,
},
{ .type = P_ES3_30,
.model = "SELPHY ES3/ES30",
.init_length = 16,
.foot_length = 12,
.init_readback = { 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
.ready_y_readback = { 0x01, 0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
.ready_m_readback = { 0x03, 0xff, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
.ready_c_readback = { 0x05, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
.done_c_readback = { 0x00, 0xff, 0x10, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
// .clear_error
// .paper_codes
.pgcode_offset = 2,
.paper_code_offset = -1,
.error_detect = es3_error_detect,
},
{ .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 },
// .clear_error
// .paper_codes
.pgcode_offset = 2,
.paper_code_offset = 11,
.error_detect = es40_error_detect,
},
{ .type = P_CP_XXX,
.model = "SELPHY CP Series (!CP-10/CP790)",
.init_length = 12,
.foot_length = 0, /* CP900 has four-byte NULL footer that can be safely ignored */
.init_readback = { 0x01, 0x00, 0x00, 0x00, -1, 0x00, -1, 0x00, 0x00, 0x00, 0x00, -1 },
.ready_y_readback = { 0x02, 0x00, 0x00, 0x00, 0x70, 0x00, -1, 0x00, 0x00, 0x00, 0x00, -1 },
.ready_m_readback = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, -1 },
.ready_c_readback = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, -1 },
.done_c_readback = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, -1 },
.clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
// .paper_codes
.pgcode_offset = 3,
.paper_code_offset = 6,
.error_detect = cpxxx_error_detect,
},
{ .type = P_CP10,
.model = "SELPHY CP-10",
.init_length = 12,
.foot_length = 0,
.init_readback = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.ready_y_readback = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.ready_m_readback = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.ready_c_readback = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.done_c_readback = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
// .paper_codes
// .clear_error
.pgcode_offset = -1,
.paper_code_offset = -1,
.error_detect = cp10_error_detect,
},
{ .type = -1 },
};
#define MAX_HEADER 28
static const uint32_t es40_cp790_plane_lengths[4] = { 2227456, 1601600, 698880, 2976512 };
static void setup_paper_codes(void)
{
int i, j;
2013-07-18 23:12:25 -04:00
for (i = 0 ; ; i++) {
if (selphy_printers[i].type == -1)
break;
/* Default all to IGNORE */
for (j = 0 ; j < 256 ; j++)
selphy_printers[i].paper_codes[j] = -1;
2013-07-18 23:12:25 -04:00
/* Set up specifics */
switch (selphy_printers[i].type) {
case P_ES1:
selphy_printers[i].paper_codes[0x11] = 0x01;
selphy_printers[i].paper_codes[0x12] = 0x02; // ? guess
selphy_printers[i].paper_codes[0x13] = 0x03;
break;
case P_ES2_20:
selphy_printers[i].paper_codes[0x01] = 0x01;
selphy_printers[i].paper_codes[0x02] = 0x02; // ? guess
selphy_printers[i].paper_codes[0x03] = 0x03;
break;
case P_ES3_30:
/* N/A, printer does not report types */
break;
case P_ES40_CP790: // ? guess
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_CP_XXX:
selphy_printers[i].paper_codes[0x01] = 0x11;
selphy_printers[i].paper_codes[0x02] = 0x22;
selphy_printers[i].paper_codes[0x03] = 0x33;
selphy_printers[i].paper_codes[0x04] = 0x44;
break;
case P_CP10:
/* N/A, printer supports one type only */
break;
}
}
}
#define INCORRECT_PAPER -999
/* Program states */
enum {
S_IDLE = 0,
S_PRINTER_READY,
S_PRINTER_INIT_SENT,
S_PRINTER_READY_Y,
S_PRINTER_Y_SENT,
S_PRINTER_READY_M,
S_PRINTER_M_SENT,
S_PRINTER_READY_C,
S_PRINTER_C_SENT,
S_PRINTER_DONE,
S_FINISHED,
};
static int fancy_memcmp(const uint8_t *buf_a, const int16_t *buf_b, uint len)
{
uint i;
for (i = 0 ; i < len ; i++) {
if (buf_b[i] == -1)
continue;
else if (buf_a[i] > buf_b[i])
return 1;
else if (buf_a[i] < buf_b[i])
return -1;
}
return 0;
}
static int parse_printjob(uint8_t *buffer, uint8_t *bw_mode, uint32_t *plane_len)
{
int printer_type = -1;
if (buffer[0] != 0x40 &&
buffer[1] != 0x00) {
goto done;
}
if (buffer[12] == 0x40 &&
buffer[13] == 0x01) {
*plane_len = *(uint32_t*)(&buffer[16]);
*plane_len = le32_to_cpu(*plane_len);
if (buffer[2] == 0x00) {
if (*plane_len == 688480)
printer_type = P_CP10;
else
printer_type = P_CP_XXX;
} else {
printer_type = P_ES1;
*bw_mode = (buffer[2] == 0x20);
}
goto done;
}
*plane_len = *(uint32_t*)(&buffer[12]);
*plane_len = le32_to_cpu(*plane_len);
if (buffer[16] == 0x40 &&
buffer[17] == 0x01) {
if (buffer[4] == 0x02) {
printer_type = P_ES2_20;
*bw_mode = (buffer[7] == 0x01);
goto done;
}
if (es40_cp790_plane_lengths[buffer[2]] == *plane_len) {
printer_type = P_ES40_CP790;
*bw_mode = (buffer[3] == 0x01);
goto done;
} else {
printer_type = P_ES3_30;
*bw_mode = (buffer[3] == 0x01);
goto done;
}
}
done:
return printer_type;
}
/* Private data stucture */
struct canonselphy_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
struct printer_data *printer;
uint8_t bw_mode;
int16_t paper_code;
uint32_t plane_len;
uint8_t *header;
uint8_t *plane_y;
uint8_t *plane_m;
uint8_t *plane_c;
uint8_t *footer;
uint8_t *buffer;
};
static void *canonselphy_init(void)
{
struct canonselphy_ctx *ctx = malloc(sizeof(struct canonselphy_ctx));
if (!ctx)
return NULL;
memset(ctx, 0, sizeof(struct canonselphy_ctx));
/* Static initialization */
setup_paper_codes();
ctx->buffer = malloc(MAX_HEADER);
return ctx;
}
static void canonselphy_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct canonselphy_ctx *ctx = vctx;
2013-11-23 19:51:55 -05:00
UNUSED(jobid);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
}
static void canonselphy_teardown(void *vctx) {
struct canonselphy_ctx *ctx = vctx;
if (!ctx)
return;
if (ctx->header)
free(ctx->header);
if (ctx->plane_y)
free(ctx->plane_y);
if (ctx->plane_m)
free(ctx->plane_m);
if (ctx->plane_c)
free(ctx->plane_c);
if (ctx->footer)
free(ctx->footer);
if (ctx->buffer)
free(ctx->buffer);
free(ctx);
}
static int canonselphy_early_parse(void *vctx, int data_fd)
{
struct canonselphy_ctx *ctx = vctx;
int printer_type, i;
if (!ctx)
return -1;
/* Figure out printer this file is intended for */
i = read(data_fd, ctx->buffer, MAX_HEADER);
if (i < 0 || i != MAX_HEADER) {
if (i == 0)
return -1;
ERROR("Read failed (%d/%d/%d)\n",
i, 0, MAX_HEADER);
perror("ERROR: Read failed");
return i;
}
printer_type = parse_printjob(ctx->buffer, &ctx->bw_mode, &ctx->plane_len);
for (i = 0; selphy_printers[i].type != -1; i++) {
if (selphy_printers[i].type == printer_type) {
ctx->printer = &selphy_printers[i];
break;
}
}
if (!ctx->printer) {
ERROR("Unrecognized printjob file format!\n");
return -1;
}
ctx->plane_len += 12; /* Add in plane header length! */
if (ctx->printer->pgcode_offset != -1)
ctx->paper_code = ctx->printer->paper_codes[ctx->buffer[ctx->printer->pgcode_offset]];
else
ctx->paper_code = -1;
INFO("%sFile intended for a '%s' printer\n", ctx->bw_mode? "B/W " : "", ctx->printer->model);
return printer_type;
}
static int canonselphy_read_parse(void *vctx, int data_fd)
{
struct canonselphy_ctx *ctx = vctx;
int i, remain;
if (!ctx)
return 1;
if (ctx->header) {
free(ctx->header);
ctx->header = NULL;
}
if (ctx->plane_y) {
free(ctx->plane_y);
ctx->plane_y = NULL;
}
if (ctx->plane_m) {
free(ctx->plane_m);
ctx->plane_m = NULL;
}
if (ctx->plane_c) {
free(ctx->plane_c);
ctx->plane_c = NULL;
}
if (ctx->footer) {
free(ctx->footer);
ctx->footer = NULL;
}
/* Set up buffers */
ctx->plane_y = malloc(ctx->plane_len);
ctx->plane_m = malloc(ctx->plane_len);
ctx->plane_c = malloc(ctx->plane_len);
ctx->header = malloc(ctx->printer->init_length);
ctx->footer = malloc(ctx->printer->foot_length);
if (!ctx->plane_y || !ctx->plane_m || !ctx->plane_c || !ctx->header ||
(ctx->printer->foot_length && !ctx->footer)) {
ERROR("Memory allocation failure!\n");
return 1;
}
/* Move over chunks already read in */
memcpy(ctx->header, ctx->buffer, ctx->printer->init_length);
memcpy(ctx->plane_y, ctx->buffer+ctx->printer->init_length,
MAX_HEADER-ctx->printer->init_length);
/* Read in YELLOW plane */
remain = ctx->plane_len - (MAX_HEADER-ctx->printer->init_length);
while (remain > 0) {
i = read(data_fd, ctx->plane_y + (ctx->plane_len - remain), remain);
if (i < 0)
return i;
remain -= i;
}
/* Read in MAGENTA plane */
remain = ctx->plane_len;
while (remain > 0) {
i = read(data_fd, ctx->plane_m + (ctx->plane_len - remain), remain);
if (i < 0)
return i;
remain -= i;
}
/* Read in CYAN plane */
remain = ctx->plane_len;
while (remain > 0) {
i = read(data_fd, ctx->plane_c + (ctx->plane_len - remain), remain);
if (i < 0)
return i;
remain -= i;
}
/* Read in footer */
if (ctx->printer->foot_length) {
remain = ctx->printer->foot_length;
while (remain > 0) {
i = read(data_fd, ctx->footer + (ctx->printer->foot_length - remain), remain);
if (i < 0)
return i;
remain -= i;
}
}
2012-10-26 22:06:47 -04:00
return 0;
}
2012-10-26 22:06:47 -04:00
static int canonselphy_main_loop(void *vctx, int copies) {
struct canonselphy_ctx *ctx = vctx;
uint8_t rdbuf[READBACK_LEN], rdbuf2[READBACK_LEN];
int last_state = -1, state = S_IDLE;
int ret, num;
/* Read in the printer status */
ret = read_data(ctx->dev, ctx->endp_up,
rdbuf, READBACK_LEN, &num);
if (ret < 0)
return ret;
top:
if (state != last_state) {
if (dyesub_debug)
DEBUG("last_state %d new %d\n", last_state, state);
}
/* Do it twice to clear initial state */
ret = read_data(ctx->dev, ctx->endp_up,
rdbuf, READBACK_LEN, &num);
if (ret < 0)
return ret;
if (num != READBACK_LEN) {
ERROR("Short read! (%d/%d)\n", num, READBACK_LEN);
return 4;
}
2012-10-28 12:19:17 -04:00
if (memcmp(rdbuf, rdbuf2, READBACK_LEN)) {
memcpy(rdbuf2, rdbuf, READBACK_LEN);
} else if (state == last_state) {
sleep(1);
}
last_state = state;
fflush(stderr);
/* Error detection */
if (ctx->printer->error_detect(rdbuf))
return 4;
switch(state) {
case S_IDLE:
INFO("Waiting for printer idle\n");
if (fancy_memcmp(rdbuf, ctx->printer->init_readback, READBACK_LEN))
break;
/* Make sure paper is correct */
if (ctx->paper_code != -1) {
if (ctx->printer->type == P_ES40_CP790) {
if ((rdbuf[ctx->printer->paper_code_offset] & 0x0f) !=
(ctx->paper_code & 0x0f)) {
ERROR("Incorrect paper 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 */
}
} else {
if (rdbuf[ctx->printer->paper_code_offset] !=
ctx->paper_code) {
ERROR("Incorrect paper 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 */
}
}
}
state = S_PRINTER_READY;
break;
case S_PRINTER_READY:
INFO("Printing started; Sending init sequence\n");
/* Send printer init */
if ((ret = send_data(ctx->dev, ctx->endp_down, ctx->header, ctx->printer->init_length)))
return ret;
2012-10-26 22:06:47 -04:00
state = S_PRINTER_INIT_SENT;
break;
case S_PRINTER_INIT_SENT:
if (!fancy_memcmp(rdbuf, ctx->printer->ready_y_readback, READBACK_LEN)) {
state = S_PRINTER_READY_Y;
}
break;
case S_PRINTER_READY_Y:
if (ctx->bw_mode)
INFO("Sending BLACK plane\n");
else
INFO("Sending YELLOW plane\n");
if ((ret = send_data(ctx->dev, ctx->endp_down, ctx->plane_y, ctx->plane_len)))
return ret;
state = S_PRINTER_Y_SENT;
break;
case S_PRINTER_Y_SENT:
if (!fancy_memcmp(rdbuf, ctx->printer->ready_m_readback, READBACK_LEN)) {
if (ctx->bw_mode)
2012-10-26 23:35:48 -04:00
state = S_PRINTER_DONE;
else
state = S_PRINTER_READY_M;
}
break;
case S_PRINTER_READY_M:
INFO("Sending MAGENTA plane\n");
if ((ret = send_data(ctx->dev, ctx->endp_down, ctx->plane_m, ctx->plane_len)))
return ret;
state = S_PRINTER_M_SENT;
break;
case S_PRINTER_M_SENT:
if (!fancy_memcmp(rdbuf, ctx->printer->ready_c_readback, READBACK_LEN)) {
state = S_PRINTER_READY_C;
}
break;
case S_PRINTER_READY_C:
INFO("Sending CYAN plane\n");
if ((ret = send_data(ctx->dev, ctx->endp_down, ctx->plane_c, ctx->plane_len)))
return ret;
state = S_PRINTER_C_SENT;
break;
case S_PRINTER_C_SENT:
if (!fancy_memcmp(rdbuf, ctx->printer->done_c_readback, READBACK_LEN)) {
state = S_PRINTER_DONE;
}
break;
case S_PRINTER_DONE:
if (ctx->printer->foot_length) {
INFO("Cleaning up\n");
if ((ret = send_data(ctx->dev, ctx->endp_down, ctx->footer, ctx->printer->foot_length)))
return ret;
}
state = S_FINISHED;
/* Intentional Fallthrough */
case S_FINISHED:
INFO("All data sent to printer!\n");
break;
}
if (state != S_FINISHED)
goto top;
2012-10-26 22:06:47 -04:00
/* Clean up */
if (terminate)
copies = 1;
INFO("Print complete (%d copies remaining)\n", copies - 1);
if (copies && --copies) {
state = S_IDLE;
goto top;
}
return 0;
2012-10-26 22:06:47 -04:00
}
/* Exported */
#define USB_VID_CANON 0x04a9
#define USB_PID_CANON_CP10 0x304A
#define USB_PID_CANON_CP100 0x3063
#define USB_PID_CANON_CP200 0x307C
#define USB_PID_CANON_CP220 0x30BD
#define USB_PID_CANON_CP300 0x307D
#define USB_PID_CANON_CP330 0x30BE
#define USB_PID_CANON_CP400 0x30F6
#define USB_PID_CANON_CP500 0x30F5
#define USB_PID_CANON_CP510 0x3128
#define USB_PID_CANON_CP520 520 // XXX 316f? 3172? (related to cp740/cp750)
#define USB_PID_CANON_CP530 0x31b1
#define USB_PID_CANON_CP600 0x310B
#define USB_PID_CANON_CP710 0x3127
#define USB_PID_CANON_CP720 0x3143
#define USB_PID_CANON_CP730 0x3142
#define USB_PID_CANON_CP740 0x3171
#define USB_PID_CANON_CP750 0x3170
#define USB_PID_CANON_CP760 0x31AB
#define USB_PID_CANON_CP770 0x31AA
#define USB_PID_CANON_CP780 0x31DD
#define USB_PID_CANON_CP790 0x31E7
#define USB_PID_CANON_CP800 0x3214
#define USB_PID_CANON_CP810 0x3256
#define USB_PID_CANON_CP900 0x3255
#define USB_PID_CANON_ES1 0x3141
#define USB_PID_CANON_ES2 0x3185
#define USB_PID_CANON_ES20 0x3186
#define USB_PID_CANON_ES3 0x31AF
#define USB_PID_CANON_ES30 0x31B0
#define USB_PID_CANON_ES40 0x31EE
struct dyesub_backend canonselphy_backend = {
.name = "Canon SELPHY CP/ES",
.version = "0.71",
.multipage_capable = 1,
.uri_prefix = "canonselphy",
.init = canonselphy_init,
.attach = canonselphy_attach,
.teardown = canonselphy_teardown,
.early_parse = canonselphy_early_parse,
.read_parse = canonselphy_read_parse,
.main_loop = canonselphy_main_loop,
.devices = {
{ USB_VID_CANON, USB_PID_CANON_CP10, P_CP10, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP100, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP200, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP220, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP300, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP330, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP400, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP500, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP510, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP520, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP530, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP600, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP710, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP720, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP730, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP740, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP750, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP760, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP770, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP780, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP790, P_ES40_CP790, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP800, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP810, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_CP900, P_CP_XXX, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_ES1, P_ES1, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_ES2, P_ES2_20, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_ES20, P_ES2_20, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_ES3, P_ES3_30, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_ES30, P_ES3_30, "Canon"},
{ USB_VID_CANON, USB_PID_CANON_ES40, P_ES40_CP790, "Canon"},
{ 0, 0, 0, ""}
}
};
/*
***************************