2013-01-19 17:10:21 -05:00
|
|
|
/*
|
2013-07-27 07:32:21 -04:00
|
|
|
* Kodak Professional 1400/805 CUPS backend -- libusb-1.0 version
|
2013-01-19 17:10:21 -05:00
|
|
|
*
|
2021-02-23 07:39:47 -05:00
|
|
|
* (c) 2013-2021 Solomon Peachy <pizza@shaftnet.org>
|
2013-01-19 17:10:21 -05:00
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
2014-01-13 05:41:48 -05:00
|
|
|
*
|
2021-01-23 10:47:01 -05:00
|
|
|
* https://git.shaftnet.org/cgit/selphy_print.git
|
2014-01-13 05:41:48 -05:00
|
|
|
*
|
2013-01-19 17:10:21 -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/>.
|
2013-01-19 17:10:21 -05:00
|
|
|
*
|
2017-11-17 13:34:26 -05:00
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
*
|
2013-01-19 17:10:21 -05:00
|
|
|
*/
|
|
|
|
|
2015-08-13 21:09:56 -04:00
|
|
|
#define BACKEND kodak1400_backend
|
|
|
|
|
2013-07-18 21:05:33 -04:00
|
|
|
#include "backend_common.h"
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2013-01-19 19:11:20 -05:00
|
|
|
/* Program states */
|
|
|
|
enum {
|
|
|
|
S_IDLE = 0,
|
|
|
|
S_PRINTER_READY_Y,
|
2013-01-19 21:36:23 -05:00
|
|
|
S_PRINTER_SENT_Y,
|
2013-01-19 19:11:20 -05:00
|
|
|
S_PRINTER_READY_M,
|
2013-01-19 21:36:23 -05:00
|
|
|
S_PRINTER_SENT_M,
|
2013-01-19 19:11:20 -05:00
|
|
|
S_PRINTER_READY_C,
|
2013-01-19 21:36:23 -05:00
|
|
|
S_PRINTER_SENT_C,
|
|
|
|
S_PRINTER_READY_L,
|
|
|
|
S_PRINTER_SENT_L,
|
2013-01-19 19:11:20 -05:00
|
|
|
S_PRINTER_DONE,
|
|
|
|
S_FINISHED,
|
|
|
|
};
|
|
|
|
|
2013-07-18 21:05:33 -04:00
|
|
|
#define CMDBUF_LEN 96
|
|
|
|
#define READBACK_LEN 8
|
|
|
|
|
|
|
|
/* File header */
|
2013-01-19 17:10:21 -05:00
|
|
|
struct kodak1400_hdr {
|
2013-01-19 19:11:20 -05:00
|
|
|
uint8_t hdr[4];
|
|
|
|
uint16_t columns;
|
|
|
|
uint16_t null1;
|
|
|
|
uint16_t rows;
|
|
|
|
uint16_t null2;
|
|
|
|
uint32_t planesize;
|
|
|
|
uint32_t null3;
|
|
|
|
uint8_t matte;
|
|
|
|
uint8_t laminate;
|
|
|
|
uint8_t unk1; /* Always 0x01 */
|
|
|
|
uint8_t lam_strength;
|
|
|
|
uint8_t null4[12];
|
2013-06-28 07:18:16 -04:00
|
|
|
} __attribute__((packed));
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2013-06-27 23:02:34 -04:00
|
|
|
|
2017-05-05 08:06:28 -04:00
|
|
|
/* Private data structure */
|
2018-06-15 14:55:03 -04:00
|
|
|
struct kodak1400_printjob {
|
2021-02-23 07:39:47 -05:00
|
|
|
size_t jobsize;
|
|
|
|
int copies;
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
struct kodak1400_hdr hdr;
|
|
|
|
uint8_t *plane_r;
|
|
|
|
uint8_t *plane_g;
|
|
|
|
uint8_t *plane_b;
|
|
|
|
};
|
|
|
|
|
2013-07-18 21:05:33 -04:00
|
|
|
struct kodak1400_ctx {
|
2020-08-11 20:27:26 -04:00
|
|
|
struct dyesub_connection *conn;
|
2013-01-19 21:36:23 -05:00
|
|
|
|
2018-04-29 14:07:08 -04:00
|
|
|
struct marker marker;
|
2013-07-18 21:05:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int send_plane(struct kodak1400_ctx *ctx,
|
2018-06-15 14:55:03 -04:00
|
|
|
const struct kodak1400_printjob *job,
|
2013-01-19 22:24:58 -05:00
|
|
|
uint8_t planeno, uint8_t *planedata,
|
2013-07-18 21:05:33 -04:00
|
|
|
uint8_t *cmdbuf)
|
2013-01-19 22:24:58 -05:00
|
|
|
{
|
|
|
|
uint16_t temp16;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (planeno != 1) {
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x74;
|
|
|
|
cmdbuf[2] = 0x00;
|
|
|
|
cmdbuf[3] = 0x50;
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-01-19 22:24:58 -05:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x5a;
|
|
|
|
cmdbuf[2] = 0x54;
|
|
|
|
cmdbuf[3] = planeno;
|
2013-01-19 22:26:52 -05:00
|
|
|
|
|
|
|
if (planedata) {
|
2020-01-25 07:33:52 -05:00
|
|
|
temp16 = be16_to_cpu(job->hdr.columns);
|
2013-01-19 22:26:52 -05:00
|
|
|
memcpy(cmdbuf+7, &temp16, 2);
|
2020-01-25 07:33:52 -05:00
|
|
|
temp16 = be16_to_cpu(job->hdr.rows);
|
2013-01-19 22:26:52 -05:00
|
|
|
memcpy(cmdbuf+9, &temp16, 2);
|
2013-01-19 22:46:04 -05:00
|
|
|
}
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-01-19 22:46:04 -05:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (planedata) {
|
2014-02-11 20:11:33 -05:00
|
|
|
int i;
|
2018-06-15 14:55:03 -04:00
|
|
|
for (i = 0 ; i < job->hdr.rows ; i++) {
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2018-06-15 14:55:03 -04:00
|
|
|
planedata + i * job->hdr.columns,
|
|
|
|
job->hdr.columns)))
|
2013-01-19 22:26:52 -05:00
|
|
|
return ret;
|
|
|
|
}
|
2013-01-19 22:24:58 -05:00
|
|
|
}
|
2013-01-19 22:26:52 -05:00
|
|
|
|
2013-01-19 22:24:58 -05:00
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x74;
|
|
|
|
cmdbuf[2] = 0x01;
|
|
|
|
cmdbuf[3] = 0x50;
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-01-19 22:24:58 -05:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
|
|
|
return ret;
|
|
|
|
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-01-19 22:24:58 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 12:55:57 -04:00
|
|
|
#define TONE_CURVE_SIZE 1552
|
2013-07-18 21:05:33 -04:00
|
|
|
static int kodak1400_set_tonecurve(struct kodak1400_ctx *ctx, char *fname)
|
2013-07-08 20:45:46 -04:00
|
|
|
{
|
|
|
|
uint8_t cmdbuf[8];
|
|
|
|
uint8_t respbuf[64];
|
2014-02-11 20:11:33 -05:00
|
|
|
int ret = 0, num = 0;
|
2013-07-08 20:45:46 -04:00
|
|
|
|
|
|
|
INFO("Set Tone Curve from '%s'\n", fname);
|
|
|
|
|
2019-05-12 12:55:57 -04:00
|
|
|
uint16_t *data = malloc(TONE_CURVE_SIZE);
|
2013-07-08 20:45:46 -04:00
|
|
|
|
2015-06-23 20:32:41 -04:00
|
|
|
if (!data) {
|
|
|
|
ERROR("Memory Allocation Failure!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-08 20:45:46 -04:00
|
|
|
/* Read in file */
|
2019-05-12 12:55:57 -04:00
|
|
|
if ((ret = dyesub_read_file(fname, data, TONE_CURVE_SIZE, NULL))) {
|
2019-01-13 15:44:29 -05:00
|
|
|
ERROR("Failed to read Tone Curve file\n");
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
|
|
|
}
|
2013-07-08 20:45:46 -04:00
|
|
|
|
|
|
|
/* Byteswap data to printer's format */
|
2019-05-12 12:55:57 -04:00
|
|
|
for (ret = 0; ret < (TONE_CURVE_SIZE-16)/2 ; ret++) {
|
2013-07-08 20:45:46 -04:00
|
|
|
data[ret] = cpu_to_le16(be16_to_cpu(data[ret]));
|
|
|
|
}
|
|
|
|
/* Null-terminate */
|
2019-05-12 12:55:57 -04:00
|
|
|
memset(data + (TONE_CURVE_SIZE-16)/2, 0, 16);
|
2013-07-08 20:45:46 -04:00
|
|
|
|
|
|
|
/* Clear tables */
|
|
|
|
memset(cmdbuf, 0, sizeof(cmdbuf));
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0xa2;
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2014-02-11 20:11:33 -05:00
|
|
|
cmdbuf, 2))) {
|
|
|
|
ret = -3;
|
|
|
|
goto done;
|
|
|
|
}
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2013-12-21 22:55:33 -05:00
|
|
|
respbuf, sizeof(respbuf), &num);
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
if (ret < 0)
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-12-21 22:55:33 -05:00
|
|
|
if (num != 8) {
|
|
|
|
ERROR("Short Read! (%d/%d)\n", num, 8);
|
2014-02-11 20:11:33 -05:00
|
|
|
ret = -4;
|
|
|
|
goto done;
|
2013-07-08 20:45:46 -04:00
|
|
|
}
|
|
|
|
if (respbuf[1] != 0x01) {
|
|
|
|
ERROR("Received unexpected response\n");
|
2014-02-11 20:11:33 -05:00
|
|
|
ret = -5;
|
|
|
|
goto done;
|
2013-07-08 20:45:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the update command */
|
|
|
|
memset(cmdbuf, 0, sizeof(cmdbuf));
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0xa0;
|
|
|
|
cmdbuf[2] = 0x02;
|
|
|
|
cmdbuf[3] = 0x03;
|
|
|
|
cmdbuf[4] = 0x06;
|
2019-05-12 12:55:57 -04:00
|
|
|
cmdbuf[5] = 0x10; /* 06 10 == TONE_CURVE_SIZE */
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-07-08 20:45:46 -04:00
|
|
|
cmdbuf, 6)))
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-07-08 20:45:46 -04:00
|
|
|
|
|
|
|
/* Send the payload over */
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2019-05-12 12:55:57 -04:00
|
|
|
(uint8_t *) data, TONE_CURVE_SIZE)))
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-07-08 20:45:46 -04:00
|
|
|
|
|
|
|
/* get the response */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2013-12-21 22:55:33 -05:00
|
|
|
respbuf, sizeof(respbuf), &num);
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
if (ret < 0)
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-12-21 22:55:33 -05:00
|
|
|
if (num != 8) {
|
|
|
|
ERROR("Short Read! (%d/%d)\n", num, 8);
|
2014-02-11 20:11:33 -05:00
|
|
|
ret = -6;
|
|
|
|
goto done;
|
2013-07-08 20:45:46 -04:00
|
|
|
}
|
|
|
|
if (respbuf[1] != 0x00) {
|
2013-12-21 22:55:33 -05:00
|
|
|
ERROR("Received unexpected response!\n");
|
2014-02-11 20:11:33 -05:00
|
|
|
ret = -7;
|
|
|
|
goto done;
|
2013-07-08 20:45:46 -04:00
|
|
|
}
|
|
|
|
|
2014-02-11 20:11:33 -05:00
|
|
|
done:
|
2013-07-08 20:45:46 -04:00
|
|
|
free(data);
|
|
|
|
|
2014-02-11 20:11:33 -05:00
|
|
|
return ret;
|
2013-07-08 20:45:46 -04:00
|
|
|
}
|
|
|
|
|
2014-02-10 20:10:36 -05:00
|
|
|
static void kodak1400_cmdline(void)
|
2013-01-19 17:10:21 -05:00
|
|
|
{
|
2014-02-10 20:10:36 -05:00
|
|
|
DEBUG("\t\t[ -C filename ] # Set tone curve\n");
|
2013-07-18 21:05:33 -04:00
|
|
|
}
|
2013-01-19 21:36:23 -05:00
|
|
|
|
2020-03-24 18:22:39 -04:00
|
|
|
static int kodak1400_cmdline_arg(void *vctx, int argc, char **argv)
|
2013-07-18 21:05:33 -04:00
|
|
|
{
|
|
|
|
struct kodak1400_ctx *ctx = vctx;
|
2014-02-11 22:45:14 -05:00
|
|
|
int i, j = 0;
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2015-08-24 17:28:10 -04:00
|
|
|
if (!ctx)
|
|
|
|
return -1;
|
|
|
|
|
2015-08-13 21:09:56 -04:00
|
|
|
while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "C:")) >= 0) {
|
2014-02-10 20:10:36 -05:00
|
|
|
switch(i) {
|
2015-08-13 21:09:56 -04:00
|
|
|
GETOPT_PROCESS_GLOBAL
|
2014-02-10 20:10:36 -05:00
|
|
|
case 'C':
|
2015-08-24 17:28:10 -04:00
|
|
|
j = kodak1400_set_tonecurve(ctx, optarg);
|
|
|
|
break;
|
2014-02-10 20:10:36 -05:00
|
|
|
default:
|
|
|
|
break; /* Ignore completely */
|
|
|
|
}
|
2014-02-11 22:45:14 -05:00
|
|
|
|
|
|
|
if (j) return j;
|
2014-02-10 20:10:36 -05:00
|
|
|
}
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-07-18 21:05:33 -04:00
|
|
|
}
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2013-07-19 09:23:53 -04:00
|
|
|
static void *kodak1400_init(void)
|
2013-07-18 21:05:33 -04:00
|
|
|
{
|
|
|
|
struct kodak1400_ctx *ctx = malloc(sizeof(struct kodak1400_ctx));
|
2015-06-23 20:32:41 -04:00
|
|
|
if (!ctx) {
|
|
|
|
ERROR("Memory Allocation Failure!\n");
|
2013-07-18 21:05:33 -04:00
|
|
|
return NULL;
|
2015-06-23 20:32:41 -04:00
|
|
|
}
|
2013-07-18 21:05:33 -04:00
|
|
|
memset(ctx, 0, sizeof(struct kodak1400_ctx));
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2013-07-19 09:23:53 -04:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
static int kodak1400_attach(void *vctx, struct dyesub_connection *conn,
|
|
|
|
uint8_t jobid)
|
2013-07-19 09:23:53 -04:00
|
|
|
{
|
|
|
|
struct kodak1400_ctx *ctx = vctx;
|
|
|
|
|
2013-11-23 19:51:55 -05:00
|
|
|
UNUSED(jobid);
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
ctx->conn = conn;
|
2018-04-27 15:07:43 -04:00
|
|
|
|
2018-04-29 14:07:08 -04:00
|
|
|
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
|
|
|
|
ctx->marker.name = "Unknown";
|
2019-09-28 10:54:10 -04:00
|
|
|
ctx->marker.numtype = -1;
|
2019-12-11 23:18:39 -05:00
|
|
|
ctx->marker.levelmax = CUPS_MARKER_UNAVAILABLE;
|
|
|
|
ctx->marker.levelnow = CUPS_MARKER_UNKNOWN;
|
2018-04-29 14:07:08 -04:00
|
|
|
|
2018-04-27 15:07:43 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2015-08-12 22:56:29 -04:00
|
|
|
}
|
2013-07-19 09:23:53 -04:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static void kodak1400_cleanup_job(const void *vjob)
|
|
|
|
{
|
|
|
|
const struct kodak1400_printjob *job = vjob;
|
|
|
|
|
|
|
|
if (job->plane_r)
|
|
|
|
free(job->plane_r);
|
|
|
|
if (job->plane_g)
|
|
|
|
free(job->plane_g);
|
|
|
|
if (job->plane_b)
|
|
|
|
free(job->plane_b);
|
|
|
|
|
|
|
|
free((void*)job);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kodak1400_read_parse(void *vctx, const void **vjob, int data_fd, int copies) {
|
2013-07-18 21:05:33 -04:00
|
|
|
struct kodak1400_ctx *ctx = vctx;
|
|
|
|
int i, ret;
|
2013-07-17 19:47:47 -04:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
struct kodak1400_printjob *job = NULL;
|
|
|
|
|
2013-07-18 21:05:33 -04:00
|
|
|
if (!ctx)
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
job = malloc(sizeof(*job));
|
|
|
|
if (!job) {
|
|
|
|
ERROR("Memory allocation failure!\n");
|
|
|
|
return CUPS_BACKEND_RETRY_CURRENT;
|
2014-01-21 20:34:00 -05:00
|
|
|
}
|
2018-06-15 14:55:03 -04:00
|
|
|
memset(job, 0, sizeof(*job));
|
|
|
|
job->copies = copies;
|
2013-05-02 20:15:55 -04:00
|
|
|
|
2013-01-19 17:10:21 -05:00
|
|
|
/* Read in then validate header */
|
2018-06-15 14:55:03 -04:00
|
|
|
ret = read(data_fd, &job->hdr, sizeof(job->hdr));
|
|
|
|
if (ret < 0 || ret != sizeof(job->hdr)) {
|
2021-02-23 07:39:47 -05:00
|
|
|
if (ret == 0) {
|
|
|
|
kodak1400_cleanup_job(job);
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2021-02-23 07:39:47 -05:00
|
|
|
}
|
2017-07-10 20:15:56 -04:00
|
|
|
ERROR("Read failed (%d/%d/%d)\n",
|
2018-06-15 14:55:03 -04:00
|
|
|
ret, 0, (int)sizeof(job->hdr));
|
2014-01-13 18:30:30 -05:00
|
|
|
perror("ERROR: Read failed");
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-01-13 18:30:30 -05:00
|
|
|
}
|
2018-06-15 14:55:03 -04:00
|
|
|
if (job->hdr.hdr[0] != 'P' ||
|
|
|
|
job->hdr.hdr[1] != 'G' ||
|
|
|
|
job->hdr.hdr[2] != 'H' ||
|
|
|
|
job->hdr.hdr[3] != 'D') {
|
2013-01-19 17:10:21 -05:00
|
|
|
ERROR("Unrecognized data format!\n");
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2013-01-19 17:10:21 -05:00
|
|
|
}
|
2018-06-15 14:55:03 -04:00
|
|
|
job->hdr.planesize = le32_to_cpu(job->hdr.planesize);
|
|
|
|
job->hdr.rows = le16_to_cpu(job->hdr.rows);
|
|
|
|
job->hdr.columns = le16_to_cpu(job->hdr.columns);
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2013-01-19 17:10:21 -05:00
|
|
|
/* Set up plane data */
|
2018-06-15 14:55:03 -04:00
|
|
|
job->plane_r = malloc(job->hdr.planesize);
|
|
|
|
job->plane_g = malloc(job->hdr.planesize);
|
|
|
|
job->plane_b = malloc(job->hdr.planesize);
|
|
|
|
if (!job->plane_r || !job->plane_g || !job->plane_b) {
|
2013-01-19 17:10:21 -05:00
|
|
|
ERROR("Memory allocation failure!\n");
|
2018-02-16 10:49:21 -05:00
|
|
|
return CUPS_BACKEND_RETRY_CURRENT;
|
2013-01-19 17:10:21 -05:00
|
|
|
}
|
2018-06-15 14:55:03 -04:00
|
|
|
for (i = 0 ; i < job->hdr.rows ; i++) {
|
2013-01-19 17:10:21 -05:00
|
|
|
int j;
|
|
|
|
uint8_t *ptr;
|
|
|
|
for (j = 0 ; j < 3 ; j++) {
|
2014-02-11 20:11:33 -05:00
|
|
|
int remain;
|
2013-01-19 17:10:21 -05:00
|
|
|
if (j == 0)
|
2018-06-15 14:55:03 -04:00
|
|
|
ptr = job->plane_r + i * job->hdr.columns;
|
2013-02-02 12:47:53 -05:00
|
|
|
else if (j == 1)
|
2018-06-15 14:55:03 -04:00
|
|
|
ptr = job->plane_g + i * job->hdr.columns;
|
2013-02-02 12:47:53 -05:00
|
|
|
else if (j == 2)
|
2018-06-15 14:55:03 -04:00
|
|
|
ptr = job->plane_b + i * job->hdr.columns;
|
2018-05-01 14:46:51 -04:00
|
|
|
else
|
|
|
|
ptr = NULL;
|
2013-01-19 23:10:09 -05:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
remain = job->hdr.columns;
|
2013-02-02 12:47:53 -05:00
|
|
|
do {
|
|
|
|
ret = read(data_fd, ptr, remain);
|
|
|
|
if (ret < 0) {
|
2017-07-10 20:15:56 -04:00
|
|
|
ERROR("Read failed (%d/%d/%u) (%d/%u @ %d)\n",
|
2018-06-15 14:55:03 -04:00
|
|
|
ret, remain, job->hdr.columns,
|
|
|
|
i, job->hdr.rows, j);
|
2013-02-02 12:47:53 -05:00
|
|
|
perror("ERROR: Read failed");
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2013-02-02 12:47:53 -05:00
|
|
|
}
|
|
|
|
ptr += ret;
|
|
|
|
remain -= ret;
|
|
|
|
} while (remain);
|
2013-01-19 17:10:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
*vjob = job;
|
|
|
|
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-07-18 21:05:33 -04:00
|
|
|
}
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2013-07-18 21:05:33 -04:00
|
|
|
static uint8_t idle_data[READBACK_LEN] = { 0xe4, 0x72, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00 };
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static int kodak1400_main_loop(void *vctx, const void *vjob) {
|
2013-07-18 21:05:33 -04:00
|
|
|
struct kodak1400_ctx *ctx = vctx;
|
2013-07-08 20:45:46 -04:00
|
|
|
|
2013-07-18 21:05:33 -04:00
|
|
|
uint8_t rdbuf[READBACK_LEN], rdbuf2[READBACK_LEN];
|
|
|
|
uint8_t cmdbuf[CMDBUF_LEN];
|
|
|
|
int last_state = -1, state = S_IDLE;
|
|
|
|
int num, ret;
|
|
|
|
uint16_t temp16;
|
2018-06-15 14:55:03 -04:00
|
|
|
int copies;
|
|
|
|
|
|
|
|
const struct kodak1400_printjob *job = vjob;
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
if (!job)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
copies = job->copies;
|
2013-01-19 19:11:20 -05:00
|
|
|
|
|
|
|
top:
|
2013-07-16 23:19:04 -04:00
|
|
|
if (state != last_state) {
|
2013-12-21 22:15:18 -05:00
|
|
|
if (dyesub_debug)
|
|
|
|
DEBUG("last_state %d new %d\n", last_state, state);
|
2013-07-16 23:19:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send Status Query */
|
2013-01-19 19:11:20 -05:00
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x72;
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-01-19 22:17:33 -05:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 19:11:20 -05:00
|
|
|
|
|
|
|
/* Read in the printer status */
|
2020-08-11 20:27:26 -04:00
|
|
|
ret = read_data(ctx->conn,
|
2013-12-21 22:55:33 -05:00
|
|
|
rdbuf, READBACK_LEN, &num);
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
if (ret < 0)
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 19:11:20 -05:00
|
|
|
if (memcmp(rdbuf, rdbuf2, READBACK_LEN)) {
|
|
|
|
memcpy(rdbuf2, rdbuf, READBACK_LEN);
|
2013-07-16 23:19:04 -04:00
|
|
|
} else if (state == last_state) {
|
2013-01-19 19:11:20 -05:00
|
|
|
sleep(1);
|
|
|
|
}
|
2013-07-16 23:19:04 -04:00
|
|
|
last_state = state;
|
|
|
|
|
2013-09-01 16:58:11 -04:00
|
|
|
/* Error handling */
|
|
|
|
if (rdbuf[4] || rdbuf[5]) {
|
|
|
|
ERROR("Error code reported by printer (%02x/%02x), terminating print\n",
|
|
|
|
rdbuf[4], rdbuf[5]);
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_STOP; // HOLD/CANCEL/FAILED? XXXX parse error!
|
2013-09-01 16:58:11 -04:00
|
|
|
}
|
|
|
|
|
2020-08-11 12:48:38 -04:00
|
|
|
fflush(logger);
|
2013-01-19 19:11:20 -05:00
|
|
|
|
|
|
|
switch (state) {
|
2013-01-19 21:36:23 -05:00
|
|
|
case S_IDLE:
|
2013-05-02 20:15:55 -04:00
|
|
|
INFO("Printing started\n");
|
|
|
|
|
2013-01-19 21:36:23 -05:00
|
|
|
/* Send reset/attention */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-05-02 20:15:55 -04:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:36:23 -05:00
|
|
|
|
|
|
|
/* Send page setup */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x5a;
|
|
|
|
cmdbuf[2] = 0x53;
|
2018-06-15 14:55:03 -04:00
|
|
|
temp16 = be16_to_cpu(job->hdr.columns);
|
2013-01-19 21:36:23 -05:00
|
|
|
memcpy(cmdbuf+3, &temp16, 2);
|
2018-06-15 14:55:03 -04:00
|
|
|
temp16 = be16_to_cpu(job->hdr.rows);
|
2013-01-19 21:36:23 -05:00
|
|
|
memcpy(cmdbuf+5, &temp16, 2);
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-01-19 22:17:33 -05:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:36:23 -05:00
|
|
|
|
2013-01-19 21:54:18 -05:00
|
|
|
/* Send lamination toggle? */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x59;
|
2018-06-15 14:55:03 -04:00
|
|
|
cmdbuf[2] = job->hdr.matte; // ???
|
2013-01-19 21:54:18 -05:00
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-01-19 22:17:33 -05:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:54:18 -05:00
|
|
|
|
2013-01-27 11:35:32 -05:00
|
|
|
/* Send matte toggle */
|
2013-01-19 21:54:18 -05:00
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x60;
|
2018-06-15 14:55:03 -04:00
|
|
|
cmdbuf[2] = job->hdr.laminate;
|
2013-01-19 21:54:18 -05:00
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if (send_data(ctx->conn,
|
2013-01-19 22:17:33 -05:00
|
|
|
cmdbuf, CMDBUF_LEN))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 19:11:20 -05:00
|
|
|
|
2013-01-19 21:36:23 -05:00
|
|
|
/* Send lamination strength */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x62;
|
2018-06-15 14:55:03 -04:00
|
|
|
cmdbuf[2] = job->hdr.lam_strength;
|
2013-01-19 19:11:20 -05:00
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-01-19 22:17:33 -05:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:36:23 -05:00
|
|
|
|
2013-01-27 11:35:32 -05:00
|
|
|
/* Send unknown */
|
2013-01-19 21:54:18 -05:00
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x61;
|
2018-06-15 14:55:03 -04:00
|
|
|
cmdbuf[2] = job->hdr.unk1; // ???
|
2013-01-19 21:54:18 -05:00
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-01-19 22:17:33 -05:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:52:02 -05:00
|
|
|
|
2013-01-19 21:36:23 -05:00
|
|
|
state = S_PRINTER_READY_Y;
|
|
|
|
break;
|
|
|
|
case S_PRINTER_READY_Y:
|
2013-07-01 07:23:13 -04:00
|
|
|
INFO("Sending YELLOW plane\n");
|
2018-06-15 14:55:03 -04:00
|
|
|
if ((ret = send_plane(ctx, job, 1, job->plane_b, cmdbuf)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:36:23 -05:00
|
|
|
state = S_PRINTER_SENT_Y;
|
|
|
|
break;
|
|
|
|
case S_PRINTER_SENT_Y:
|
|
|
|
if (!memcmp(rdbuf, idle_data, READBACK_LEN))
|
|
|
|
state = S_PRINTER_READY_M;
|
|
|
|
break;
|
|
|
|
case S_PRINTER_READY_M:
|
2013-07-01 07:23:13 -04:00
|
|
|
INFO("Sending MAGENTA plane\n");
|
2018-06-15 14:55:03 -04:00
|
|
|
if ((ret = send_plane(ctx, job, 2, job->plane_g, cmdbuf)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:36:23 -05:00
|
|
|
state = S_PRINTER_SENT_M;
|
|
|
|
break;
|
|
|
|
case S_PRINTER_SENT_M:
|
|
|
|
if (!memcmp(rdbuf, idle_data, READBACK_LEN))
|
|
|
|
state = S_PRINTER_READY_C;
|
|
|
|
break;
|
|
|
|
case S_PRINTER_READY_C:
|
2013-07-01 07:23:13 -04:00
|
|
|
INFO("Sending CYAN plane\n");
|
2018-06-15 14:55:03 -04:00
|
|
|
if ((ret = send_plane(ctx, job, 3, job->plane_r, cmdbuf)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:36:23 -05:00
|
|
|
state = S_PRINTER_SENT_C;
|
|
|
|
break;
|
|
|
|
case S_PRINTER_SENT_C:
|
2013-02-03 10:34:42 -05:00
|
|
|
if (!memcmp(rdbuf, idle_data, READBACK_LEN)) {
|
2018-06-15 14:55:03 -04:00
|
|
|
if (job->hdr.laminate)
|
2013-02-03 10:34:42 -05:00
|
|
|
state = S_PRINTER_READY_L;
|
|
|
|
else
|
|
|
|
state = S_PRINTER_DONE;
|
|
|
|
}
|
2013-01-19 21:36:23 -05:00
|
|
|
break;
|
|
|
|
case S_PRINTER_READY_L:
|
2013-07-01 07:23:13 -04:00
|
|
|
INFO("Laminating page\n");
|
2018-06-15 14:55:03 -04:00
|
|
|
if ((ret = send_plane(ctx, job, 4, NULL, cmdbuf)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:36:23 -05:00
|
|
|
state = S_PRINTER_SENT_L;
|
|
|
|
break;
|
|
|
|
case S_PRINTER_SENT_L:
|
|
|
|
if (!memcmp(rdbuf, idle_data, READBACK_LEN))
|
|
|
|
state = S_PRINTER_DONE;
|
|
|
|
break;
|
|
|
|
case S_PRINTER_DONE:
|
2013-07-01 07:23:13 -04:00
|
|
|
INFO("Cleaning up\n");
|
2013-01-19 21:44:58 -05:00
|
|
|
/* Cleanup */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x74;
|
|
|
|
cmdbuf[2] = 0x00;
|
|
|
|
cmdbuf[3] = 0x50;
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if ((ret = send_data(ctx->conn,
|
2013-01-19 22:17:33 -05:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-01-19 21:44:58 -05:00
|
|
|
|
2013-01-19 21:36:23 -05:00
|
|
|
state = S_FINISHED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-01-19 19:11:20 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
if (state != S_FINISHED)
|
|
|
|
goto top;
|
2013-02-02 12:47:53 -05:00
|
|
|
|
2013-05-03 07:42:23 -04:00
|
|
|
/* Clean up */
|
|
|
|
if (terminate)
|
|
|
|
copies = 1;
|
|
|
|
|
2014-01-22 09:10:34 -05:00
|
|
|
INFO("Print complete (%d copies remaining)\n", copies - 1);
|
2013-05-02 20:15:55 -04:00
|
|
|
|
|
|
|
if (copies && --copies) {
|
|
|
|
state = S_IDLE;
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
|
2014-04-20 11:57:26 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-01-19 17:10:21 -05:00
|
|
|
}
|
|
|
|
|
2018-04-29 14:07:08 -04:00
|
|
|
static int kodak1400_query_markers(void *vctx, struct marker **markers, int *count)
|
|
|
|
{
|
|
|
|
struct kodak1400_ctx *ctx = vctx;
|
|
|
|
|
|
|
|
*markers = &ctx->marker;
|
|
|
|
*count = 1;
|
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-18 21:05:33 -04:00
|
|
|
/* Exported */
|
2013-07-18 23:39:36 -04:00
|
|
|
#define USB_VID_KODAK 0x040A
|
|
|
|
#define USB_PID_KODAK_1400 0x4022
|
|
|
|
#define USB_PID_KODAK_805 0x4034
|
2016-11-04 15:44:02 -04:00
|
|
|
#define USB_VID_MITSU 0x06D3
|
|
|
|
#define USB_PID_MITSU_3020D 0x038B
|
|
|
|
#define USB_PID_MITSU_3020DA 0x03AA
|
2013-07-18 23:39:36 -04:00
|
|
|
|
|