2016-12-02 23:49:22 -05:00
|
|
|
/*
|
|
|
|
* Canon SELPHY CPneo series CUPS backend -- libusb-1.0 version
|
|
|
|
*
|
2020-06-30 23:42:54 -04:00
|
|
|
* (c) 2016-2020 Solomon Peachy <pizza@shaftnet.org>
|
2016-12-02 23:49:22 -05:00
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
|
|
|
*
|
2021-01-23 10:47:01 -05:00
|
|
|
* https://git.shaftnet.org/cgit/selphy_print.git
|
2016-12-02 23:49:22 -05: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
|
2020-01-17 16:50:56 -05:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2016-12-02 23:49:22 -05:00
|
|
|
*
|
2017-11-17 13:34:26 -05:00
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
*
|
2016-12-02 23:49:22 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define BACKEND canonselphyneo_backend
|
|
|
|
|
|
|
|
#include "backend_common.h"
|
|
|
|
|
|
|
|
/* Exported */
|
|
|
|
#define USB_VID_CANON 0x04a9
|
2017-03-26 23:15:35 -04:00
|
|
|
#define USB_PID_CANON_CP820 0x327b
|
2016-12-02 23:49:22 -05:00
|
|
|
#define USB_PID_CANON_CP910 0x327a
|
2016-12-28 11:38:02 -05:00
|
|
|
#define USB_PID_CANON_CP1000 0x32ae
|
2016-12-02 23:49:22 -05:00
|
|
|
#define USB_PID_CANON_CP1200 0x32b1
|
2018-01-27 18:16:36 -05:00
|
|
|
#define USB_PID_CANON_CP1300 0x32db
|
2016-12-02 23:49:22 -05:00
|
|
|
|
|
|
|
/* Header data structure */
|
|
|
|
struct selphyneo_hdr {
|
2016-12-09 11:02:44 -05:00
|
|
|
uint8_t data[24];
|
|
|
|
uint32_t cols; /* LE */
|
|
|
|
uint32_t rows; /* LE */
|
2016-12-02 23:49:22 -05:00
|
|
|
} __attribute((packed));
|
|
|
|
|
|
|
|
/* Readback data structure */
|
|
|
|
struct selphyneo_readback {
|
|
|
|
uint8_t data[12];
|
|
|
|
} __attribute((packed));
|
|
|
|
|
2017-05-05 08:06:28 -04:00
|
|
|
/* Private data structure */
|
2018-06-15 14:55:03 -04:00
|
|
|
struct selphyneo_printjob {
|
|
|
|
uint8_t *databuf;
|
|
|
|
uint32_t datalen;
|
|
|
|
|
|
|
|
int copies;
|
|
|
|
};
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
struct selphyneo_ctx {
|
2020-08-11 20:27:26 -04:00
|
|
|
struct dyesub_connection *conn;
|
2016-12-02 23:49:22 -05:00
|
|
|
|
2018-04-27 15:40:09 -04:00
|
|
|
struct marker marker;
|
2016-12-02 23:49:22 -05:00
|
|
|
};
|
|
|
|
|
2020-03-24 18:22:39 -04:00
|
|
|
static const char *selphyneo_statuses(uint8_t sts)
|
2016-12-02 23:49:22 -05:00
|
|
|
{
|
|
|
|
switch(sts) {
|
|
|
|
case 0x01:
|
|
|
|
return "Idle";
|
|
|
|
case 0x02:
|
|
|
|
return "Feeding Paper";
|
|
|
|
case 0x04:
|
|
|
|
return "Printing YELLOW";
|
|
|
|
case 0x08:
|
|
|
|
return "Printing MAGENTA";
|
|
|
|
case 0x10:
|
|
|
|
return "Printing CYAN";
|
|
|
|
case 0x20:
|
|
|
|
return "Printing LAMINATE";
|
|
|
|
default:
|
|
|
|
return "Unknown state!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 18:22:39 -04:00
|
|
|
static const char *selphyneo_errors(uint8_t err)
|
2016-12-02 23:49:22 -05:00
|
|
|
{
|
|
|
|
switch(err) {
|
|
|
|
case 0x00:
|
|
|
|
return "None";
|
|
|
|
case 0x02:
|
|
|
|
return "Paper Feed";
|
|
|
|
case 0x03:
|
|
|
|
return "No Paper";
|
2017-11-12 19:42:33 -05:00
|
|
|
case 0x05:
|
|
|
|
return "Incorrect Paper loaded";
|
2017-04-20 21:43:22 -04:00
|
|
|
case 0x06:
|
|
|
|
return "Ink Cassette Empty";
|
2016-12-02 23:49:22 -05:00
|
|
|
case 0x07:
|
|
|
|
return "No Ink";
|
2016-12-10 22:43:20 -05:00
|
|
|
case 0x09:
|
|
|
|
return "No Paper and Ink";
|
2016-12-02 23:49:22 -05:00
|
|
|
case 0x0A:
|
|
|
|
return "Incorrect media for job";
|
2017-11-12 19:42:33 -05:00
|
|
|
case 0x0B:
|
|
|
|
return "Paper jam";
|
2016-12-02 23:49:22 -05:00
|
|
|
default:
|
|
|
|
return "Unknown Error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 18:22:39 -04:00
|
|
|
static const char *selphynew_pgcodes(uint8_t type) {
|
2016-12-10 22:43:20 -05:00
|
|
|
|
|
|
|
switch (type & 0xf) {
|
|
|
|
case 0x01:
|
|
|
|
return "P";
|
|
|
|
case 0x02:
|
|
|
|
return "L";
|
|
|
|
case 0x03:
|
|
|
|
return "C";
|
|
|
|
case 0x00:
|
|
|
|
return "None";
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 21:24:19 -05:00
|
|
|
static int selphyneo_send_reset(struct selphyneo_ctx *ctx)
|
|
|
|
{
|
|
|
|
uint8_t rstcmd[12] = { 0x40, 0x10, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00 };
|
|
|
|
int ret;
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2016-12-09 21:24:19 -05:00
|
|
|
rstcmd, sizeof(rstcmd))))
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:00:57 -05:00
|
|
|
static int selphyneo_get_status(struct selphyneo_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct selphyneo_readback rdback;
|
|
|
|
int ret, num;
|
|
|
|
|
|
|
|
/* Read in the printer status to clear last state */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2018-01-04 10:00:57 -05:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
/* And again, for the markers */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2018-01-04 10:00:57 -05:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
INFO("Printer state: %s\n", selphyneo_statuses(rdback.data[0]));
|
|
|
|
INFO("Media type: %s\n", selphynew_pgcodes(rdback.data[6]));
|
|
|
|
if (rdback.data[2]) {
|
|
|
|
INFO("Printer error: %s\n", selphyneo_errors(rdback.data[2]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
static void *selphyneo_init(void)
|
|
|
|
{
|
|
|
|
struct selphyneo_ctx *ctx = malloc(sizeof(struct selphyneo_ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
ERROR("Memory Allocation Failure!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memset(ctx, 0, sizeof(struct selphyneo_ctx));
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
static int selphyneo_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
|
2016-12-02 23:49:22 -05:00
|
|
|
{
|
|
|
|
struct selphyneo_ctx *ctx = vctx;
|
2018-04-27 15:40:09 -04:00
|
|
|
struct selphyneo_readback rdback;
|
|
|
|
int ret, num;
|
2016-12-02 23:49:22 -05:00
|
|
|
|
|
|
|
UNUSED(jobid);
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
ctx->conn = conn;
|
2016-12-02 23:49:22 -05:00
|
|
|
|
2018-05-12 21:40:29 -04:00
|
|
|
if (test_mode < TEST_MODE_NOATTACH) {
|
|
|
|
/* Read in the printer status to clear last state */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2018-05-12 21:40:29 -04:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
2018-04-27 15:07:43 -04:00
|
|
|
|
2018-05-12 21:40:29 -04:00
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
2018-04-27 15:40:09 -04:00
|
|
|
|
2018-05-12 21:40:29 -04:00
|
|
|
/* And again, for the markers */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2018-05-12 21:40:29 -04:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
2018-04-27 15:40:09 -04:00
|
|
|
|
2018-05-12 21:40:29 -04:00
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
} else {
|
|
|
|
rdback.data[2] = 0;
|
|
|
|
rdback.data[6] = 0x01;
|
2018-09-21 15:57:15 -04:00
|
|
|
if (getenv("MEDIA_CODE"))
|
|
|
|
rdback.data[6] = atoi(getenv("MEDIA_CODE"));
|
2018-05-12 21:40:29 -04:00
|
|
|
}
|
2018-04-27 15:40:09 -04:00
|
|
|
|
|
|
|
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
|
|
|
|
ctx->marker.name = selphynew_pgcodes(rdback.data[6]);
|
2019-09-28 10:54:10 -04:00
|
|
|
ctx->marker.numtype = rdback.data[6];
|
2019-12-11 23:18:39 -05:00
|
|
|
ctx->marker.levelmax = CUPS_MARKER_UNAVAILABLE;
|
2018-04-29 14:15:54 -04:00
|
|
|
if (rdback.data[2]) {
|
|
|
|
ctx->marker.levelnow = 0;
|
|
|
|
} else {
|
2019-12-11 23:18:39 -05:00
|
|
|
ctx->marker.levelnow = CUPS_MARKER_UNKNOWN_OK;
|
2018-04-29 14:15:54 -04:00
|
|
|
}
|
2018-04-27 15:07:43 -04:00
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
2016-12-02 23:49:22 -05:00
|
|
|
}
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static void selphyneo_cleanup_job(const void *vjob) {
|
|
|
|
const struct selphyneo_printjob *job = vjob;
|
|
|
|
|
|
|
|
if (job->databuf)
|
|
|
|
free(job->databuf);
|
|
|
|
|
|
|
|
free((void*)job);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int selphyneo_read_parse(void *vctx, const void **vjob, int data_fd, int copies)
|
2016-12-02 23:49:22 -05:00
|
|
|
{
|
|
|
|
struct selphyneo_ctx *ctx = vctx;
|
|
|
|
struct selphyneo_hdr hdr;
|
|
|
|
int i, remain;
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
struct selphyneo_printjob *job = NULL;
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
if (!ctx)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
job = malloc(sizeof(*job));
|
|
|
|
if (!job) {
|
|
|
|
ERROR("Memory allocation failure!\n");
|
|
|
|
return CUPS_BACKEND_RETRY_CURRENT;
|
|
|
|
}
|
|
|
|
memset(job, 0, sizeof(*job));
|
|
|
|
job->copies = copies;
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
/* Read the header.. */
|
|
|
|
i = read(data_fd, &hdr, sizeof(hdr));
|
|
|
|
if (i != sizeof(hdr)) {
|
2018-06-17 21:08:17 -04:00
|
|
|
if (i == 0) {
|
|
|
|
selphyneo_cleanup_job(job);
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2018-06-17 21:08:17 -04:00
|
|
|
}
|
2017-07-10 20:15:56 -04:00
|
|
|
ERROR("Read failed (%d/%d)\n",
|
2016-12-02 23:49:22 -05:00
|
|
|
i, (int)sizeof(hdr));
|
|
|
|
perror("ERROR: Read failed");
|
2018-06-17 19:17:28 -04:00
|
|
|
selphyneo_cleanup_job(job);
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine job length */
|
|
|
|
switch(hdr.data[18]) {
|
2016-12-09 11:02:44 -05:00
|
|
|
case 0x50: /* P */
|
|
|
|
case 0x4c: /* L */
|
|
|
|
case 0x43: /* C */
|
|
|
|
remain = le32_to_cpu(hdr.cols) * le32_to_cpu(hdr.rows) * 3;
|
2016-12-02 23:49:22 -05:00
|
|
|
break;
|
|
|
|
default:
|
2016-12-09 11:02:44 -05:00
|
|
|
ERROR("Unknown print size! (%02x, %ux%u)\n",
|
|
|
|
hdr.data[10], le32_to_cpu(hdr.cols), le32_to_cpu(hdr.rows));
|
2018-06-17 21:08:17 -04:00
|
|
|
selphyneo_cleanup_job(job);
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2018-09-21 15:57:15 -04:00
|
|
|
// XXX Sanity check job against loaded media?
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
/* Allocate a buffer */
|
2018-06-15 14:55:03 -04:00
|
|
|
job->datalen = 0;
|
|
|
|
job->databuf = malloc(remain + sizeof(hdr));
|
|
|
|
if (!job->databuf) {
|
2016-12-02 23:49:22 -05:00
|
|
|
ERROR("Memory allocation failure!\n");
|
2018-06-17 19:17:28 -04:00
|
|
|
selphyneo_cleanup_job(job);
|
2018-02-16 10:49:21 -05:00
|
|
|
return CUPS_BACKEND_RETRY_CURRENT;
|
2017-07-10 20:15:56 -04:00
|
|
|
}
|
2016-12-02 23:49:22 -05:00
|
|
|
|
|
|
|
/* Store the read-in header */
|
2018-06-15 14:55:03 -04:00
|
|
|
memcpy(job->databuf, &hdr, sizeof(hdr));
|
|
|
|
job->datalen += sizeof(hdr);
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
/* Read in data */
|
|
|
|
while (remain > 0) {
|
2018-06-15 14:55:03 -04:00
|
|
|
i = read(data_fd, job->databuf + job->datalen, remain);
|
2018-06-17 19:17:28 -04:00
|
|
|
if (i < 0) {
|
|
|
|
selphyneo_cleanup_job(job);
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2018-06-17 19:17:28 -04:00
|
|
|
}
|
2016-12-02 23:49:22 -05:00
|
|
|
remain -= i;
|
2018-06-15 14:55:03 -04:00
|
|
|
job->datalen += i;
|
2016-12-02 23:49:22 -05:00
|
|
|
}
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
*vjob = job;
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static int selphyneo_main_loop(void *vctx, const void *vjob) {
|
2016-12-02 23:49:22 -05:00
|
|
|
struct selphyneo_ctx *ctx = vctx;
|
|
|
|
struct selphyneo_readback rdback;
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
int ret, num;
|
2018-06-15 14:55:03 -04:00
|
|
|
int copies;
|
|
|
|
|
|
|
|
const struct selphyneo_printjob *job = vjob;
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
if (!job)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
copies = job->copies;
|
2016-12-02 23:49:22 -05:00
|
|
|
|
|
|
|
/* Read in the printer status to clear last state */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2016-12-02 23:49:22 -05:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
|
|
|
|
2018-04-26 14:45:32 -04:00
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2017-07-10 20:15:56 -04:00
|
|
|
top:
|
2016-12-02 23:49:22 -05:00
|
|
|
INFO("Waiting for printer idle\n");
|
|
|
|
|
|
|
|
do {
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2016-12-02 23:49:22 -05:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
if (rdback.data[0] == 0x01)
|
|
|
|
break;
|
|
|
|
|
|
|
|
INFO("Printer state: %s\n", selphyneo_statuses(rdback.data[0]));
|
|
|
|
|
|
|
|
switch (rdback.data[2]) {
|
|
|
|
case 0x00:
|
|
|
|
break;
|
|
|
|
case 0x0A:
|
2016-12-10 22:43:20 -05:00
|
|
|
ERROR("Printer error: %s (%02x)\n", selphyneo_errors(rdback.data[2]), rdback.data[2]);
|
2018-04-27 15:40:09 -04:00
|
|
|
ctx->marker.levelnow = 0;
|
|
|
|
dump_markers(&ctx->marker, 1, 0);
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
default:
|
|
|
|
ERROR("Printer error: %s (%02x)\n", selphyneo_errors(rdback.data[2]), rdback.data[2]);
|
2018-04-27 15:40:09 -04:00
|
|
|
ctx->marker.levelnow = 0;
|
|
|
|
dump_markers(&ctx->marker, 1, 0);
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
} while(1);
|
|
|
|
|
2018-04-27 15:40:09 -04:00
|
|
|
dump_markers(&ctx->marker, 1, 0);
|
2016-12-02 23:49:22 -05:00
|
|
|
|
2017-07-10 20:15:56 -04:00
|
|
|
INFO("Sending spool data\n");
|
2016-12-02 23:49:22 -05:00
|
|
|
/* Send the data over in 256K chunks */
|
|
|
|
{
|
|
|
|
int chunk = 256*1024;
|
|
|
|
int sent = 0;
|
|
|
|
while (chunk > 0) {
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2018-06-15 14:55:03 -04:00
|
|
|
job->databuf + sent, chunk)))
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
sent += chunk;
|
2018-06-15 14:55:03 -04:00
|
|
|
chunk = job->datalen - sent;
|
2016-12-02 23:49:22 -05:00
|
|
|
if (chunk > 256*1024)
|
|
|
|
chunk = 256*1024;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in the printer status to clear last state */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2016-12-02 23:49:22 -05:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
|
|
|
|
2018-04-27 10:17:16 -04:00
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
INFO("Waiting for printer acknowledgement\n");
|
|
|
|
do {
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2016-12-02 23:49:22 -05:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
if (rdback.data[0] == 0x01)
|
|
|
|
break;
|
|
|
|
|
|
|
|
INFO("Printer state: %s\n", selphyneo_statuses(rdback.data[0]));
|
|
|
|
|
|
|
|
switch (rdback.data[2]) {
|
|
|
|
case 0x00:
|
|
|
|
break;
|
|
|
|
case 0x0A:
|
2016-12-10 22:43:20 -05:00
|
|
|
ERROR("Printer error: %s (%02x)\n", selphyneo_errors(rdback.data[2]), rdback.data[2]);
|
2018-04-27 15:40:09 -04:00
|
|
|
ctx->marker.levelnow = 0;
|
|
|
|
dump_markers(&ctx->marker, 1, 0);
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
default:
|
|
|
|
ERROR("Printer error: %s (%02x)\n", selphyneo_errors(rdback.data[2]), rdback.data[2]);
|
2018-04-27 15:40:09 -04:00
|
|
|
ctx->marker.levelnow = 0;
|
|
|
|
dump_markers(&ctx->marker, 1, 0);
|
2016-12-02 23:49:22 -05:00
|
|
|
return CUPS_BACKEND_STOP;
|
|
|
|
}
|
|
|
|
|
2017-12-07 14:07:26 -05:00
|
|
|
if (rdback.data[0] > 0x02 && fast_return && copies <= 1) {
|
2016-12-02 23:49:22 -05:00
|
|
|
INFO("Fast return mode enabled.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
} while(1);
|
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
if (terminate)
|
|
|
|
copies = 1;
|
|
|
|
|
|
|
|
INFO("Print complete (%d copies remaining)\n", copies - 1);
|
|
|
|
|
|
|
|
if (copies && --copies) {
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int selphyneo_cmdline_arg(void *vctx, int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct selphyneo_ctx *ctx = vctx;
|
|
|
|
int i, j = 0;
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return -1;
|
|
|
|
|
2018-01-04 10:00:57 -05:00
|
|
|
while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "Rs")) >= 0) {
|
2016-12-02 23:49:22 -05:00
|
|
|
switch(i) {
|
|
|
|
GETOPT_PROCESS_GLOBAL
|
2016-12-09 21:24:19 -05:00
|
|
|
case 'R':
|
|
|
|
selphyneo_send_reset(ctx);
|
2017-07-10 20:15:56 -04:00
|
|
|
break;
|
2018-01-04 10:00:57 -05:00
|
|
|
case 's':
|
|
|
|
selphyneo_get_status(ctx);
|
|
|
|
break;
|
2016-12-02 23:49:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (j) return j;
|
|
|
|
}
|
|
|
|
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2016-12-02 23:49:22 -05:00
|
|
|
}
|
|
|
|
|
2016-12-09 21:24:19 -05:00
|
|
|
static void selphyneo_cmdline(void)
|
|
|
|
{
|
|
|
|
DEBUG("\t\t[ -R ] # Reset printer\n");
|
2018-01-04 10:00:57 -05:00
|
|
|
DEBUG("\t\t[ -s ] # Query printer status\n");
|
2016-12-09 21:24:19 -05:00
|
|
|
}
|
|
|
|
|
2018-04-27 15:40:09 -04:00
|
|
|
static int selphyneo_query_markers(void *vctx, struct marker **markers, int *count)
|
|
|
|
{
|
|
|
|
struct selphyneo_ctx *ctx = vctx;
|
|
|
|
struct selphyneo_readback rdback;
|
|
|
|
int ret, num;
|
|
|
|
|
|
|
|
/* Read in the printer status to clear last state */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2018-04-27 15:40:09 -04:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
/* And again, for the markers */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2018-04-27 15:40:09 -04:00
|
|
|
(uint8_t*) &rdback, sizeof(rdback), &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
if (rdback.data[2])
|
|
|
|
ctx->marker.levelnow = 0;
|
|
|
|
else
|
2019-12-11 23:18:39 -05:00
|
|
|
ctx->marker.levelnow = CUPS_MARKER_UNKNOWN_OK;
|
2018-04-27 15:40:09 -04:00
|
|
|
|
|
|
|
*markers = &ctx->marker;
|
|
|
|
*count = 1;
|
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-16 15:35:00 -04:00
|
|
|
static const char *canonselphyneo_prefixes[] = {
|
2018-09-22 09:11:14 -04:00
|
|
|
"canonselphyneo", // Family name
|
|
|
|
// backwards compatibility
|
2018-03-16 15:35:00 -04:00
|
|
|
"selphycp820", "selphycp910", "selphycp1000", "selphycp1200", "selphycp1300",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-10-05 22:26:39 -04:00
|
|
|
const struct dyesub_backend canonselphyneo_backend = {
|
2018-03-26 22:27:27 -04:00
|
|
|
.name = "Canon SELPHY CP (new)",
|
2020-08-11 20:27:26 -04:00
|
|
|
.version = "0.21",
|
2018-03-16 15:35:00 -04:00
|
|
|
.uri_prefixes = canonselphyneo_prefixes,
|
2016-12-09 21:24:19 -05:00
|
|
|
.cmdline_usage = selphyneo_cmdline,
|
2016-12-02 23:49:22 -05:00
|
|
|
.cmdline_arg = selphyneo_cmdline_arg,
|
|
|
|
.init = selphyneo_init,
|
|
|
|
.attach = selphyneo_attach,
|
2018-06-15 14:55:03 -04:00
|
|
|
.cleanup_job = selphyneo_cleanup_job,
|
2016-12-02 23:49:22 -05:00
|
|
|
.read_parse = selphyneo_read_parse,
|
|
|
|
.main_loop = selphyneo_main_loop,
|
2018-04-27 15:40:09 -04:00
|
|
|
.query_markers = selphyneo_query_markers,
|
2016-12-02 23:49:22 -05:00
|
|
|
.devices = {
|
2018-09-22 09:11:14 -04:00
|
|
|
{ USB_VID_CANON, USB_PID_CANON_CP820, P_CP910, NULL, "canon-cp820"},
|
|
|
|
{ USB_VID_CANON, USB_PID_CANON_CP910, P_CP910, NULL, "canon-cp910"},
|
|
|
|
{ USB_VID_CANON, USB_PID_CANON_CP1000, P_CP910, NULL, "canon-cp1000"},
|
|
|
|
{ USB_VID_CANON, USB_PID_CANON_CP1200, P_CP910, NULL, "canon-cp1200"},
|
|
|
|
{ USB_VID_CANON, USB_PID_CANON_CP1300, P_CP910, NULL, "canon-cp1300"},
|
2018-03-16 15:35:00 -04:00
|
|
|
{ 0, 0, 0, NULL, NULL}
|
2016-12-02 23:49:22 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
|
|
|
|
***************************************************************************
|
|
|
|
|
|
|
|
Stream formats and readback codes for supported printers
|
|
|
|
|
|
|
|
***************************************************************************
|
|
|
|
Selphy CP820/CP910/CP1000/CP1200:
|
|
|
|
|
|
|
|
Radically different spool file format! 300dpi, same print sizes, but also
|
|
|
|
adding a 50x50mm sticker and 22x17.3mm ministickers, though I think the
|
|
|
|
driver treats all of those as 'C' sizes for printing purposes.
|
|
|
|
|
|
|
|
32-byte header:
|
|
|
|
|
|
|
|
0f 00 00 40 00 00 00 00 00 00 00 00 00 00 01 00
|
2017-04-20 21:33:21 -04:00
|
|
|
01 00 TT 00 00 00 00 ZZ XX XX XX XX YY YY YY YY
|
2016-12-02 23:49:22 -05:00
|
|
|
|
2016-12-09 11:02:44 -05:00
|
|
|
cols (le32) rows (le32)
|
|
|
|
50 e0 04 50 07 1248 * 1872 (P)
|
|
|
|
4c 80 04 c0 05 1152 * 1472 (L)
|
|
|
|
43 40 04 9c 02 1088 * 668 (C)
|
|
|
|
|
|
|
|
TT == 50 (P)
|
2016-12-02 23:49:22 -05:00
|
|
|
== 4c (L)
|
|
|
|
== 43 (C)
|
|
|
|
|
2017-04-20 21:33:21 -04:00
|
|
|
ZZ == 00 Y'CbCr data follows
|
|
|
|
== 01 CMY data follows
|
|
|
|
|
2016-12-09 11:02:44 -05:00
|
|
|
Followed by three planes of image data.
|
2016-12-02 23:49:22 -05:00
|
|
|
|
|
|
|
P == 7008800 == 2336256 * 3 + 32 (1872*1248)
|
2016-12-09 11:02:44 -05:00
|
|
|
L == 5087264 == 1695744 * 3 + 32 (1472*1152)
|
2016-12-02 23:49:22 -05:00
|
|
|
C == 2180384 == 726784 * 3 + 32 (1088*668)
|
|
|
|
|
2017-07-10 20:15:56 -04:00
|
|
|
It is worth mentioning that the Y'CbCr image data is surmised to use the
|
2017-04-20 21:33:21 -04:00
|
|
|
JPEG coefficients, although we realistically have no way of confirming this.
|
2016-12-02 23:49:22 -05:00
|
|
|
|
2016-12-09 11:02:44 -05:00
|
|
|
Other questions:
|
|
|
|
|
|
|
|
* Printer supports different lamination types, how to control?
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
Data Readback:
|
|
|
|
|
|
|
|
XX 00 YY 00 00 00 ZZ 00 00 00 00 00
|
|
|
|
|
|
|
|
XX == Status
|
|
|
|
|
|
|
|
01 Idle
|
|
|
|
02 Feeding Paper
|
|
|
|
04 Printing Y
|
|
|
|
08 Printing M
|
|
|
|
10 Printing C
|
|
|
|
20 Printing L
|
|
|
|
|
|
|
|
YY == Error
|
|
|
|
|
|
|
|
00 None
|
|
|
|
02 No Paper (?)
|
|
|
|
03 No Paper
|
2017-11-12 19:42:33 -05:00
|
|
|
05 Wrong Paper
|
2016-12-02 23:49:22 -05:00
|
|
|
07 No Ink
|
2016-12-10 22:43:20 -05:00
|
|
|
09 No Paper and Ink
|
2016-12-02 23:49:22 -05:00
|
|
|
0A Media/Job mismatch
|
2017-11-12 19:42:33 -05:00
|
|
|
0B Paper Jam
|
2016-12-02 23:49:22 -05:00
|
|
|
|
|
|
|
ZZ == Media?
|
|
|
|
|
2017-07-10 20:15:56 -04:00
|
|
|
01
|
2016-12-02 23:49:22 -05:00
|
|
|
10
|
|
|
|
11
|
2016-12-09 21:24:19 -05:00
|
|
|
^-- Ribbon
|
|
|
|
^-- Paper
|
2016-12-02 23:49:22 -05:00
|
|
|
|
2016-12-10 22:43:20 -05:00
|
|
|
1 == P
|
|
|
|
2 == L ??
|
|
|
|
3 == C
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
Also, the first time a readback happens after plugging in the printer:
|
|
|
|
|
|
|
|
34 44 35 31 01 00 01 00 01 00 45 00 "4D51" ...??
|
2019-10-19 21:13:59 -04:00
|
|
|
34 44 35 31 01 00 01 00 01 00 54 00 [also seen..]
|
2016-12-02 23:49:22 -05:00
|
|
|
|
2017-04-12 20:36:27 -04:00
|
|
|
|
|
|
|
** ** ** ** This is what windows sends if you print over the network:
|
|
|
|
|
|
|
|
00 00 00 00 40 00 00 00 02 00 00 00 00 00 04 00 Header [unknown]
|
|
|
|
00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
|
|
|
|
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
|
|
|
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
|
|
|
|
|
|
|
00 00 01 00 HH HH HH HH 02 00 00 00 PP PP PP PP Header2 [unknown] PP == payload len, HH == payload + header2 len [ie + 3 ]
|
|
|
|
CC CC CC CC RR RR RR RR 00 00 00 00 LL LL LL LL CC == cols, RR == rows, LL == plane len (ie RR * CC)
|
|
|
|
L2 L2 L2 L2 L2 == LL * 2, apparently.
|
|
|
|
|
|
|
|
[ ..followed by three planes of LL bytes, totalling PP bytes.. ]
|
|
|
|
|
2016-12-02 23:49:22 -05:00
|
|
|
*/
|