2012-10-26 22:06:47 -04:00
|
|
|
/*
|
2013-07-18 23:00:58 -04:00
|
|
|
* Canon SELPHY ES/CP series CUPS backend -- libusb-1.0 version
|
2012-10-26 22:06:47 -04:00
|
|
|
*
|
2018-02-22 06:02:49 -05:00
|
|
|
* (c) 2007-2018 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
|
|
|
*
|
2013-08-20 20:10:21 -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]
|
|
|
|
*
|
2017-11-17 13:34:26 -05:00
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
*
|
2012-10-26 22:06:47 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-10-26 23:21:33 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2013-05-02 20:27:32 -04:00
|
|
|
#include <signal.h>
|
2012-10-26 23:21:33 -04:00
|
|
|
|
2015-08-13 21:09:56 -04:00
|
|
|
#define BACKEND canonselphy_backend
|
|
|
|
|
2013-07-18 23:00:58 -04:00
|
|
|
#include "backend_common.h"
|
2013-06-27 23:02:34 -04:00
|
|
|
|
2015-08-12 22:56:29 -04:00
|
|
|
#define P_ES40_CP790 (P_END + 1) // used for detection only
|
|
|
|
|
2014-02-18 23:33:33 -05: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
|
2014-05-18 18:31:32 -04:00
|
|
|
#define USB_PID_CANON_CP520 0x3172
|
2014-02-18 23:33:33 -05:00
|
|
|
#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
|
|
|
|
|
2013-05-02 20:34:01 -04:00
|
|
|
#define READBACK_LEN 12
|
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
struct printer_data; /* Forward declaration */
|
|
|
|
|
2013-05-02 20:34:01 -04:00
|
|
|
struct printer_data {
|
|
|
|
int type; /* P_??? */
|
|
|
|
char *model; /* eg "SELPHY ES1" */
|
2018-04-06 08:18:29 -04:00
|
|
|
uint16_t init_length;
|
|
|
|
uint16_t foot_length;
|
2013-05-02 20:34:01 -04:00
|
|
|
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];
|
2014-01-31 09:38:53 -05:00
|
|
|
uint8_t clear_error[READBACK_LEN];
|
2018-04-06 08:18:29 -04:00
|
|
|
uint8_t clear_error_len;
|
2013-05-02 20:34:01 -04:00
|
|
|
int16_t paper_codes[256];
|
2018-04-06 08:18:29 -04:00
|
|
|
int8_t pgcode_offset; /* Offset into printjob for paper type */
|
|
|
|
int8_t paper_code_offset; /* Offset in readback for paper type */
|
|
|
|
int8_t paper_code_offset2; /* Offset in readback for paper type (2nd) */
|
|
|
|
uint8_t (*error_detect)(uint8_t *rdbuf);
|
|
|
|
char *(*pgcode_names)(uint8_t *rdbuf, struct printer_data *printer);
|
2013-05-02 20:34:01 -04:00
|
|
|
};
|
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
static char *generic_pgcode_names(uint8_t *rdbuf, struct printer_data *printer)
|
2016-08-19 17:40:12 -04:00
|
|
|
{
|
2018-04-06 08:18:29 -04:00
|
|
|
uint8_t pgcode = 0, pgcode2 = 0;
|
|
|
|
|
|
|
|
if (printer->paper_code_offset != -1)
|
|
|
|
pgcode = rdbuf[printer->paper_code_offset];
|
|
|
|
if (printer->paper_code_offset2 != -1)
|
|
|
|
pgcode2 = rdbuf[printer->paper_code_offset2];
|
|
|
|
|
2016-08-19 17:40:12 -04:00
|
|
|
switch(pgcode & 0xf) {
|
|
|
|
case 0x01: return "P";
|
|
|
|
case 0x02: return "L";
|
2018-04-06 08:18:29 -04:00
|
|
|
case 0x03: return pgcode2 ? "Cl" : "C";
|
2016-08-19 17:40:12 -04:00
|
|
|
case 0x04: return "W";
|
|
|
|
case 0x0f: return "None";
|
|
|
|
default: return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
static uint8_t es1_error_detect(uint8_t *rdbuf)
|
2014-01-29 10:22:20 -05:00
|
|
|
{
|
2014-01-29 21:26:59 -05:00
|
|
|
if (rdbuf[1] == 0x01) {
|
|
|
|
if (rdbuf[9] == 0x00) {
|
|
|
|
ERROR("Cover open!\n");
|
|
|
|
} else {
|
2014-01-29 21:31:26 -05:00
|
|
|
ERROR("Unknown error %02x\n", rdbuf[9]);
|
2014-01-29 21:26:59 -05:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} else if (rdbuf[4] == 0x01 && rdbuf[5] == 0xff &&
|
|
|
|
rdbuf[6] == 0xff && rdbuf[7] == 0xff) {
|
2016-08-19 17:40:12 -04:00
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-29 10:22:20 -05:00
|
|
|
ERROR("No media loaded!\n");
|
2014-01-29 21:26:59 -05:00
|
|
|
return 1;
|
2014-01-29 22:11:32 -05:00
|
|
|
} else if (rdbuf[0] == 0x0f) {
|
2016-08-19 17:40:12 -04:00
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-29 22:11:32 -05:00
|
|
|
ERROR("Out of media!\n");
|
|
|
|
return 1;
|
2014-01-29 21:26:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-01-29 10:22:20 -05:00
|
|
|
}
|
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
static uint8_t es2_error_detect(uint8_t *rdbuf)
|
2014-01-29 10:22:20 -05:00
|
|
|
{
|
|
|
|
if (rdbuf[0] == 0x16 &&
|
|
|
|
rdbuf[1] == 0x01) {
|
2014-01-30 20:00:21 -05:00
|
|
|
ERROR("Printer cover open!\n");
|
2014-01-29 10:22:20 -05:00
|
|
|
return 1;
|
|
|
|
}
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2014-01-29 10:22:20 -05:00
|
|
|
if (rdbuf[0] == 0x02 &&
|
|
|
|
rdbuf[4] == 0x05 &&
|
|
|
|
rdbuf[5] == 0x05 &&
|
|
|
|
rdbuf[6] == 0x02) {
|
2016-08-19 17:40:12 -04:00
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-29 10:22:20 -05:00
|
|
|
ERROR("No media loaded!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-01-29 21:31:26 -05:00
|
|
|
if (rdbuf[0] == 0x14) {
|
2016-08-19 17:40:12 -04:00
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-29 21:31:26 -05:00
|
|
|
ERROR("Out of media!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-01-29 10:22:20 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
static uint8_t es3_error_detect(uint8_t *rdbuf)
|
2014-01-29 10:22:20 -05:00
|
|
|
{
|
|
|
|
if (rdbuf[8] == 0x01) {
|
|
|
|
if (rdbuf[10] == 0x0f) {
|
|
|
|
ERROR("Communications Error\n");
|
|
|
|
} else if (rdbuf[10] == 0x01) {
|
2016-08-19 17:40:12 -04:00
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-30 20:00:21 -05:00
|
|
|
ERROR("No media loaded!\n");
|
2014-01-29 10:22:20 -05:00
|
|
|
} else {
|
2017-07-10 20:15:56 -04:00
|
|
|
ERROR("Unknown error - %02x + %02x\n",
|
2014-01-29 10:22:20 -05:00
|
|
|
rdbuf[8], rdbuf[10]);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} else if (rdbuf[8] == 0x03 &&
|
|
|
|
rdbuf[10] == 0x02) {
|
2017-07-10 20:15:56 -04:00
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-30 20:00:21 -05:00
|
|
|
ERROR("No media loaded!\n");
|
2014-01-29 10:22:20 -05:00
|
|
|
return 1;
|
|
|
|
} else if (rdbuf[8] == 0x08 &&
|
|
|
|
rdbuf[10] == 0x04) {
|
2014-01-30 20:00:21 -05:00
|
|
|
ERROR("Printer cover open!\n");
|
2014-01-29 10:22:20 -05:00
|
|
|
return 1;
|
2014-01-29 21:36:17 -05:00
|
|
|
} else if (rdbuf[8] == 0x05 &&
|
|
|
|
rdbuf[10] == 0x01) {
|
2014-01-30 20:00:21 -05:00
|
|
|
ERROR("Incorrect media loaded!\n");
|
2014-01-29 21:36:17 -05:00
|
|
|
return 1;
|
2014-01-29 10:22:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rdbuf[8] || rdbuf[10]) {
|
2017-07-10 20:15:56 -04:00
|
|
|
ERROR("Unknown error - %02x + %02x\n",
|
2014-01-29 21:31:26 -05:00
|
|
|
rdbuf[8], rdbuf[10]);
|
2014-01-29 21:36:17 -05:00
|
|
|
return 1;
|
2014-01-29 10:22:20 -05:00
|
|
|
}
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2014-01-29 10:22:20 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
static uint8_t es40_error_detect(uint8_t *rdbuf)
|
2014-01-29 10:22:20 -05:00
|
|
|
{
|
2014-02-08 14:45:55 -05:00
|
|
|
/* ES40 */
|
|
|
|
if (!rdbuf[3])
|
|
|
|
return 0;
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2014-02-08 14:45:55 -05:00
|
|
|
if (rdbuf[3] == 0x01)
|
|
|
|
ERROR("Generic communication error\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
else if (rdbuf[3] == 0x32) {
|
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-02-08 14:45:55 -05:00
|
|
|
ERROR("Cover open or media empty!\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
} else
|
2014-02-08 14:45:55 -05:00
|
|
|
ERROR("Unknown error - %02x\n", rdbuf[3]);
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2014-02-08 14:45:55 -05:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2014-01-30 08:50:08 -05:00
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
static uint8_t cp790_error_detect(uint8_t *rdbuf)
|
2014-02-08 14:45:55 -05:00
|
|
|
{
|
2014-01-29 10:22:20 -05:00
|
|
|
/* CP790 */
|
2014-02-10 21:50:05 -05:00
|
|
|
if (rdbuf[5] == 0xff) {
|
2014-01-30 20:00:21 -05:00
|
|
|
ERROR("No ribbon loaded!\n");
|
2014-01-29 10:22:20 -05:00
|
|
|
return 1;
|
2014-02-10 21:50:05 -05:00
|
|
|
} else if (rdbuf[4] == 0xff) {
|
2014-02-08 13:59:24 -05:00
|
|
|
ERROR("No paper tray loaded!\n");
|
2014-01-29 10:22:20 -05:00
|
|
|
return 1;
|
2014-02-04 07:44:19 -05:00
|
|
|
} else if (rdbuf[3]) {
|
2016-08-19 17:40:12 -04:00
|
|
|
if ((rdbuf[3] & 0xf) == 0x02) { // 0x12 0x22
|
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-02-10 21:50:05 -05:00
|
|
|
ERROR("No paper tray loaded!\n");
|
2017-07-10 20:15:56 -04:00
|
|
|
} else if ((rdbuf[3] & 0xf) == 0x03) { // 0x13 0x23
|
2016-08-19 17:40:12 -04:00
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-02-10 21:50:05 -05:00
|
|
|
ERROR("Empty paper tray or feed error!\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
} else if (rdbuf[3] == 0x11)
|
2014-02-10 21:50:05 -05:00
|
|
|
ERROR("Paper feed error!\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
else if (rdbuf[3] == 0x21) {
|
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-02-10 21:50:05 -05:00
|
|
|
ERROR("Ribbon depleted!\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
} else
|
2014-02-10 21:50:05 -05:00
|
|
|
ERROR("Unknown error - %02x\n", rdbuf[3]);
|
2014-02-04 07:44:19 -05:00
|
|
|
return 1;
|
2014-01-29 10:22:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
static char *cp10_pgcode_names(uint8_t *rdbuf, struct printer_data *printer)
|
2016-08-19 17:40:12 -04:00
|
|
|
{
|
2018-04-06 08:18:29 -04:00
|
|
|
UNUSED(rdbuf);
|
|
|
|
UNUSED(printer);
|
|
|
|
|
|
|
|
return "C"; /* Printer only supports one media type */
|
2016-08-19 17:40:12 -04:00
|
|
|
}
|
2014-02-08 14:45:55 -05:00
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
static uint8_t cp10_error_detect(uint8_t *rdbuf)
|
2014-01-29 10:22:20 -05:00
|
|
|
{
|
|
|
|
if (!rdbuf[2])
|
|
|
|
return 0;
|
|
|
|
|
2016-08-19 17:40:12 -04:00
|
|
|
if (rdbuf[2] == 0x80) {
|
2017-07-10 20:15:56 -04:00
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-30 20:00:21 -05:00
|
|
|
ERROR("No ribbon loaded\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
} else if (rdbuf[2] == 0x08) {
|
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-02-04 07:44:19 -05:00
|
|
|
ERROR("Ribbon depleted!\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
} else if (rdbuf[2] == 0x01) {
|
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-30 20:00:21 -05:00
|
|
|
ERROR("No paper loaded!\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
} else
|
2014-01-29 10:22:20 -05:00
|
|
|
ERROR("Unknown error - %02x\n", rdbuf[2]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
static uint8_t cpxxx_error_detect(uint8_t *rdbuf)
|
2014-01-29 10:22:20 -05:00
|
|
|
{
|
|
|
|
if (!rdbuf[2])
|
|
|
|
return 0;
|
|
|
|
|
2016-08-19 17:40:12 -04:00
|
|
|
if (rdbuf[2] == 0x01) {
|
2017-07-10 20:15:56 -04:00
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-30 20:00:21 -05:00
|
|
|
ERROR("Paper feed problem!\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
} else if (rdbuf[2] == 0x04)
|
2014-01-29 10:22:20 -05:00
|
|
|
ERROR("Ribbon problem!\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
else if (rdbuf[2] == 0x08) {
|
|
|
|
ATTR("marker-levels=%d\n", 0);
|
2014-01-29 10:22:20 -05:00
|
|
|
ERROR("Ribbon depleted!\n");
|
2016-08-19 17:40:12 -04:00
|
|
|
} else
|
2014-01-29 10:22:20 -05:00
|
|
|
ERROR("Unknown error - %02x\n", rdbuf[2]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-07-18 23:00:58 -04:00
|
|
|
static struct printer_data selphy_printers[] = {
|
2013-05-02 20:34:01 -04:00
|
|
|
{ .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 },
|
2014-03-05 09:43:01 -05:00
|
|
|
.clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
.clear_error_len = 12,
|
2013-05-02 20:34:01 -04:00
|
|
|
.pgcode_offset = 3,
|
|
|
|
.paper_code_offset = 6,
|
2018-04-06 08:18:29 -04:00
|
|
|
.paper_code_offset2 = -1,
|
2014-01-29 10:22:20 -05:00
|
|
|
.error_detect = es1_error_detect,
|
2016-08-19 17:40:12 -04:00
|
|
|
.pgcode_names = generic_pgcode_names,
|
2013-05-02 20:34:01 -04:00
|
|
|
},
|
|
|
|
{ .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 },
|
2014-03-05 09:43:01 -05:00
|
|
|
.clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
.clear_error_len = 12,
|
2013-05-02 20:34:01 -04:00
|
|
|
.pgcode_offset = 2,
|
|
|
|
.paper_code_offset = 4,
|
2018-04-06 08:18:29 -04:00
|
|
|
.paper_code_offset2 = 6,
|
2014-01-29 10:22:20 -05:00
|
|
|
.error_detect = es2_error_detect,
|
2016-08-19 17:40:12 -04:00
|
|
|
.pgcode_names = generic_pgcode_names,
|
2013-05-02 20:34:01 -04:00
|
|
|
},
|
|
|
|
{ .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 },
|
2014-03-05 09:43:01 -05:00
|
|
|
.clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
.clear_error_len = 12,
|
2013-05-02 20:34:01 -04:00
|
|
|
.pgcode_offset = 2,
|
|
|
|
.paper_code_offset = -1,
|
2018-04-06 08:18:29 -04:00
|
|
|
.paper_code_offset2 = -1,
|
2014-01-29 10:22:20 -05:00
|
|
|
.error_detect = es3_error_detect,
|
2016-08-19 17:40:12 -04:00
|
|
|
.pgcode_names = NULL,
|
2013-05-02 20:34:01 -04:00
|
|
|
},
|
2014-02-08 14:45:55 -05:00
|
|
|
{ .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 },
|
2014-03-05 09:43:01 -05:00
|
|
|
.clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
.clear_error_len = 12,
|
2013-05-02 20:34:01 -04:00
|
|
|
.pgcode_offset = 2,
|
2014-02-08 14:45:55 -05:00
|
|
|
.paper_code_offset = 11,
|
2018-04-06 08:18:29 -04:00
|
|
|
.paper_code_offset2 = -1,
|
2014-01-29 10:22:20 -05:00
|
|
|
.error_detect = es40_error_detect,
|
2016-08-19 17:40:12 -04:00
|
|
|
.pgcode_names = generic_pgcode_names,
|
2013-05-02 20:34:01 -04:00
|
|
|
},
|
2014-02-08 14:45:55 -05:00
|
|
|
{ .type = P_CP790,
|
|
|
|
.model = "SELPHY CP790",
|
|
|
|
.init_length = 16,
|
|
|
|
.foot_length = 12,
|
2014-02-10 21:50:05 -05:00
|
|
|
.init_readback = { 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
|
|
|
|
.ready_y_readback = { 0x00, 0x01, 0x01, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
|
|
|
|
.ready_m_readback = { 0x00, 0x03, 0x02, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
|
|
|
|
.ready_c_readback = { 0x00, 0x05, 0x03, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
|
|
|
|
.done_c_readback = { 0x00, 0x00, 0x10, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
|
|
|
|
.clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
.clear_error_len = 12,
|
2014-02-08 14:45:55 -05:00
|
|
|
.pgcode_offset = 2,
|
2014-02-10 21:50:05 -05:00
|
|
|
.paper_code_offset = -1, /* Uses a different technique */
|
2018-04-06 08:18:29 -04:00
|
|
|
.paper_code_offset2 = -1,
|
2014-02-08 14:45:55 -05:00
|
|
|
.error_detect = cp790_error_detect,
|
2017-07-10 20:15:56 -04:00
|
|
|
.pgcode_names = generic_pgcode_names,
|
2014-02-08 14:45:55 -05:00
|
|
|
},
|
2013-05-02 20:34:01 -04:00
|
|
|
{ .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 */
|
2017-04-11 14:03:35 -04:00
|
|
|
.init_readback = { 0x01, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 },
|
|
|
|
.ready_y_readback = { 0x02, 0x00, 0x00, 0x00, 0x70, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 },
|
|
|
|
.ready_m_readback = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 },
|
|
|
|
.ready_c_readback = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 },
|
|
|
|
.done_c_readback = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 },
|
2013-05-03 07:24:58 -04:00
|
|
|
.clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
2014-01-31 13:23:04 -05:00
|
|
|
.clear_error_len = 12,
|
2013-05-02 20:34:01 -04:00
|
|
|
.pgcode_offset = 3,
|
|
|
|
.paper_code_offset = 6,
|
2018-04-06 08:18:29 -04:00
|
|
|
.paper_code_offset2 = -1,
|
2014-01-29 10:22:20 -05:00
|
|
|
.error_detect = cpxxx_error_detect,
|
2017-07-10 20:15:56 -04:00
|
|
|
.pgcode_names = generic_pgcode_names,
|
2013-05-02 20:34:01 -04:00
|
|
|
},
|
|
|
|
{ .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 },
|
2014-02-03 20:12:00 -05:00
|
|
|
.clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
.clear_error_len = 12,
|
2016-08-19 17:40:12 -04:00
|
|
|
.pgcode_offset = 2,
|
2013-05-02 20:34:01 -04:00
|
|
|
.paper_code_offset = -1,
|
2018-04-06 08:18:29 -04:00
|
|
|
.paper_code_offset2 = -1,
|
2014-01-29 10:22:20 -05:00
|
|
|
.error_detect = cp10_error_detect,
|
2017-07-10 20:15:56 -04:00
|
|
|
.pgcode_names = cp10_pgcode_names,
|
2013-05-02 20:34:01 -04:00
|
|
|
},
|
2013-07-18 23:00:58 -04:00
|
|
|
{ .type = -1 },
|
2013-05-02 20:34:01 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_HEADER 28
|
|
|
|
|
2013-07-26 16:18:35 -04:00
|
|
|
static const uint32_t es40_cp790_plane_lengths[4] = { 2227456, 1601600, 698880, 2976512 };
|
2013-05-02 20:34:01 -04:00
|
|
|
|
|
|
|
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 */
|
2017-07-10 20:15:56 -04:00
|
|
|
for (j = 0 ; j < 256 ; j++)
|
2013-07-18 23:00:58 -04:00
|
|
|
selphy_printers[i].paper_codes[j] = -1;
|
2013-05-02 20:34:01 -04:00
|
|
|
|
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;
|
2014-02-10 21:50:05 -05:00
|
|
|
selphy_printers[i].paper_codes[0x12] = 0x02;
|
2013-07-18 23:12:25 -04:00
|
|
|
selphy_printers[i].paper_codes[0x13] = 0x03;
|
|
|
|
break;
|
|
|
|
case P_ES2_20:
|
|
|
|
selphy_printers[i].paper_codes[0x01] = 0x01;
|
2014-02-10 21:50:05 -05:00
|
|
|
selphy_printers[i].paper_codes[0x02] = 0x02;
|
2013-07-18 23:12:25 -04:00
|
|
|
selphy_printers[i].paper_codes[0x03] = 0x03;
|
|
|
|
break;
|
2014-02-08 14:45:55 -05:00
|
|
|
case P_ES40:
|
2013-07-18 23:12:25 -04:00
|
|
|
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;
|
2014-02-10 21:50:05 -05:00
|
|
|
case P_ES3_30:
|
|
|
|
/* N/A, printer does not report types */
|
|
|
|
case P_CP790:
|
|
|
|
/* N/A, printer uses different technique */
|
2013-07-18 23:12:25 -04:00
|
|
|
case P_CP10:
|
|
|
|
/* N/A, printer supports one type only */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-02 20:34:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#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,
|
2014-06-25 11:51:00 -04:00
|
|
|
S_PRINTER_CP900_FOOTER,
|
2013-05-02 20:34:01 -04:00
|
|
|
S_PRINTER_DONE,
|
|
|
|
S_FINISHED,
|
|
|
|
};
|
|
|
|
|
2017-07-10 20:15:56 -04:00
|
|
|
static int fancy_memcmp(const uint8_t *buf_a, const int16_t *buf_b, uint len)
|
2012-12-11 19:52:03 -05:00
|
|
|
{
|
2013-07-26 16:18:35 -04:00
|
|
|
uint i;
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2012-12-11 19:52:03 -05:00
|
|
|
for (i = 0 ; i < len ; i++) {
|
2014-01-29 10:22:20 -05:00
|
|
|
if (buf_b[i] == -1)
|
2012-12-11 19:52:03 -05:00
|
|
|
continue;
|
|
|
|
else if (buf_a[i] > buf_b[i])
|
|
|
|
return 1;
|
|
|
|
else if (buf_a[i] < buf_b[i])
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-10 20:15:56 -04:00
|
|
|
static int parse_printjob(uint8_t *buffer, uint8_t *bw_mode, uint32_t *plane_len)
|
2012-12-11 19:52:03 -05:00
|
|
|
{
|
|
|
|
int printer_type = -1;
|
|
|
|
|
|
|
|
if (buffer[0] != 0x40 &&
|
|
|
|
buffer[1] != 0x00) {
|
|
|
|
goto done;
|
|
|
|
}
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2012-12-11 19:52:03 -05:00
|
|
|
if (buffer[12] == 0x40 &&
|
|
|
|
buffer[13] == 0x01) {
|
2013-01-29 17:51:43 -05:00
|
|
|
*plane_len = *(uint32_t*)(&buffer[16]);
|
|
|
|
*plane_len = le32_to_cpu(*plane_len);
|
|
|
|
|
2012-12-11 19:52:03 -05:00
|
|
|
if (buffer[2] == 0x00) {
|
2013-01-29 17:51:43 -05:00
|
|
|
if (*plane_len == 688480)
|
2012-12-12 19:00:45 -05:00
|
|
|
printer_type = P_CP10;
|
|
|
|
else
|
|
|
|
printer_type = P_CP_XXX;
|
2012-12-11 19:52:03 -05:00
|
|
|
} 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;
|
|
|
|
}
|
2014-01-27 14:09:23 -05:00
|
|
|
|
2012-12-11 19:52:03 -05:00
|
|
|
if (es40_cp790_plane_lengths[buffer[2]] == *plane_len) {
|
2014-01-27 14:09:23 -05:00
|
|
|
printer_type = P_ES40_CP790;
|
2012-12-11 19:52:03 -05:00
|
|
|
*bw_mode = (buffer[3] == 0x01);
|
|
|
|
goto done;
|
|
|
|
} else {
|
2014-01-27 14:09:23 -05:00
|
|
|
printer_type = P_ES3_30;
|
2012-12-11 19:52:03 -05:00
|
|
|
*bw_mode = (buffer[3] == 0x01);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2013-07-19 07:52:21 -04:00
|
|
|
return printer_type;
|
2012-12-11 19:52:03 -05:00
|
|
|
}
|
|
|
|
|
2017-05-05 08:06:28 -04:00
|
|
|
/* Private data structure */
|
2013-07-18 23:00:58 -04:00
|
|
|
struct canonselphy_ctx {
|
2012-11-06 22:20:42 -05:00
|
|
|
struct libusb_device_handle *dev;
|
2013-07-18 23:00:58 -04:00
|
|
|
uint8_t endp_up;
|
|
|
|
uint8_t endp_down;
|
2015-08-12 22:56:29 -04:00
|
|
|
int type;
|
2012-11-06 22:20:42 -05:00
|
|
|
|
2013-07-18 23:00:58 -04:00
|
|
|
struct printer_data *printer;
|
2012-11-06 22:20:42 -05:00
|
|
|
|
2013-07-18 23:00:58 -04:00
|
|
|
uint8_t bw_mode;
|
2012-11-06 22:20:42 -05:00
|
|
|
|
2013-07-18 23:00:58 -04:00
|
|
|
int16_t paper_code;
|
2012-11-06 22:20:42 -05:00
|
|
|
|
2013-07-18 23:00:58 -04:00
|
|
|
uint32_t plane_len;
|
2012-11-06 22:20:42 -05:00
|
|
|
|
2013-07-18 23:00:58 -04:00
|
|
|
uint8_t *header;
|
|
|
|
uint8_t *plane_y;
|
|
|
|
uint8_t *plane_m;
|
|
|
|
uint8_t *plane_c;
|
|
|
|
uint8_t *footer;
|
2013-07-19 10:15:27 -04:00
|
|
|
|
|
|
|
uint8_t *buffer;
|
2014-06-25 11:51:00 -04:00
|
|
|
|
|
|
|
uint8_t cp900;
|
2013-07-18 23:00:58 -04:00
|
|
|
};
|
2012-11-06 22:20:42 -05:00
|
|
|
|
2018-01-04 10:00:57 -05:00
|
|
|
static int canonselphy_get_status(struct canonselphy_ctx *ctx)
|
|
|
|
{
|
|
|
|
uint8_t rdbuf[READBACK_LEN];
|
|
|
|
int ret, num;
|
|
|
|
|
2018-04-05 19:52:53 -04:00
|
|
|
/* Read in the printer status, twice. */
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
(uint8_t*) rdbuf, READBACK_LEN, &num);
|
2018-01-04 10:00:57 -05:00
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
(uint8_t*) rdbuf, READBACK_LEN, &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2018-04-06 08:18:29 -04:00
|
|
|
INFO("Media type: %s\n", ctx->printer->pgcode_names? ctx->printer->pgcode_names(rdbuf, ctx->printer) : "Unknown");
|
2018-01-04 10:00:57 -05:00
|
|
|
ctx->printer->error_detect(rdbuf);
|
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-09 21:24:19 -05:00
|
|
|
static int canonselphy_send_reset(struct canonselphy_ctx *ctx)
|
|
|
|
{
|
|
|
|
uint8_t rstcmd[12] = { 0x40, 0x10, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00 };
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
rstcmd, sizeof(rstcmd))))
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-19 09:23:53 -04:00
|
|
|
static void *canonselphy_init(void)
|
2013-07-18 23:00:58 -04:00
|
|
|
{
|
|
|
|
struct canonselphy_ctx *ctx = malloc(sizeof(struct canonselphy_ctx));
|
2015-06-23 20:32:41 -04:00
|
|
|
if (!ctx) {
|
|
|
|
ERROR("Memory Allocation Failure!\n");
|
2013-07-18 23:00:58 -04:00
|
|
|