2013-01-19 17:10:21 -05:00
|
|
|
/*
|
|
|
|
* Kodak Professional 1400 print assister
|
|
|
|
*
|
|
|
|
* (c) 2013 Solomon Peachy <pizza@shaftnet.org>
|
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
|
|
|
*
|
|
|
|
* http://git.shaftnet.org/git/gitweb.cgi?p=selphy_print.git
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2013-05-02 20:15:55 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2013-07-17 19:57:20 -04:00
|
|
|
#define VERSION "0.20"
|
2013-07-14 20:18:04 -04:00
|
|
|
#define URI_PREFIX "kodak1400://"
|
2013-06-27 23:02:34 -04:00
|
|
|
|
|
|
|
#include "backend_common.c"
|
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-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
|
|
|
#define CMDBUF_LEN 96
|
|
|
|
#define READBACK_LEN 8
|
|
|
|
|
2013-01-19 21:36:23 -05:00
|
|
|
static uint8_t idle_data[READBACK_LEN] = { 0xe4, 0x72, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
2013-01-19 22:24:58 -05:00
|
|
|
static int send_plane(struct libusb_device_handle *dev, uint8_t endp,
|
|
|
|
uint8_t planeno, uint8_t *planedata,
|
|
|
|
struct kodak1400_hdr *hdr, uint8_t *cmdbuf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
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;
|
|
|
|
|
|
|
|
if ((ret = send_data(dev, endp,
|
|
|
|
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) {
|
2013-01-20 08:13:22 -05:00
|
|
|
temp16 = htons(hdr->columns);
|
2013-01-19 22:26:52 -05:00
|
|
|
memcpy(cmdbuf+7, &temp16, 2);
|
2013-01-20 08:13:22 -05:00
|
|
|
temp16 = htons(hdr->rows);
|
2013-01-19 22:26:52 -05:00
|
|
|
memcpy(cmdbuf+9, &temp16, 2);
|
2013-01-19 22:46:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = send_data(dev, endp,
|
|
|
|
cmdbuf, CMDBUF_LEN)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (planedata) {
|
2013-01-19 22:26:52 -05:00
|
|
|
for (i = 0 ; i < hdr->rows ; i++) {
|
|
|
|
if ((ret = send_data(dev, endp,
|
|
|
|
planedata + i * hdr->columns,
|
|
|
|
hdr->columns)))
|
|
|
|
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;
|
|
|
|
|
|
|
|
if ((ret = send_data(dev, endp,
|
|
|
|
cmdbuf, CMDBUF_LEN)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-08 20:45:46 -04:00
|
|
|
#define UPDATE_SIZE 1552
|
|
|
|
|
|
|
|
static int set_tonecurve(char *fname, libusb_device_handle *dev,
|
|
|
|
uint8_t endp_down, uint8_t endp_up)
|
|
|
|
{
|
|
|
|
uint8_t cmdbuf[8];
|
|
|
|
uint8_t respbuf[64];
|
|
|
|
int ret, num = 0;
|
|
|
|
|
|
|
|
INFO("Set Tone Curve from '%s'\n", fname);
|
|
|
|
|
|
|
|
uint16_t *data = malloc(UPDATE_SIZE);
|
|
|
|
|
|
|
|
/* Read in file */
|
|
|
|
int tc_fd = open(fname, O_RDONLY);
|
|
|
|
if (tc_fd < 0)
|
|
|
|
return -1;
|
|
|
|
if (read(tc_fd, data, UPDATE_SIZE) != UPDATE_SIZE)
|
|
|
|
return -2;
|
|
|
|
close(tc_fd);
|
|
|
|
|
|
|
|
/* Byteswap data to printer's format */
|
2013-07-08 21:53:52 -04:00
|
|
|
for (ret = 0; ret < (UPDATE_SIZE-16)/2 ; ret++) {
|
2013-07-08 20:45:46 -04:00
|
|
|
data[ret] = cpu_to_le16(be16_to_cpu(data[ret]));
|
|
|
|
}
|
|
|
|
/* Null-terminate */
|
|
|
|
memset(((uint8_t*)data)+UPDATE_SIZE-16, 0x0, 16);
|
|
|
|
|
|
|
|
/* Clear tables */
|
|
|
|
memset(cmdbuf, 0, sizeof(cmdbuf));
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0xa2;
|
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, 2)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ret = libusb_bulk_transfer(dev, endp_up,
|
|
|
|
respbuf,
|
|
|
|
sizeof(respbuf),
|
|
|
|
&num,
|
|
|
|
5000);
|
|
|
|
|
|
|
|
if (ret < 0 || (num != 8)) {
|
|
|
|
ERROR("Failure to receive data from printer (libusb error %d: (%d/%d from 0x%02x))\n", ret, num, (int)sizeof(respbuf), endp_up);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (respbuf[1] != 0x01) {
|
|
|
|
ERROR("Received unexpected response\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
cmdbuf[5] = 0x10; /* 06 10 == UPDATE_SIZE */
|
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, 6)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Send the payload over */
|
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
(uint8_t *) data, UPDATE_SIZE))) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the response */
|
|
|
|
ret = libusb_bulk_transfer(dev, endp_up,
|
|
|
|
respbuf,
|
|
|
|
sizeof(respbuf),
|
|
|
|
&num,
|
|
|
|
5000);
|
|
|
|
|
|
|
|
if (ret < 0 || (num != 8)) {
|
|
|
|
ERROR("Failure to receive data from printer (libusb error %d: (%d/%d from 0x%02x))\n", ret, num, (int)sizeof(respbuf), endp_up);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (respbuf[1] != 0x00) {
|
|
|
|
ERROR("Received unexpected response\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-19 17:10:21 -05:00
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct libusb_context *ctx;
|
|
|
|
struct libusb_device **list;
|
|
|
|
struct libusb_device_handle *dev;
|
|
|
|
struct libusb_config_descriptor *config;
|
|
|
|
|
|
|
|
uint8_t endp_up = 0;
|
|
|
|
uint8_t endp_down = 0;
|
|
|
|
|
2013-01-19 21:36:23 -05:00
|
|
|
uint16_t temp16;
|
|
|
|
|
2013-01-19 17:10:21 -05:00
|
|
|
int data_fd = fileno(stdin);
|
|
|
|
|
2013-01-19 19:11:20 -05:00
|
|
|
int i, num;
|
2013-01-19 17:10:21 -05:00
|
|
|
int claimed;
|
|
|
|
|
2013-07-08 20:45:46 -04:00
|
|
|
int query_only = 0;
|
2013-01-19 17:10:21 -05:00
|
|
|
int ret = 0;
|
|
|
|
int iface = 0;
|
|
|
|
int found = -1;
|
2013-05-02 20:15:55 -04:00
|
|
|
int copies = 1;
|
2013-01-19 17:10:21 -05:00
|
|
|
char *uri = getenv("DEVICE_URI");;
|
|
|
|
char *use_serno = NULL;
|
|
|
|
|
|
|
|
struct kodak1400_hdr hdr;
|
2013-01-19 19:11:20 -05:00
|
|
|
uint8_t *plane_r, *plane_g, *plane_b, *cmdbuf;
|
|
|
|
|
|
|
|
uint8_t rdbuf[READBACK_LEN], rdbuf2[READBACK_LEN];
|
|
|
|
int last_state = -1, state = S_IDLE;
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2013-07-17 19:57:20 -04:00
|
|
|
DEBUG("Kodak 1400/805 CUPS backend version " VERSION "/" BACKEND_VERSION " \n");
|
2013-06-30 07:28:51 -04:00
|
|
|
|
2013-01-19 17:10:21 -05:00
|
|
|
/* Cmdline help */
|
|
|
|
if (argc < 2) {
|
2013-07-08 20:45:46 -04:00
|
|
|
DEBUG("Usage:\n\t%s [ infile | - ]\n\t%s job user title num-copies options [ filename ]\n\t%s [ -stc filename ] \n\n",
|
|
|
|
argv[0], argv[0], argv[0]);
|
2013-01-19 17:10:21 -05:00
|
|
|
libusb_init(&ctx);
|
2013-07-17 23:39:31 -04:00
|
|
|
find_and_enumerate(ctx, &list, NULL, P_KODAK_1400_805, 1);
|
2013-01-19 17:10:21 -05:00
|
|
|
libusb_free_device_list(list, 1);
|
|
|
|
libusb_exit(ctx);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Are we running as a CUPS backend? */
|
|
|
|
if (uri) {
|
2013-05-02 20:15:55 -04:00
|
|
|
if (argv[4])
|
|
|
|
copies = atoi(argv[4]);
|
2013-01-19 17:10:21 -05:00
|
|
|
if (argv[6]) { /* IOW, is it specified? */
|
|
|
|
data_fd = open(argv[6], O_RDONLY);
|
|
|
|
if (data_fd < 0) {
|
|
|
|
perror("ERROR:Can't open input file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 12:47:53 -05:00
|
|
|
/* Ensure we're using BLOCKING I/O */
|
|
|
|
i = fcntl(data_fd, F_GETFL, 0);
|
|
|
|
if (i < 0) {
|
|
|
|
perror("ERROR:Can't open input");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
i &= ~O_NONBLOCK;
|
|
|
|
i = fcntl(data_fd, F_SETFL, 0);
|
|
|
|
if (i < 0) {
|
|
|
|
perror("ERROR:Can't open input");
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-01-19 17:10:21 -05:00
|
|
|
/* Start parsing URI 'selphy://PID/SERIAL' */
|
|
|
|
if (strncmp(URI_PREFIX, uri, strlen(URI_PREFIX))) {
|
|
|
|
ERROR("Invalid URI prefix (%s)\n", uri);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
use_serno = strchr(uri, '=');
|
|
|
|
if (!use_serno || !*(use_serno+1)) {
|
|
|
|
ERROR("Invalid URI (%s)\n", uri);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
use_serno++;
|
|
|
|
} else {
|
2013-07-17 19:47:47 -04:00
|
|
|
use_serno = getenv("DEVICE");
|
|
|
|
|
2013-07-08 20:45:46 -04:00
|
|
|
if (!strcmp("-stc", argv[1])) {
|
|
|
|
query_only = 1;
|
|
|
|
goto skip_read;
|
|
|
|
}
|
2013-07-17 19:47:47 -04:00
|
|
|
|
2013-01-19 17:10:21 -05:00
|
|
|
/* Open Input File */
|
|
|
|
if (strcmp("-", argv[1])) {
|
|
|
|
data_fd = open(argv[1], O_RDONLY);
|
|
|
|
if (data_fd < 0) {
|
|
|
|
perror("ERROR:Can't open input file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 20:15:55 -04:00
|
|
|
/* Ignore SIGPIPE */
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2013-05-03 07:42:23 -04:00
|
|
|
signal(SIGTERM, sigterm_handler);
|
2013-05-02 20:15:55 -04:00
|
|
|
|
2013-01-19 17:10:21 -05:00
|
|
|
/* Read in then validate header */
|
|
|
|
read(data_fd, &hdr, sizeof(hdr));
|
|
|
|
if (hdr.hdr[0] != 'P' ||
|
|
|
|
hdr.hdr[1] != 'G' ||
|
|
|
|
hdr.hdr[2] != 'H' ||
|
|
|
|
hdr.hdr[3] != 'D') {
|
|
|
|
ERROR("Unrecognized data format!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
hdr.planesize = le32_to_cpu(hdr.planesize);
|
|
|
|
hdr.rows = le16_to_cpu(hdr.rows);
|
2013-01-19 19:11:20 -05:00
|
|
|
hdr.columns = le16_to_cpu(hdr.columns);
|
2013-01-19 17:10:21 -05:00
|
|
|
|
|
|
|
/* Set up plane data */
|
2013-01-19 19:11:20 -05:00
|
|
|
cmdbuf = malloc(CMDBUF_LEN);
|
2013-01-19 17:10:21 -05:00
|
|
|
plane_r = malloc(hdr.planesize);
|
|
|
|
plane_g = malloc(hdr.planesize);
|
|
|
|
plane_b = malloc(hdr.planesize);
|
2013-01-19 19:11:20 -05:00
|
|
|
if (!cmdbuf || !plane_r || !plane_g || !plane_b) {
|
2013-01-19 17:10:21 -05:00
|
|
|
ERROR("Memory allocation failure!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (i = 0 ; i < hdr.rows ; i++) {
|
|
|
|
int j;
|
2013-02-02 12:47:53 -05:00
|
|
|
int remain;
|
2013-01-19 17:10:21 -05:00
|
|
|
uint8_t *ptr;
|
|
|
|
for (j = 0 ; j < 3 ; j++) {
|
|
|
|
if (j == 0)
|
2013-01-19 23:10:09 -05:00
|
|
|
ptr = plane_r + i * hdr.columns;
|
2013-02-02 12:47:53 -05:00
|
|
|
else if (j == 1)
|
2013-01-19 19:11:20 -05:00
|
|
|
ptr = plane_g + i * hdr.columns;
|
2013-02-02 12:47:53 -05:00
|
|
|
else if (j == 2)
|
2013-01-19 23:10:09 -05:00
|
|
|
ptr = plane_b + i * hdr.columns;
|
|
|
|
|
2013-02-02 12:47:53 -05:00
|
|
|
remain = hdr.columns;
|
|
|
|
do {
|
|
|
|
ret = read(data_fd, ptr, remain);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Read failed (%d/%d/%d) (%d/%d @ %d)\n",
|
|
|
|
ret, remain, hdr.columns,
|
|
|
|
i, hdr.rows, j);
|
|
|
|
perror("ERROR: Read failed");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
ptr += ret;
|
|
|
|
remain -= ret;
|
|
|
|
} while (remain);
|
2013-01-19 17:10:21 -05:00
|
|
|
}
|
|
|
|
}
|
2013-05-02 20:15:55 -04:00
|
|
|
close(data_fd); /* We're done reading! */
|
2013-01-19 17:10:21 -05:00
|
|
|
|
2013-07-08 20:45:46 -04:00
|
|
|
skip_read:
|
2013-01-19 17:10:21 -05:00
|
|
|
/* Libusb setup */
|
|
|
|
libusb_init(&ctx);
|
2013-07-17 23:39:31 -04:00
|
|
|
found = find_and_enumerate(ctx, &list, use_serno, P_KODAK_1400_805, 0);
|
2013-01-19 17:10:21 -05:00
|
|
|
|
|
|
|
if (found == -1) {
|
2013-05-04 07:52:22 -04:00
|
|
|
ERROR("Printer open failure (No suitable printers found!)\n");
|
2013-01-19 17:10:21 -05:00
|
|
|
ret = 3;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = libusb_open(list[found], &dev);
|
|
|
|
if (ret) {
|
2013-05-04 07:52:22 -04:00
|
|
|
ERROR("Printer open failure (Need to be root?) (%d)\n", ret);
|
2013-01-19 17:10:21 -05:00
|
|
|
ret = 4;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
claimed = libusb_kernel_driver_active(dev, iface);
|
|
|
|
if (claimed) {
|
|
|
|
ret = libusb_detach_kernel_driver(dev, iface);
|
|
|
|
if (ret) {
|
2013-05-04 07:52:22 -04:00
|
|
|
ERROR("Printer open failure (Could not detach printer from kernel)\n");
|
2013-01-19 17:10:21 -05:00
|
|
|
ret = 4;
|
|
|
|
goto done_close;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = libusb_claim_interface(dev, iface);
|
|
|
|
if (ret) {
|
2013-05-04 07:52:22 -04:00
|
|
|
ERROR("Printer open failure (Could not claim printer interface)\n");
|
2013-01-19 17:10:21 -05:00
|
|
|
ret = 4;
|
|
|
|
goto done_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = libusb_get_active_config_descriptor(list[found], &config);
|
|
|
|
if (ret) {
|
2013-05-04 07:52:22 -04:00
|
|
|
ERROR("Printer open failure (Could not fetch config descriptor)\n");
|
2013-01-19 17:10:21 -05:00
|
|
|
ret = 4;
|
|
|
|
goto done_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < config->interface[0].altsetting[0].bNumEndpoints ; i++) {
|
|
|
|
if ((config->interface[0].altsetting[0].endpoint[i].bmAttributes & 3) == LIBUSB_TRANSFER_TYPE_BULK) {
|
|
|
|
if (config->interface[0].altsetting[0].endpoint[i].bEndpointAddress & LIBUSB_ENDPOINT_IN)
|
|
|
|
endp_up = config->interface[0].altsetting[0].endpoint[i].bEndpointAddress;
|
|
|
|
else
|
|
|
|
endp_down = config->interface[0].altsetting[0].endpoint[i].bEndpointAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-08 20:45:46 -04:00
|
|
|
if (query_only) {
|
|
|
|
if (!strcmp("-stc", argv[1]))
|
|
|
|
set_tonecurve(argv[2], dev, endp_down, endp_up);
|
|
|
|
goto done_claimed;
|
|
|
|
}
|
|
|
|
|
2013-01-19 19:11:20 -05:00
|
|
|
/* Time for the main processing loop */
|
|
|
|
|
|
|
|
top:
|
2013-07-16 23:19:04 -04:00
|
|
|
if (state != last_state) {
|
|
|
|
DEBUG("last_state %d new %d\n", last_state, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send Status Query */
|
2013-01-19 19:11:20 -05:00
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x72;
|
|
|
|
|
2013-01-19 22:17:33 -05:00
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2013-01-19 19:11:20 -05:00
|
|
|
goto done_claimed;
|
|
|
|
|
|
|
|
/* Read in the printer status */
|
|
|
|
ret = libusb_bulk_transfer(dev, endp_up,
|
|
|
|
rdbuf,
|
|
|
|
READBACK_LEN,
|
|
|
|
&num,
|
|
|
|
2000);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
2013-05-04 07:52:22 -04:00
|
|
|
ERROR("Failure to receive data from printer (libusb error %d: (%d/%d from 0x%02x))\n", ret, num, READBACK_LEN, endp_up);
|
2013-01-19 19:11:20 -05:00
|
|
|
ret = 4;
|
|
|
|
goto done_claimed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(rdbuf, rdbuf2, READBACK_LEN)) {
|
|
|
|
DEBUG("readback: %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
|
|
|
rdbuf[0], rdbuf[1], rdbuf[2], rdbuf[3],
|
|
|
|
rdbuf[4], rdbuf[5], rdbuf[6], rdbuf[7]);
|
|
|
|
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-01-19 19:11:20 -05:00
|
|
|
fflush(stderr);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-01-19 22:17:33 -05:00
|
|
|
if ((ret = send_data(dev, endp_down,
|
2013-05-02 20:15:55 -04:00
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2013-01-19 21:36:23 -05:00
|
|
|
goto done_claimed;
|
|
|
|
|
|
|
|
/* Send page setup */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x5a;
|
|
|
|
cmdbuf[2] = 0x53;
|
2013-06-27 23:02:34 -04:00
|
|
|
temp16 = be16_to_cpu(hdr.columns);
|
2013-01-19 21:36:23 -05:00
|
|
|
memcpy(cmdbuf+3, &temp16, 2);
|
2013-06-27 23:02:34 -04:00
|
|
|
temp16 = be16_to_cpu(hdr.rows);
|
2013-01-19 21:36:23 -05:00
|
|
|
memcpy(cmdbuf+5, &temp16, 2);
|
|
|
|
|
2013-01-19 22:17:33 -05:00
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2013-01-19 21:36:23 -05:00
|
|
|
goto done_claimed;
|
|
|
|
|
2013-01-19 21:54:18 -05:00
|
|
|
/* Send lamination toggle? */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x59;
|
2013-01-27 11:35:32 -05:00
|
|
|
cmdbuf[2] = hdr.matte; // ???
|
2013-01-19 21:54:18 -05:00
|
|
|
|
2013-01-19 22:17:33 -05:00
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2013-01-19 21:54:18 -05:00
|
|
|
goto done_claimed;
|
|
|
|
|
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;
|
2013-02-03 10:34:42 -05:00
|
|
|
cmdbuf[2] = hdr.laminate;
|
2013-01-19 21:54:18 -05:00
|
|
|
|
2013-01-19 22:17:33 -05:00
|
|
|
if (send_data(dev, endp_down,
|
|
|
|
cmdbuf, CMDBUF_LEN))
|
2013-01-19 21:54:18 -05:00
|
|
|
goto done_claimed;
|
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;
|
|
|
|
cmdbuf[2] = hdr.lam_strength;
|
2013-01-19 19:11:20 -05:00
|
|
|
|
2013-01-19 22:17:33 -05:00
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2013-01-19 21:36:23 -05:00
|
|
|
goto done_claimed;
|
|
|
|
|
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;
|
|
|
|
cmdbuf[2] = hdr.unk1; // ???
|
|
|
|
|
2013-01-19 22:17:33 -05:00
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2013-01-19 21:54:18 -05:00
|
|
|
goto done_claimed;
|
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");
|
2013-01-19 22:24:58 -05:00
|
|
|
if ((ret = send_plane(dev, endp_down,
|
|
|
|
1, plane_b, &hdr, cmdbuf)))
|
2013-01-19 21:44:58 -05:00
|
|
|
goto done_claimed;
|
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");
|
2013-01-19 22:24:58 -05:00
|
|
|
if ((ret = send_plane(dev, endp_down,
|
|
|
|
2, plane_g, &hdr, cmdbuf)))
|
|
|
|
goto done_claimed;
|
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");
|
2013-01-19 22:24:58 -05:00
|
|
|
if ((ret = send_plane(dev, endp_down,
|
|
|
|
3, plane_r, &hdr, cmdbuf)))
|
2013-01-19 21:44:58 -05:00
|
|
|
goto done_claimed;
|
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)) {
|
|
|
|
if (hdr.laminate)
|
|
|
|
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");
|
2013-01-19 22:26:52 -05:00
|
|
|
if ((ret = send_plane(dev, endp_down,
|
|
|
|
4, NULL, &hdr, cmdbuf)))
|
2013-01-19 21:44:58 -05:00
|
|
|
goto done_claimed;
|
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;
|
|
|
|
|
2013-01-19 22:17:33 -05:00
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, CMDBUF_LEN)))
|
2013-01-19 21:44:58 -05:00
|
|
|
goto done_claimed;
|
|
|
|
|
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;
|
|
|
|
|
2013-05-02 20:15:55 -04:00
|
|
|
INFO("Print complete (%d remaining)\n", copies - 1);
|
|
|
|
|
|
|
|
if (copies && --copies) {
|
|
|
|
state = S_IDLE;
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done printing */
|
|
|
|
INFO("All printing done\n");
|
2013-02-02 12:49:02 -05:00
|
|
|
ret = 0;
|
|
|
|
|
2013-01-19 17:10:21 -05:00
|
|
|
done_claimed:
|
|
|
|
libusb_release_interface(dev, iface);
|
|
|
|
|
|
|
|
done_close:
|
2013-07-16 18:34:48 -04:00
|
|
|
#if 0
|
2013-01-19 17:10:21 -05:00
|
|
|
if (claimed)
|
|
|
|
libusb_attach_kernel_driver(dev, iface);
|
2013-07-16 18:34:48 -04:00
|
|
|
#endif
|
2013-01-19 17:10:21 -05:00
|
|
|
libusb_close(dev);
|
|
|
|
done:
|
|
|
|
if (plane_r)
|
|
|
|
free(plane_r);
|
|
|
|
if (plane_b)
|
|
|
|
free(plane_b);
|
|
|
|
if (plane_g)
|
|
|
|
free(plane_g);
|
2013-01-19 19:11:20 -05:00
|
|
|
if (cmdbuf)
|
|
|
|
free(cmdbuf);
|
2013-01-19 17:10:21 -05:00
|
|
|
|
|
|
|
libusb_free_device_list(list, 1);
|
|
|
|
libusb_exit(ctx);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-02 07:34:53 -05:00
|
|
|
/* Kodak 1400/805 data format
|
2013-01-19 17:10:21 -05:00
|
|
|
|
|
|
|
Spool file consists of 36-byte header followed by row-interleaved BGR data.
|
|
|
|
Native printer resolution is 2560 pixels per row, and 3010 or 3612 rows.
|
|
|
|
|
|
|
|
Header:
|
|
|
|
|
|
|
|
50 47 48 44 "PGHD"
|
2013-06-29 10:37:38 -04:00
|
|
|
XX XX Number of columns, Little endian. Fixed at 2560.
|
2013-01-19 17:10:21 -05:00
|
|
|
00 00 NULL
|
2013-01-19 19:11:20 -05:00
|
|
|
XX XX Number of rows, Little Endian
|
2013-01-19 17:10:21 -05:00
|
|
|
00 00 NULL
|
|
|
|
XX XX XX XX Number of bytes per plane, Little Endian
|
|
|
|
00 00 00 00 NULL
|
2013-02-02 07:34:53 -05:00
|
|
|
XX 00 Glossy, 01 Matte (Note: Kodak805 only supports Glossy)
|
2013-01-19 19:11:20 -05:00
|
|
|
XX 01 to laminate, 00 to not.
|
|
|
|
01 Unkown, always set to 01
|
2013-01-19 17:10:21 -05:00
|
|
|
XX Lamination Strength:
|
|
|
|
|
|
|
|
3c Glossy
|
|
|
|
28 Matte +5
|
|
|
|
2e Matte +4
|
|
|
|
34 Matte +3
|
|
|
|
3a Matte +2
|
|
|
|
40 Matte +1
|
|
|
|
46 Matte
|
|
|
|
52 Matte -1
|
|
|
|
5e Matte -2
|
|
|
|
6a Matte -3
|
|
|
|
76 Matte -4
|
|
|
|
82 Matte -5
|
|
|
|
|
|
|
|
00 00 00 00 00 00 00 00 00 00 00 00 NULL
|
|
|
|
|
2013-01-19 19:11:20 -05:00
|
|
|
************************************************************************
|
|
|
|
|
2013-02-02 07:34:53 -05:00
|
|
|
The data format actually sent to the Kodak 1400 is rather different.
|
2013-01-19 19:11:20 -05:00
|
|
|
|
|
|
|
All commands are null-padded to 96 bytes.
|
|
|
|
All readback values are 8 bytes long.
|
|
|
|
|
|
|
|
Multi-byte numbers are sent BIG ENDIAN.
|
|
|
|
|
|
|
|
Image data is sent via planes, one scanline per URB.
|
|
|
|
|
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 00 00 # Idle response
|
|
|
|
|
|
|
|
<-- 1b 00 # Reset/attention?
|
|
|
|
<-- 1b 5a 53 0a 00 0b c2 # Setup (ie hdr.columns and hdr.rows)
|
2013-02-03 10:34:42 -05:00
|
|
|
<-- 1b 59 01 # ?? hdr.matte ?
|
|
|
|
<-- 1b 60 XX # hdr.lamination
|
|
|
|
<-- 1b 62 XX # hdr.lam_strength
|
|
|
|
<-- 1b 61 01 # ?? hdr.unk1 ?
|
2013-01-19 19:11:20 -05:00
|
|
|
|
2013-01-19 21:52:02 -05:00
|
|
|
<-- 1b 5a 54 01 00 00 00 0a 00 0b c2 # start of plane 1 data
|
2013-01-19 19:11:20 -05:00
|
|
|
<-- row 1
|
|
|
|
<-- row 2
|
|
|
|
<-- row last
|
|
|
|
|
|
|
|
<-- 1b 74 01 50 # ??
|
|
|
|
|
2013-06-29 10:37:38 -04:00
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 50 59 # Printing plane 1
|
|
|
|
[ repeats until...]
|
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 40 00 50 59 # Paper loaded?
|
|
|
|
[ repeats until...]
|
2013-01-19 19:11:20 -05:00
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 50 59 # Printing plane 1
|
|
|
|
[ repeats until...]
|
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 00 00 # Idle response
|
|
|
|
|
|
|
|
<-- 1b 74 00 50 # ??
|
2013-01-19 21:52:02 -05:00
|
|
|
<-- 1b 5a 54 02 00 00 00 0a 00 0b c2 # start of plane 2 data
|
2013-01-19 19:11:20 -05:00
|
|
|
<-- row 1
|
|
|
|
<-- row 2
|
|
|
|
<-- row last
|
|
|
|
<-- 1b 74 01 50 # ??
|
|
|
|
|
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 50 4d # Printing plane 2
|
|
|
|
[ repeats until...]
|
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 00 00 # Idle response
|
|
|
|
|
|
|
|
<-- 1b 74 00 50 # ??
|
2013-01-19 21:52:02 -05:00
|
|
|
<-- 1b 5a 54 03 00 00 00 0a 00 0b c2 # start of plane 3 data
|
2013-01-19 19:11:20 -05:00
|
|
|
<-- row 1
|
|
|
|
<-- row 2
|
|
|
|
<-- row last
|
|
|
|
<-- 1b 74 01 50 # ??
|
|
|
|
|
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 50 43 # Printing plane 3
|
|
|
|
[ repeats until...]
|
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 00 00 # Idle response
|
|
|
|
|
2013-02-03 10:34:42 -05:00
|
|
|
## this block is only present if lamination is used
|
|
|
|
|
2013-01-19 19:11:20 -05:00
|
|
|
<-- 1b 74 00 50 # ??
|
|
|
|
<-- 1b 5a 54 04 # start of lamination
|
|
|
|
<-- 1b 74 01 50 # ??
|
|
|
|
|
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 50 50 # Laminating
|
|
|
|
[ repeats until...]
|
|
|
|
<-- 1b 72 # Status query
|
|
|
|
--> e4 72 00 00 00 00 00 00 # Idle response
|
|
|
|
|
2013-02-03 10:34:42 -05:00
|
|
|
## end lamination block
|
|
|
|
|
2013-01-19 19:11:20 -05:00
|
|
|
<-- 1b 74 00 50 # ??
|
|
|
|
|
|
|
|
[[ DONE ]]
|
|
|
|
|
2013-06-29 10:37:38 -04:00
|
|
|
Other readback codes seen:
|
|
|
|
|
|
|
|
e4 72 00 00 10 00 50 59 -- ???
|
|
|
|
e4 72 00 00 10 01 50 59 -- ???
|
|
|
|
e4 72 00 00 00 04 50 59 -- media red blink, error red [media too small for image ?]
|
|
|
|
e4 72 00 00 02 00 50 59 -- media off, error red. [out of paper]
|
|
|
|
e4 72 00 00 02 01 00 00 -- media off, error red. [out of paper]
|
|
|
|
e4 72 00 00 02 00 00 00 -- media off, error red. [out of paper]
|
2013-07-17 19:57:20 -04:00
|
|
|
e4 72 00 00 02 00 50 50 -- media on, error red. [paper jam while laminating]
|
2013-06-29 10:37:38 -04:00
|
|
|
|
2013-01-19 19:11:20 -05:00
|
|
|
*********************************************
|
|
|
|
Calibration data:
|
|
|
|
|
|
|
|
<-- 1b a2 # ?? Reset cal tables?
|
|
|
|
--> 00 01 00 00 00 00 00 00
|
|
|
|
|
2013-01-27 11:35:32 -05:00
|
|
|
<-- 1b a0 02 03 06 10 # 06 10 == 1552 bytes aka the CAL data.
|
|
|
|
<-- cal data
|
|
|
|
|
|
|
|
[[ Data is organized as three blocks of 512 bytes followed by
|
|
|
|
16 NULL bytes.
|
|
|
|
|
|
|
|
Each block appears to be 256 entries of 16-bit LE data,
|
|
|
|
so each input value is translated into a 16-bit number in the printer.
|
|
|
|
|
|
|
|
Assuming blocks are ordered BGR.
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
2013-01-19 19:11:20 -05:00
|
|
|
--> 00 00 00 00 00 00 00 00
|
|
|
|
|
2013-01-19 17:10:21 -05:00
|
|
|
*/
|