2015-02-08 12:01:28 -05:00
|
|
|
/*
|
|
|
|
* Shinko/Sinfonia CHC-S1245 CUPS backend -- libusb-1.0 version
|
|
|
|
*
|
2019-02-17 21:51:40 -05:00
|
|
|
* (c) 2015-2019 Solomon Peachy <pizza@shaftnet.org>
|
2015-02-08 12:01:28 -05:00
|
|
|
*
|
2015-02-21 10:53:53 -05:00
|
|
|
* Low-level documentation was provided by Sinfonia, Inc. Thank you!
|
2015-02-08 12:01:28 -05:00
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
|
|
|
*
|
|
|
|
* http://git.shaftnet.org/cgit/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
|
2020-01-17 16:50:56 -05:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2015-02-08 12:01:28 -05:00
|
|
|
*
|
2017-11-17 13:34:26 -05:00
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
*
|
2015-02-08 12:01:28 -05:00
|
|
|
*/
|
|
|
|
|
2015-08-13 21:09:56 -04:00
|
|
|
#define BACKEND shinkos1245_backend
|
|
|
|
|
2015-02-08 12:01:28 -05:00
|
|
|
#include "backend_common.h"
|
2019-05-13 10:29:00 -04:00
|
|
|
#include "backend_sinfonia.h"
|
2015-02-08 12:01:28 -05:00
|
|
|
|
2015-02-08 13:17:33 -05:00
|
|
|
/* Printer data structures */
|
|
|
|
struct shinkos1245_cmd_hdr {
|
|
|
|
uint8_t prefix; /* 0x03 */
|
|
|
|
uint8_t hdr[4]; /* 0x1b 0x43 0x48 0x43 */
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
/* Get Printer ID */
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_getid {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[1]; /* 0x12 */
|
|
|
|
uint8_t pad[11];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct shinkos1245_resp_getid {
|
|
|
|
uint8_t id; /* 0x00 */
|
|
|
|
uint8_t data[23]; /* padded with 0x20 (space) */
|
2015-08-25 18:09:51 -04:00
|
|
|
uint8_t reserved[8]; // XXX actual serial number?
|
2015-02-08 13:17:33 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
/* Set Printer ID -- Returns Status */
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_setid {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[2]; /* 0x0a 0x22 */
|
|
|
|
uint8_t id; /* 0x00 */
|
|
|
|
uint8_t data[23]; /* pad with 0x20 (space) */
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
/* Print -- Returns Status */
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_print {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[2]; /* 0x0a 0x00 */
|
|
|
|
uint8_t id; /* 1-255 */
|
2015-02-09 21:43:55 -05:00
|
|
|
uint16_t count; /* # Copies in BCD, 1-9999 */
|
2015-08-20 23:13:09 -04:00
|
|
|
uint16_t columns; /* Fixed at 2446 */
|
2015-02-08 13:17:33 -05:00
|
|
|
uint16_t rows;
|
|
|
|
uint8_t media; /* Fixed at 0x10 */
|
|
|
|
uint8_t mode; /* dust removal and lamination mode */
|
2015-02-08 15:33:17 -05:00
|
|
|
uint8_t combo; /* aka "print method" in the spool file */
|
2015-02-08 13:17:33 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
/* Get Status */
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_getstatus {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[1]; /* 0x03 */
|
2017-07-10 20:15:56 -04:00
|
|
|
uint8_t pad[10];
|
2015-02-08 13:17:33 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct shinkos1245_resp_status {
|
|
|
|
uint8_t code;
|
|
|
|
uint8_t print_status;
|
2015-02-08 15:33:17 -05:00
|
|
|
struct {
|
|
|
|
uint8_t status1;
|
2015-02-10 22:39:18 -05:00
|
|
|
uint32_t status2; /* BE */
|
2015-02-08 15:33:17 -05:00
|
|
|
uint8_t error;
|
2017-01-18 05:14:13 -05:00
|
|
|
} __attribute__((packed)) state;
|
2015-02-08 13:17:33 -05:00
|
|
|
struct {
|
|
|
|
uint32_t lifetime; /* BE */
|
|
|
|
uint32_t maint; /* BE */
|
|
|
|
uint32_t media; /* BE */
|
|
|
|
uint32_t cutter; /* BE */
|
|
|
|
uint8_t reserved;
|
|
|
|
uint8_t ver_boot;
|
2015-02-08 18:59:26 -05:00
|
|
|
uint8_t ver_ctrl;
|
2015-02-08 15:33:17 -05:00
|
|
|
uint8_t control_flag; // 0x00 == epson, 0x01 == cypress
|
2017-01-18 05:14:13 -05:00
|
|
|
} __attribute__((packed)) counters;
|
2015-02-08 13:17:33 -05:00
|
|
|
struct {
|
|
|
|
uint16_t main_boot;
|
|
|
|
uint16_t main_control;
|
|
|
|
uint16_t dsp_boot;
|
2015-05-14 18:08:59 -04:00
|
|
|
uint16_t dsp_control;
|
2017-01-18 05:14:13 -05:00
|
|
|
} __attribute__((packed)) versions;
|
2015-02-08 13:17:33 -05:00
|
|
|
struct {
|
|
|
|
uint8_t bank1_id;
|
|
|
|
uint8_t bank2_id;
|
|
|
|
uint16_t bank1_remain; /* BE */
|
|
|
|
uint16_t bank1_complete; /* BE */
|
|
|
|
uint16_t bank1_spec; /* BE */
|
|
|
|
uint16_t bank2_remain; /* BE */
|
|
|
|
uint16_t bank2_complete; /* BE */
|
2015-05-14 18:08:59 -04:00
|
|
|
uint16_t bank2_spec; /* BE */
|
2017-01-18 05:14:13 -05:00
|
|
|
} __attribute__((packed)) counters2;
|
2015-02-08 13:17:33 -05:00
|
|
|
uint8_t curve_status;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
/* Query media info */
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_getmedia {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[1]; /* 0x1a/0x2a/0x3a for A/B/C */
|
2015-05-14 18:08:59 -04:00
|
|
|
uint8_t pad[10];
|
2015-02-08 13:17:33 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-08-20 22:41:58 -04:00
|
|
|
#define NUM_MEDIAS 5 /* Maximum per message */
|
|
|
|
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_resp_media {
|
|
|
|
uint8_t code;
|
2017-01-18 14:42:20 -05:00
|
|
|
uint8_t reserved[6];
|
2015-02-08 18:59:26 -05:00
|
|
|
uint8_t count; /* 1-5? */
|
2019-05-14 22:31:24 -04:00
|
|
|
struct sinfonia_mediainfo_item data[NUM_MEDIAS];
|
2015-02-08 13:17:33 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PRINT_TYPE_STANDARD = 0x00,
|
|
|
|
PRINT_TYPE_8x5_2up = 0x01,
|
|
|
|
PRINT_TYPE_8x4_2up = 0x02,
|
|
|
|
PRINT_TYPE_8x6_8x4 = 0x03,
|
|
|
|
PRINT_TYPE_8x5 = 0x04,
|
|
|
|
PRINT_TYPE_8x4 = 0x05,
|
|
|
|
PRINT_TYPE_8x6 = 0x06,
|
|
|
|
PRINT_TYPE_8x6_2up = 0x07,
|
|
|
|
PRINT_TYPE_8x4_3up = 0x08,
|
|
|
|
PRINT_TYPE_8x8 = 0x09,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Cancel Job -- returns Status */
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_canceljob {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[1]; /* 0x13 */
|
|
|
|
uint8_t id; /* 1-255 */
|
|
|
|
uint8_t pad[9];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
/* Reset printer -- returns Status */
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_reset {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[1]; /* 0xc0 */
|
|
|
|
uint8_t pad[10];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
/* Tone curve manipulation -- returns Status */
|
2015-02-08 18:59:26 -05:00
|
|
|
struct shinkos1245_cmd_tone {
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[1]; /* 0xc0 */
|
|
|
|
uint8_t tone[4]; /* 0x54 0x4f 0x4e 0x45 */
|
|
|
|
uint8_t cmd2[1]; /* 0x72/0x77/0x65/0x20 for read/write/end/data */
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint8_t tone_table;
|
|
|
|
uint8_t param_table;
|
|
|
|
uint8_t pad[3];
|
|
|
|
} read_write;
|
|
|
|
struct {
|
|
|
|
uint8_t pad[5];
|
|
|
|
} end_data;
|
|
|
|
};
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-18 20:54:57 -05:00
|
|
|
#define TONE_CURVE_DATA_BLOCK_SIZE 64
|
2017-07-10 20:15:56 -04:00
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
/* Query Model information */
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_getmodel {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[1]; /* 0x02 */
|
|
|
|
uint8_t pad[10];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct shinkos1245_resp_getmodel {
|
|
|
|
uint8_t vendor_id[4];
|
|
|
|
uint8_t product_id[4];
|
|
|
|
uint8_t strings[40];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
/* Query and Set Matte info, returns a Matte response */
|
2015-02-08 13:17:33 -05:00
|
|
|
struct shinkos1245_cmd_getmatte {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[1]; /* 0x20 */
|
2015-05-14 18:08:59 -04:00
|
|
|
uint8_t mode; /* Fixed at 0x00 */
|
2015-02-08 13:17:33 -05:00
|
|
|
uint8_t pad[9];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct shinkos1245_cmd_setmatte {
|
|
|
|
struct shinkos1245_cmd_hdr hdr;
|
|
|
|
uint8_t cmd[1]; /* 0x21 */
|
|
|
|
uint8_t mode; /* Fixed at 0x00 */
|
2015-05-14 18:08:59 -04:00
|
|
|
int8_t level; /* -25->+25 */
|
2015-02-08 13:17:33 -05:00
|
|
|
uint8_t pad[8];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct shinkos1245_resp_matte {
|
|
|
|
uint8_t code;
|
|
|
|
uint8_t mode;
|
2015-02-18 21:20:59 -05:00
|
|
|
int8_t level;
|
2018-01-10 08:10:13 -05:00
|
|
|
uint8_t reserved[4];
|
2015-02-08 13:17:33 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-02-08 15:33:17 -05:00
|
|
|
#define MATTE_MODE_MATTE 0x00
|
2019-05-14 22:31:24 -04:00
|
|
|
#define MAX_MEDIA_ITEMS 15
|
2015-02-08 13:17:33 -05:00
|
|
|
|
2017-05-05 08:06:28 -04:00
|
|
|
/* Private data structure */
|
2015-02-08 19:48:17 -05:00
|
|
|
struct shinkos1245_ctx {
|
|
|
|
struct libusb_device_handle *dev;
|
|
|
|
uint8_t endp_up;
|
|
|
|
uint8_t endp_down;
|
2015-08-12 22:56:29 -04:00
|
|
|
int type;
|
2019-12-17 13:18:11 -05:00
|
|
|
int iface;
|
2015-08-12 22:56:29 -04:00
|
|
|
|
2015-02-08 19:48:17 -05:00
|
|
|
uint8_t jobid;
|
|
|
|
|
2019-05-14 22:31:24 -04:00
|
|
|
struct sinfonia_mediainfo_item medias[MAX_MEDIA_ITEMS];
|
2015-02-08 19:48:17 -05:00
|
|
|
int num_medias;
|
2016-10-12 16:16:51 -04:00
|
|
|
int media_8x12;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2019-12-17 13:18:11 -05:00
|
|
|
char serial[32];
|
|
|
|
char fwver[32];
|
|
|
|
|
2018-04-27 15:40:09 -04:00
|
|
|
struct marker marker;
|
|
|
|
|
2015-02-18 20:54:57 -05:00
|
|
|
int tonecurve;
|
2015-02-08 19:48:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
S_IDLE = 0,
|
|
|
|
S_PRINTER_READY_CMD,
|
|
|
|
S_PRINTER_SENT_DATA,
|
|
|
|
S_FINISHED,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-02-08 18:59:26 -05:00
|
|
|
/* Basic printer I/O stuffs */
|
|
|
|
static void shinkos1245_fill_hdr(struct shinkos1245_cmd_hdr *hdr)
|
|
|
|
{
|
|
|
|
hdr->prefix = 0x03;
|
|
|
|
hdr->hdr[0] = 0x1b;
|
|
|
|
hdr->hdr[1] = 0x43;
|
|
|
|
hdr->hdr[2] = 0x48;
|
|
|
|
hdr->hdr[3] = 0x43;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int shinkos1245_do_cmd(struct shinkos1245_ctx *ctx,
|
|
|
|
void *cmd, int cmd_len,
|
|
|
|
void *resp, int resp_len,
|
|
|
|
int *actual_len)
|
|
|
|
{
|
|
|
|
int ret;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-08 18:59:26 -05:00
|
|
|
/* Write command */
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmd, cmd_len)))
|
|
|
|
return (ret < 0) ? ret : -99;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-08 18:59:26 -05:00
|
|
|
/* Read response */
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
resp, resp_len, actual_len);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (*actual_len < resp_len) {
|
|
|
|
ERROR("Short read! (%d/%d))\n", *actual_len, resp_len);
|
|
|
|
return -99;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int shinkos1245_get_status(struct shinkos1245_ctx *ctx,
|
|
|
|
struct shinkos1245_resp_status *resp)
|
|
|
|
{
|
|
|
|
struct shinkos1245_cmd_getstatus cmd;
|
|
|
|
int ret, num;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-08 18:59:26 -05:00
|
|
|
shinkos1245_fill_hdr(&cmd.hdr);
|
|
|
|
cmd.cmd[0] = 0x03;
|
|
|
|
memset(cmd.pad, 0, sizeof(cmd.pad));
|
|
|
|
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
resp, sizeof(*resp), &num);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Failed to execute GET_STATUS command\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (resp->code != CMD_CODE_OK) {
|
|
|
|
ERROR("Bad return code on GET_STATUS (%02x)\n",
|
|
|
|
resp->code);
|
|
|
|
return -99;
|
|
|
|
}
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2019-05-12 12:55:57 -04:00
|
|
|
/* Byteswap important stuff */
|
|
|
|
resp->state.status2 = be32_to_cpu(resp->state.status2);
|
|
|
|
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2015-02-08 18:59:26 -05:00
|
|
|
}
|
|
|
|
|
2015-02-08 19:48:17 -05:00
|
|
|
static int shinkos1245_get_media(struct shinkos1245_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct shinkos1245_cmd_getmedia cmd;
|
|
|
|
struct shinkos1245_resp_media resp;
|
|
|
|
int i, j;
|
2015-07-04 09:38:59 -04:00
|
|
|
int ret = 0, num;
|
2015-02-08 19:48:17 -05:00
|
|
|
|
|
|
|
shinkos1245_fill_hdr(&cmd.hdr);
|
2015-05-14 18:08:59 -04:00
|
|
|
memset(cmd.pad, 0, sizeof(cmd.pad));
|
2018-01-09 12:50:27 -05:00
|
|
|
ctx->media_8x12 = 0;
|
2015-02-08 19:48:17 -05:00
|
|
|
for (i = 1 ; i <= 3 ; i++) {
|
2017-01-12 18:53:42 -05:00
|
|
|
cmd.cmd[0] = 0x0a | (i << 4);
|
2015-02-08 19:48:17 -05:00
|
|
|
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
&resp, sizeof(resp), &num);
|
|
|
|
if (ret < 0) {
|
2015-02-08 20:19:44 -05:00
|
|
|
ERROR("Failed to execute GET_MEDIA command\n");
|
2015-02-08 19:48:17 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (resp.code != CMD_CODE_OK) {
|
2015-02-08 20:19:44 -05:00
|
|
|
ERROR("Bad return code on GET_MEDIA (%02x)\n",
|
2015-02-08 19:48:17 -05:00
|
|
|
resp.code);
|
|
|
|
return -99;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store media info */
|
2018-01-08 21:51:13 -05:00
|
|
|
for (j = 0; j < NUM_MEDIAS && ctx->num_medias < resp.count ; j++) {
|
2015-02-08 19:48:17 -05:00
|
|
|
ctx->medias[ctx->num_medias].code = resp.data[j].code;
|
|
|
|
ctx->medias[ctx->num_medias].columns = be16_to_cpu(resp.data[j].columns);
|
|
|
|
ctx->medias[ctx->num_medias].rows = be16_to_cpu(resp.data[j].rows);
|
|
|
|
ctx->medias[ctx->num_medias].type = resp.data[j].type;
|
2019-05-14 22:31:24 -04:00
|
|
|
ctx->medias[ctx->num_medias].method = resp.data[j].method;
|
2015-02-08 19:48:17 -05:00
|
|
|
ctx->num_medias++;
|
2018-01-09 07:21:41 -05:00
|
|
|
|
|
|
|
if (ctx->medias[i].rows >= 3636)
|
|
|
|
ctx->media_8x12 = 1;
|
2015-02-08 19:48:17 -05:00
|
|
|
}
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2018-01-08 20:35:44 -05:00
|
|
|
/* Once we've parsed them all.. we're done */
|
2018-01-08 21:51:13 -05:00
|
|
|
if (ctx->num_medias == resp.count)
|
2015-02-08 19:48:17 -05:00
|
|
|
break;
|
2015-05-14 18:08:59 -04:00
|
|
|
}
|
2015-07-04 09:38:59 -04:00
|
|
|
return ret;
|
2015-02-08 19:48:17 -05:00
|
|
|
}
|
|
|
|
|
2015-02-08 20:19:44 -05:00
|
|
|
static int shinkos1245_get_printerid(struct shinkos1245_ctx *ctx,
|
|
|
|
struct shinkos1245_resp_getid *resp)
|
|
|
|
{
|
2015-08-25 18:09:51 -04:00
|
|
|
struct shinkos1245_cmd_getid cmd;
|
2015-02-08 20:19:44 -05:00
|
|
|
int ret, num;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-08 20:19:44 -05:00
|
|
|
shinkos1245_fill_hdr(&cmd.hdr);
|
|
|
|
cmd.cmd[0] = 0x12;
|
|
|
|
memset(cmd.pad, 0, sizeof(cmd.pad));
|
|
|
|
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
resp, sizeof(*resp), &num);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Failed to execute GET_PRINTERID command\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2015-02-08 20:19:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int shinkos1245_set_printerid(struct shinkos1245_ctx *ctx,
|
|
|
|
char *id)
|
|
|
|
{
|
|
|
|
struct shinkos1245_cmd_setid cmd;
|
|
|
|
struct shinkos1245_resp_status sts;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-08 20:19:44 -05:00
|
|
|
int ret, num;
|
|
|
|
int i;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-08 20:19:44 -05:00
|
|
|
shinkos1245_fill_hdr(&cmd.hdr);
|
|
|
|
cmd.cmd[0] = 0x0a;
|
|
|
|
cmd.cmd[1] = 0x22;
|
|
|
|
|
|
|
|
for (i = 0 ; i < (int)sizeof(cmd.data) ; i++) {
|
|
|
|
if (*id)
|
2018-01-09 20:16:41 -05:00
|
|
|
cmd.data[i] = (uint8_t) *id++;
|
2015-02-08 20:19:44 -05:00
|
|
|
else
|
|
|
|
cmd.data[i] = ' ';
|
|
|
|
}
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
&sts, sizeof(sts), &num);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Failed to execute SET_PRINTERID command\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (sts.code != CMD_CODE_OK) {
|
|
|
|
ERROR("Bad return code on SET_PRINTERID command\n");
|
|
|
|
return -99;
|
|
|
|
}
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2015-02-08 20:19:44 -05:00
|
|
|
}
|
|
|
|
|
2015-02-08 20:34:30 -05:00
|
|
|
static int shinkos1245_canceljob(struct shinkos1245_ctx *ctx,
|
|
|
|
int id)
|
|
|
|
{
|
|
|
|
struct shinkos1245_cmd_canceljob cmd;
|
|
|
|
struct shinkos1245_resp_status sts;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-08 20:34:30 -05:00
|
|
|
int ret, num;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-08 20:34:30 -05:00
|
|
|
shinkos1245_fill_hdr(&cmd.hdr);
|
|
|
|
cmd.cmd[0] = 0x13;
|
|
|
|
cmd.id = id;
|
|
|
|
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
&sts, sizeof(sts), &num);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Failed to execute CANCELJOB command\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (sts.code != CMD_CODE_OK) {
|
|
|
|
ERROR("Bad return code on CANCELJOB command\n");
|
|
|
|
return -99;
|
|
|
|
}
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2015-02-08 20:34:30 -05:00
|
|
|
}
|
2015-02-18 21:14:00 -05:00
|
|
|
|
2016-06-28 10:28:42 -04:00
|
|
|
static int shinkos1245_reset(struct shinkos1245_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct shinkos1245_cmd_reset cmd;
|
|
|
|
struct shinkos1245_resp_status sts;
|
|
|
|
|
|
|
|
int ret, num;
|
|
|
|
|
|
|
|
shinkos1245_fill_hdr(&cmd.hdr);
|
|
|
|
cmd.cmd[0] = 0xc0;
|
|
|
|
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
&sts, sizeof(sts), &num);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Failed to execute RESET command\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (sts.code != CMD_CODE_OK) {
|
|
|
|
ERROR("Bad return code on RESET command\n");
|
|
|
|
return -99;
|
|
|
|
}
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2016-06-28 10:28:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 21:04:33 -05:00
|
|
|
static int shinkos1245_set_matte(struct shinkos1245_ctx *ctx,
|
|
|
|
int intensity)
|
|
|
|
{
|
|
|
|
struct shinkos1245_cmd_setmatte cmd;
|
2015-02-18 21:14:00 -05:00
|
|
|
struct shinkos1245_resp_matte sts;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-18 21:04:33 -05:00
|
|
|
int ret, num;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-18 21:04:33 -05:00
|
|
|
shinkos1245_fill_hdr(&cmd.hdr);
|
|
|
|
cmd.cmd[0] = 0x21;
|
|
|
|
cmd.mode = MATTE_MODE_MATTE;
|
|
|
|
cmd.level = intensity;
|
|
|
|
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
&sts, sizeof(sts), &num);
|
|
|
|
if (ret < 0) {
|
2015-02-18 21:14:00 -05:00
|
|
|
ERROR("Failed to execute SET_MATTE command\n");
|
2015-02-18 21:04:33 -05:00
|
|
|
return ret;
|
|
|
|
}
|
2015-02-18 21:14:00 -05:00
|
|
|
if (sts.code == CMD_CODE_OK)
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2015-02-18 21:14:00 -05:00
|
|
|
if (sts.code == CMD_CODE_BAD)
|
|
|
|
return 1;
|
2015-02-18 21:04:33 -05:00
|
|
|
|
2017-07-10 20:15:56 -04:00
|
|
|
ERROR("Bad return code (%02x) on SET_MATTE command\n", sts.code);
|
2015-02-18 21:14:00 -05:00
|
|
|
return -99;
|
2015-02-18 21:04:33 -05:00
|
|
|
}
|
2015-02-08 20:19:44 -05:00
|
|
|
|
2015-02-18 21:20:59 -05:00
|
|
|
static int shinkos1245_get_matte(struct shinkos1245_ctx *ctx,
|
|
|
|
int *intensity)
|
|
|
|
{
|
|
|
|
struct shinkos1245_cmd_getmatte cmd;
|
|
|
|
struct shinkos1245_resp_matte sts;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-18 21:20:59 -05:00
|
|
|
int ret, num;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-18 21:20:59 -05:00
|
|
|
shinkos1245_fill_hdr(&cmd.hdr);
|
|
|
|
cmd.cmd[0] = 0x20;
|
|
|
|
cmd.mode = MATTE_MODE_MATTE;
|
|
|
|
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
&sts, sizeof(sts), &num);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Failed to execute GET_MATTE command\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (sts.code != CMD_CODE_OK) {
|
|
|
|
ERROR("Bad return code (%02x) on GET_MATTE command\n", sts.code);
|
|
|
|
return -99;
|
|
|
|
}
|
|
|
|
*intensity = sts.level;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2019-12-12 07:15:25 -05:00
|
|
|
return CUPS_BACKEND_OK;
|
2015-02-18 21:20:59 -05:00
|
|
|
}
|
|
|
|
|
2015-02-19 21:32:43 -05:00
|
|
|
static char* shinkos1245_tonecurves(int type, int table)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case TONE_TABLE_STANDARD:
|
|
|
|
switch (table) {
|
|
|
|
case PARAM_TABLE_STANDARD:
|
|
|
|
return "Standard/Standard";
|
|
|
|
case PARAM_TABLE_FINE:
|
|
|
|
return "Standard/Fine";
|
|
|
|
default:
|
|
|
|
return "Standard/Unknown";
|
|
|
|
}
|
|
|
|
case TONE_TABLE_USER:
|
|
|
|
switch (table) {
|
|
|
|
case PARAM_TABLE_STANDARD:
|
|
|
|
return "User/Standard";
|
|
|
|
case PARAM_TABLE_FINE:
|
|
|
|
return "User/Fine";
|
|
|
|
default:
|
|
|
|
return "User/Unknown";
|
|
|
|
}
|
|
|
|
case TONE_TABLE_CURRENT:
|
|
|
|
switch (table) {
|
|
|
|
case PARAM_TABLE_STANDARD:
|
|
|
|
return "Current/Standard";
|
|
|
|
case PARAM_TABLE_FINE:
|
|
|
|
return "Current/Fine";
|
|
|
|
default:
|
|
|
|
return "Current/Unknown";
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 14:42:09 -04:00
|
|
|
static void shinkos1245_dump_status(struct shinkos1245_ctx *ctx,
|
|
|
|
struct shinkos1245_resp_status *sts)
|
2015-02-10 22:39:18 -05:00
|
|
|
{
|
|
|
|
char *detail;
|
|
|
|
switch (sts->print_status) {
|
|
|
|
case STATUS_PRINTING:
|
|
|
|
detail = "Printing";
|
|
|
|
break;
|
|
|
|
case STATUS_IDLE:
|
|
|
|
detail = "Idle";
|
2015-02-08 18:59:26 -05:00
|
|
|
break;
|
|
|
|
default:
|
2015-02-10 22:39:18 -05:00
|
|
|
detail = "Unknown";
|
2015-02-08 18:59:26 -05:00
|
|
|
break;
|
|
|
|
}
|
2015-02-10 22:39:18 -05:00
|
|
|
INFO("Printer Status: %s\n", detail);
|
|
|
|
|
|
|
|
/* Byteswap */
|
|
|
|
INFO("Printer State: %s # %02x %08x %02x\n",
|
2019-05-12 12:55:57 -04:00
|
|
|
sinfonia_1x45_status_str(sts->state.status1, sts->state.status2, sts->state.error),
|
2015-02-10 22:39:18 -05:00
|
|
|
sts->state.status1, sts->state.status2, sts->state.error);
|
2015-02-08 18:59:26 -05:00
|
|
|
INFO("Counters:\n");
|
2016-08-21 10:23:00 -04:00
|
|
|
INFO("\tLifetime : %u\n", be32_to_cpu(sts->counters.lifetime));
|
|
|
|
INFO("\tThermal Head : %u\n", be32_to_cpu(sts->counters.maint));
|
|
|
|
INFO("\tMedia : %u\n", be32_to_cpu(sts->counters.media));
|
2018-05-15 14:42:09 -04:00
|
|
|
INFO("\tRemaining : %u\n", ctx->marker.levelmax - be32_to_cpu(sts->counters.media));
|
2016-08-21 10:23:00 -04:00
|
|
|
INFO("\tCutter : %u\n", be32_to_cpu(sts->counters.cutter));
|
2015-02-08 18:59:26 -05:00
|
|
|
INFO("Versions:\n");
|
2016-08-21 10:23:00 -04:00
|
|
|
INFO("\tUSB Boot : %u\n", sts->counters.ver_boot);
|
|
|
|
INFO("\tUSB Control : %u\n", sts->counters.ver_ctrl);
|
|
|
|
INFO("\tMain Boot : %u\n", be16_to_cpu(sts->versions.main_boot));
|
|
|
|
INFO("\tMain Control: %u\n", be16_to_cpu(sts->versions.main_control));
|
|
|
|
INFO("\tDSP Boot : %u\n", be16_to_cpu(sts->versions.dsp_boot));
|
|
|
|
INFO("\tDSP Control : %u\n", be16_to_cpu(sts->versions.dsp_control));
|
2015-02-08 18:59:26 -05:00
|
|
|
|
|
|
|
// INFO("USB TypeFlag: %02x\n", sts->counters.control_flag);
|
|
|
|
|
2016-08-21 10:23:00 -04:00
|
|
|
INFO("Bank 1 ID: %u\n", sts->counters2.bank1_id);
|
2015-08-25 18:09:51 -04:00
|
|
|
INFO("\tPrints: %d/%d complete\n",
|
|
|
|
be16_to_cpu(sts->counters2.bank1_complete),
|
|
|
|
be16_to_cpu(sts->counters2.bank1_spec));
|
2016-08-21 10:23:00 -04:00
|
|
|
INFO("Bank 2 ID: %u\n", sts->counters2.bank2_id);
|
2015-08-25 18:09:51 -04:00
|
|
|
INFO("\tPrints: %d/%d complete\n",
|
|
|
|
be16_to_cpu(sts->counters2.bank2_complete),
|
|
|
|
be16_to_cpu(sts->counters2.bank2_spec));
|
2015-02-08 18:59:26 -05:00
|
|
|
|
|
|
|
switch (sts->curve_status) {
|
|
|
|
case CURVE_TABLE_STATUS_INITIAL:
|
|
|
|
detail = "Initial/Default";
|
|
|
|
break;
|
|
|
|
case CURVE_TABLE_STATUS_USERSET:
|
|
|
|
detail = "User Stored";
|
|
|
|
break;
|
|
|
|
case CURVE_TABLE_STATUS_CURRENT:
|
|
|
|
detail = "Current";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
detail = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
INFO("Tone Curve Status: %s\n", detail);
|
|
|
|
}
|
|
|
|
|
2019-05-14 22:31:24 -04:00
|
|
|
static void shinkos1245_dump_media(struct sinfonia_mediainfo_item *medias,
|
2018-05-15 14:42:09 -04:00
|
|
|
int media_8x12,
|
2015-02-08 19:48:17 -05:00
|
|
|
int count)
|
|
|
|
{
|
|
|
|
int i;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2018-01-09 07:21:41 -05:00
|
|
|
INFO("Loaded media type: %s\n", media_8x12 ? "8x12" : "8x10");
|
2015-02-08 19:48:17 -05:00
|
|
|
INFO("Supported print sizes: %d\n", count);
|
|
|
|
|
|
|
|
for (i = 0 ; i < count ; i++) {
|
2019-05-14 22:31:24 -04:00
|
|
|
INFO("\t %02d: %04u*%04u (%02x/%02u)\n",
|
|
|
|
i,
|
2015-02-08 19:48:17 -05:00
|
|
|
medias[i].columns,
|
|
|
|
medias[i].rows,
|
2019-05-14 22:31:24 -04:00
|
|
|
medias[i].type,
|
|
|
|
medias[i].method);
|
2015-02-08 19:48:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 20:54:57 -05:00
|
|
|
static int get_tonecurve(struct shinkos1245_ctx *ctx, int type, int table, char *fname)
|
|
|
|
{
|
2015-07-04 11:01:10 -04:00
|
|
|
int ret = 0, num, remaining;
|
2015-02-18 20:54:57 -05:00
|
|
|
uint8_t *data, *ptr;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-18 20:54:57 -05:00
|
|
|
struct shinkos1245_cmd_tone cmd;
|
|
|
|
struct shinkos1245_resp_status resp;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-19 21:32:43 -05:00
|
|
|
INFO("Dump %s Tone Curve to '%s'\n", shinkos1245_tonecurves(type, table), fname);
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-18 20:54:57 -05:00
|
|
|
/* Issue a tone_read_start */
|
|
|
|
shinkos1245_fill_hdr(&cmd.hdr);
|
|
|
|
cmd.cmd[0] = 0x0c;
|
|
|
|
cmd.tone[0] = 0x54;
|
|
|
|
cmd.tone[1] = 0x4f;
|
|
|
|
cmd.tone[2] = 0x4e;
|
|
|
|
cmd.tone[3] = 0x45;
|
2015-07-04 09:38:59 -04:00
|
|
|
cmd.cmd2[0] = 0x72;
|
2015-02-18 20:54:57 -05:00
|
|
|
cmd.read_write.tone_table = type;
|
|
|
|
cmd.read_write.param_table = table;
|
|
|
|
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
&resp, sizeof(resp), &num);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Failed to execute TONE_READ command\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (resp.code != CMD_CODE_OK) {
|
|
|
|
ERROR("Bad return code on TONE_READ (%02x)\n",
|
|
|
|
resp.code);
|
|
|
|
return -99;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the data out */
|
2015-05-14 18:08:59 -04:00
|
|
|
remaining = TONE_CURVE_SIZE;
|
2015-02-18 20:54:57 -05:00
|
|
|
data = malloc(remaining);
|
|
|
|
if (!data) {
|
2015-06-23 20:32:41 -04:00
|
|
|
ERROR("Memory Allocation Failure!\n");
|
2015-02-18 20:54:57 -05:00
|
|
|
return -11;
|
|
|
|
}
|
|
|
|
ptr = data;
|
2015-05-14 18:08:59 -04:00
|
|
|
|
|
|
|
while(remaining) {
|
2015-02-18 20:54:57 -05:00
|
|
|
/* Issue a tone_data message */
|
2015-07-04 09:38:59 -04:00
|
|
|
cmd.cmd2[0] = 0x20;
|
2015-02-18 20:54:57 -05:00
|
|
|
|
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
&resp, sizeof(resp), &num);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Failed to execute TONE_DATA command\n");
|
2015-07-04 11:01:10 -04:00
|
|
|
goto done;
|
2015-02-18 20:54:57 -05:00
|
|
|
}
|
|
|
|
if (resp.code != CMD_CODE_OK) {
|
|
|
|
ERROR("Bad return code on TONE_DATA (%02x)\n",
|
|
|
|
resp.code);
|
2015-07-04 11:01:10 -04:00
|
|
|
ret = -99;
|
|
|
|
goto done;
|
2015-02-18 20:54:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* And read back 64-bytes of data */
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
ptr, TONE_CURVE_DATA_BLOCK_SIZE, &num);
|
2015-07-04 11:01:10 -04:00
|
|
|
if (num != TONE_CURVE_DATA_BLOCK_SIZE) {
|
|
|
|
ret = -99;
|
|
|
|
goto done;
|
|
|
|
}
|
2015-02-18 20:54:57 -05:00
|
|
|
if (ret < 0)
|
2015-07-04 11:01:10 -04:00
|
|
|
goto done;
|
2015-02-18 20:54:57 -05:00
|
|
|
ptr += num;
|
2018-04-26 14:45:32 -04:00
|
|
|
remaining -= num;
|
2015-02-18 20:54:57 -05:00
|
|
|
}
|
2015-05-14 18:08:59 -04:00
|
|
|
|
2015-02-18 20:54:57 -05:00
|
|
|
/* Issue a tone_end */
|
2015-07-04 09:38:59 -04:00
|
|
|
cmd.cmd2[0] = 0x65;
|
2015-02-18 20:54:57 -05:00
|
|
|
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
|
|
|
|
&resp, sizeof(resp), &num);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Failed to execute TONE_END command\n");
|
2015-07-04 11:01:10 -04:00
|
|
|
goto done;
|
2015-02-18 20:54:57 -05:00
|
|
|
}
|
|
|
|
if (resp.code != CMD_CODE_OK) {
|
|
|
|
ERROR("Bad return code on TONE_END (%02x)\n",
|
|
|
|
resp.code);
|
2015-07-04 11:01:10 -04:00
|
|
|
ret = -99;
|
|
|
|
goto done;
|
2015-02-18 20:54:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Open file and write it out */
|
|
|
|
{
|
|
|
|
int tc_fd = open(fname, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
|
|
|
|
if (tc_fd < 0) {
|
2015-07-04 11:01:10 -04:00
|
|
|
ret = tc_fd;
|
|
|
|
goto done;
|
2015-02-18 20:54:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = write(tc_fd, data, TONE_CURVE_SIZE);
|
|
|
|
if (ret < 0)
|
2015-07-04 11:01:10 -04:00
|
|
|
goto done;
|
2015-02-18 20:54:57 -05:00
|
|
|
close(tc_fd);
|
|
|
|
}
|
2015-07-04 11:01:10 -04:00
|
|