selphy_print/backend_shinkos1245.c

1570 lines
38 KiB
C
Raw Normal View History

/*
* Shinko/Sinfonia CHC-S1245 CUPS backend -- libusb-1.0 version
*
* (c) 2013-2015 Solomon Peachy <pizza@shaftnet.org>
*
* Development of this backend was sponsored by:
*
* LiveLink Technology [ www.livelinktechnology.net ]
*
* 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
* 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>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include "backend_common.h"
/* Structure of printjob header. All fields are LITTLE ENDIAN */
struct s1245_printjob_hdr {
uint32_t len1; /* Fixed at 0x10 */
uint32_t model; /* Equal to the printer model (eg '1245' or '2145' decimal) */
uint32_t unk2; /* Null */
uint32_t unk3; /* Fixed at 0x01 */
uint32_t len2; /* Fixed at 0x64 */
uint32_t unk5; /* Null */
uint32_t media; /* Fixed at 0x10 */
uint32_t unk6; /* Null */
uint32_t method; /* Print Method */
uint32_t mode; /* Print Mode */
uint32_t unk7; /* Null */
int32_t mattedepth; /* 0x7fffffff for glossy, 0x00 +- 25 for matte */
uint32_t dust; /* Dust control */
uint32_t columns;
uint32_t rows;
uint32_t copies;
uint32_t unk10; /* Null */
uint32_t unk11; /* Null */
uint32_t unk12; /* Null */
uint32_t unk13; /* 0xceffffff */
uint32_t unk14; /* Null */
uint32_t unk15; /* 0xceffffff */
uint32_t dpi; /* Fixed at '300' (decimal) */
uint32_t unk16; /* 0xceffffff */
uint32_t unk17; /* Null */
uint32_t unk18; /* 0xceffffff */
uint32_t unk19; /* Null */
uint32_t unk20; /* Null */
uint32_t unk21; /* Null */
} __attribute__((packed));
/* Printer data structures */
struct shinkos1245_cmd_hdr {
uint8_t prefix; /* 0x03 */
uint8_t hdr[4]; /* 0x1b 0x43 0x48 0x43 */
} __attribute__((packed));
/* Get Printer ID */
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) */
uint8_t reserved[8];
} __attribute__((packed));
/* Set Printer ID -- Returns Status */
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));
/* Print -- Returns Status */
struct shinkos1245_cmd_print {
struct shinkos1245_cmd_hdr hdr;
uint8_t cmd[2]; /* 0x0a 0x00 */
uint8_t id; /* 1-255 */
uint16_t count; /* # Copies in BCD, 1-9999 */
uint16_t columns; /* Fixed at 2448 */
uint16_t rows;
uint8_t media; /* Fixed at 0x10 */
uint8_t mode; /* dust removal and lamination mode */
uint8_t combo; /* aka "print method" in the spool file */
} __attribute__((packed));
/* Get Status */
struct shinkos1245_cmd_getstatus {
struct shinkos1245_cmd_hdr hdr;
uint8_t cmd[1]; /* 0x03 */
uint8_t pad[10];
} __attribute__((packed));
struct shinkos1245_resp_status {
uint8_t code;
uint8_t print_status;
struct {
uint8_t status1;
uint32_t status2; /* BE */
uint8_t error;
} state;
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;
uint8_t control_flag; // 0x00 == epson, 0x01 == cypress
} counters;
struct {
uint16_t main_boot;
uint16_t main_control;
uint16_t dsp_boot;
uint16_t dsp_control;
} versions;
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 */
uint16_t bank2_spec; /* BE */
} counters2;
uint8_t curve_status;
} __attribute__((packed));
enum {
CMD_CODE_OK = 1,
CMD_CODE_BAD = 2,
};
enum {
STATUS_PRINTING = 1,
STATUS_IDLE = 2,
};
enum {
STATE_STATUS1_STANDBY = 1,
STATE_STATUS1_ERROR = 2,
STATE_STATUS1_WAIT = 3,
};
2015-02-08 18:59:26 -05:00
#define STATE_STANDBY_STATUS2 0x0
enum {
WAIT_STATUS2_INIT = 0,
WAIT_STATUS2_RIBBON = 1,
WAIT_STATUS2_THERMAL = 2,
WAIT_STATUS2_OPERATING = 3,
WAIT_STATUS2_BUSY = 4,
};
#define ERROR_STATUS2_CTRL_CIRCUIT (1<<31)
#define ERROR_STATUS2_MECHANISM_CTRL (1<<30)
#define ERROR_STATUS2_SENSOR (1<<13)
#define ERROR_STATUS2_COVER_OPEN (1<<12)
#define ERROR_STATUS2_TEMP_SENSOR (1<<9)
#define ERROR_STATUS2_PAPER_JAM (1<<8)
#define ERROR_STATUS2_PAPER_EMPTY (1<<6)
#define ERROR_STATUS2_RIBBON_ERR (1<<4)
enum {
CTRL_CIR_ERROR_EEPROM1 = 0x01,
CTRL_CIR_ERROR_EEPROM2 = 0x02,
CTRL_CIR_ERROR_DSP = 0x04,
CTRL_CIR_ERROR_CRC_MAIN = 0x06,
CTRL_CIR_ERROR_DL_MAIN = 0x07,
CTRL_CIR_ERROR_CRC_DSP = 0x08,
CTRL_CIR_ERROR_DL_DSP = 0x09,
CTRL_CIR_ERROR_ASIC = 0x0a,
CTRL_CIR_ERROR_DRAM = 0x0b,
CTRL_CIR_ERROR_DSPCOMM = 0x29,
};
enum {
MECH_ERROR_HEAD_UP = 0x01,
MECH_ERROR_HEAD_DOWN = 0x02,
MECH_ERROR_MAIN_PINCH_UP = 0x03,
MECH_ERROR_MAIN_PINCH_DOWN = 0x04,
MECH_ERROR_SUB_PINCH_UP = 0x05,
MECH_ERROR_SUB_PINCH_DOWN = 0x06,
MECH_ERROR_FEEDIN_PINCH_UP = 0x07,
MECH_ERROR_FEEDIN_PINCH_DOWN = 0x08,
MECH_ERROR_FEEDOUT_PINCH_UP = 0x09,
MECH_ERROR_FEEDOUT_PINCH_DOWN = 0x0a,
MECH_ERROR_CUTTER_LR = 0x0b,
MECH_ERROR_CUTTER_RL = 0x0c,
};
enum {
SENSOR_ERROR_CUTTER = 0x05,
SENSOR_ERROR_HEAD_DOWN = 0x09,
SENSOR_ERROR_HEAD_UP = 0x0a,
SENSOR_ERROR_MAIN_PINCH_DOWN = 0x0b,
SENSOR_ERROR_MAIN_PINCH_UP = 0x0c,
SENSOR_ERROR_FEED_PINCH_DOWN = 0x0d,
SENSOR_ERROR_FEED_PINCH_UP = 0x0e,
SENSOR_ERROR_EXIT_PINCH_DOWN = 0x0f,
SENSOR_ERROR_EXIT_PINCH_UP = 0x10,
SENSOR_ERROR_LEFT_CUTTER = 0x11,
SENSOR_ERROR_RIGHT_CUTTER = 0x12,
SENSOR_ERROR_CENTER_CUTTER = 0x13,
SENSOR_ERROR_UPPER_CUTTER = 0x14,
SENSOR_ERROR_PAPER_FEED_COVER = 0x15,
};
enum {
TEMP_SENSOR_ERROR_HEAD_HIGH = 0x01,
TEMP_SENSOR_ERROR_HEAD_LOW = 0x02,
TEMP_SENSOR_ERROR_ENV_HIGH = 0x03,
TEMP_SENSOR_ERROR_ENV_LOW = 0x04,
};
enum {
COVER_OPEN_ERROR_UPPER = 0x01,
COVER_OPEN_ERROR_LOWER = 0x02,
};
enum {
PAPER_EMPTY_ERROR = 0x00,
};
enum {
RIBBON_ERROR = 0x00,
};
enum {
CURVE_TABLE_STATUS_INITIAL = 0x00,
CURVE_TABLE_STATUS_USERSET = 0x01,
CURVE_TABLE_STATUS_CURRENT = 0x02,
};
// XXX Paper jam has 0x01 -> 0xff as error codes
/* Query media info */
struct shinkos1245_cmd_getmedia {
struct shinkos1245_cmd_hdr hdr;
uint8_t cmd[1]; /* 0x1a/0x2a/0x3a for A/B/C */
uint8_t pad[10];
} __attribute__((packed));
2015-02-08 18:59:26 -05:00
struct shinkos1245_mediadesc {
uint8_t code; /* Fixed at 0x10 */
uint16_t columns; /* BE */
uint16_t rows; /* BE */
uint8_t type; /* MEDIA_TYPE_* */
uint8_t print_type; /* aka "print method" in the spool file */
uint8_t reserved[3];
} __attribute__((packed));
struct shinkos1245_resp_media {
uint8_t code;
uint8_t reserved[5];
2015-02-08 18:59:26 -05:00
uint8_t count; /* 1-5? */
struct shinkos1245_mediadesc data[5];
} __attribute__((packed));
enum {
MEDIA_TYPE_UNKNOWN = 0x00,
MEDIA_TYPE_PAPER = 0x01,
};
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 */
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));
/* Reset printer -- returns Status */
struct shinkos1245_cmd_reset {
struct shinkos1245_cmd_hdr hdr;
uint8_t cmd[1]; /* 0xc0 */
uint8_t pad[10];
} __attribute__((packed));
/* Tone curve manipulation -- returns Status */
2015-02-08 18:59:26 -05:00
struct shinkos1245_cmd_tone {
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));
enum {
TONE_TABLE_STANDARD = 0,
TONE_TABLE_USER = 1,
TONE_TABLE_CURRENT = 2,
};
enum {
PARAM_TABLE_STANDARD = 1,
PARAM_TABLE_FINE = 2,
};
2015-02-18 20:54:57 -05:00
#define TONE_CURVE_SIZE 1536
#define TONE_CURVE_DATA_BLOCK_SIZE 64
/* Query Model information */
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));
/* Query and Set Matte info, returns a Matte response */
struct shinkos1245_cmd_getmatte {
struct shinkos1245_cmd_hdr hdr;
uint8_t cmd[1]; /* 0x20 */
uint8_t mode; /* Fixed at 0x00 */
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 */
int8_t level; /* -25->+25 */
uint8_t pad[8];
} __attribute__((packed));
struct shinkos1245_resp_matte {
uint8_t code;
uint8_t mode;
uint8_t level;
uint8_t reserved[3];
} __attribute__((packed));
#define MATTE_MODE_MATTE 0x00
/* Private data stucture */
struct shinkos1245_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
uint8_t jobid;
uint8_t fast_return;
struct s1245_printjob_hdr hdr;
struct shinkos1245_mediadesc medias[15];
int num_medias;
uint8_t *databuf;
int datalen;
2015-02-18 20:54:57 -05:00
int tonecurve;
};
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;
/* Write command */
if ((ret = send_data(ctx->dev, ctx->endp_down,
cmd, cmd_len)))
return (ret < 0) ? ret : -99;
/* 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;
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;
}
return 0;
}
static int shinkos1245_get_media(struct shinkos1245_ctx *ctx)
{
struct shinkos1245_cmd_getmedia cmd;
struct shinkos1245_resp_media resp;
int i, j;
int ret, num;
shinkos1245_fill_hdr(&cmd.hdr);
memset(cmd.pad, 0, sizeof(cmd.pad));
for (i = 1 ; i <= 3 ; i++) {
cmd.cmd[0] = 0x0a || (i << 4);
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
&resp, sizeof(resp), &num);
if (ret < 0) {
ERROR("Failed to execute GET_MEDIA command\n");
return ret;
}
if (resp.code != CMD_CODE_OK) {
ERROR("Bad return code on GET_MEDIA (%02x)\n",
resp.code);
return -99;
}
/* Store media info */
for (j = 0; j < resp.count ; j++) {
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;
ctx->medias[ctx->num_medias].print_type = resp.data[j].print_type;
ctx->num_medias++;
}
if (resp.count < 5)
break;
}
return 0;
}
static int shinkos1245_get_printerid(struct shinkos1245_ctx *ctx,
struct shinkos1245_resp_getid *resp)
{
struct shinkos1245_cmd_getstatus cmd;
int ret, num;
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;
}
return 0;
}
static int shinkos1245_set_printerid(struct shinkos1245_ctx *ctx,
char *id)
{
struct shinkos1245_cmd_setid cmd;
struct shinkos1245_resp_status sts;
int ret, num;
int i;
shinkos1245_fill_hdr(&cmd.hdr);
cmd.cmd[0] = 0x0a;
cmd.cmd[1] = 0x22;
for (i = 0 ; i < (int)sizeof(cmd.data) ; i++) {
if (*id)
cmd.data[i] = (uint8_t) *id;
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;
}
return 0;
}
static int shinkos1245_canceljob(struct shinkos1245_ctx *ctx,
int id)
{
struct shinkos1245_cmd_canceljob cmd;
struct shinkos1245_resp_status sts;
int ret, num;
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;
}
return 0;
}
static int shinkos1245_set_matte(struct shinkos1245_ctx *ctx,
int intensity)
{
struct shinkos1245_cmd_setmatte cmd;
struct shinkos1245_resp_status sts;
int ret, num;
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) {
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;
}
return 0;
}
/* Structure dumps */
static char *shinkos1245_status_str(struct shinkos1245_resp_status *resp)
2015-02-08 18:59:26 -05:00
{
switch(resp->state.status1) {
2015-02-08 18:59:26 -05:00
case STATE_STATUS1_STANDBY:
return "Standby (Ready)";
2015-02-08 18:59:26 -05:00
case STATE_STATUS1_WAIT:
switch (resp->state.status2) {
2015-02-08 18:59:26 -05:00
case WAIT_STATUS2_INIT:
return "Wait (Initializing)";
2015-02-08 18:59:26 -05:00
case WAIT_STATUS2_RIBBON:
return "Wait (Ribbon Winding)";
2015-02-08 18:59:26 -05:00
case WAIT_STATUS2_THERMAL:
return "Wait (Thermal Protection)";
2015-02-08 18:59:26 -05:00
case WAIT_STATUS2_OPERATING:
return "Wait (Operating)";
2015-02-08 18:59:26 -05:00
case WAIT_STATUS2_BUSY:
return "Wait (Busy)";
2015-02-08 18:59:26 -05:00
default:
return "Wait (Unknown)";
2015-02-08 18:59:26 -05:00
}
case STATE_STATUS1_ERROR:
switch (resp->state.status2) {
2015-02-08 18:59:26 -05:00
case ERROR_STATUS2_CTRL_CIRCUIT:
switch (resp->state.error) {
case CTRL_CIR_ERROR_EEPROM1:
return "Error (EEPROM1)";
case CTRL_CIR_ERROR_EEPROM2:
return "Error (EEPROM2)";
case CTRL_CIR_ERROR_DSP:
return "Error (DSP)";
case CTRL_CIR_ERROR_CRC_MAIN:
return "Error (Main CRC)";
case CTRL_CIR_ERROR_DL_MAIN:
return "Error (Main Download)";
case CTRL_CIR_ERROR_CRC_DSP:
return "Error (DSP CRC)";
case CTRL_CIR_ERROR_DL_DSP:
return "Error (DSP Download)";
case CTRL_CIR_ERROR_ASIC:
return "Error (ASIC)";
case CTRL_CIR_ERROR_DRAM:
return "Error (DRAM)";
case CTRL_CIR_ERROR_DSPCOMM:
return "Error (DSP Communincation)";
default:
return "Error (Unknown Circuit)";
}
2015-02-08 18:59:26 -05:00
case ERROR_STATUS2_MECHANISM_CTRL:
switch (resp->state.error) {
case MECH_ERROR_HEAD_UP:
return "Error (Head Up Mechanism)";
case MECH_ERROR_HEAD_DOWN:
return "Error (Head Down Mechanism)";
case MECH_ERROR_MAIN_PINCH_UP:
return "Error (Main Pinch Up Mechanism)";
case MECH_ERROR_MAIN_PINCH_DOWN:
return "Error (Main Pinch Down Mechanism)";
case MECH_ERROR_SUB_PINCH_UP:
return "Error (Sub Pinch Up Mechanism)";
case MECH_ERROR_SUB_PINCH_DOWN:
return "Error (Sub Pinch Down Mechanism)";
case MECH_ERROR_FEEDIN_PINCH_UP:
return "Error (Feed-in Pinch Up Mechanism)";
case MECH_ERROR_FEEDIN_PINCH_DOWN:
return "Error (Feed-in Pinch Down Mechanism)";
case MECH_ERROR_FEEDOUT_PINCH_UP:
return "Error (Feed-out Pinch Up Mechanism)";
case MECH_ERROR_FEEDOUT_PINCH_DOWN:
return "Error (Feed-out Pinch Down Mechanism)";
case MECH_ERROR_CUTTER_LR:
return "Error (Left->Right Cutter)";
case MECH_ERROR_CUTTER_RL:
return "Error (Right->Left Cutter)";
default:
return "Error (Unknown Mechanism)";
}
2015-02-08 18:59:26 -05:00
case ERROR_STATUS2_SENSOR:
switch (resp->state.error) {
case SENSOR_ERROR_CUTTER:
return "Error (Cutter Sensor)";
case SENSOR_ERROR_HEAD_DOWN:
return "Error (Head Down Sensor)";
case SENSOR_ERROR_HEAD_UP:
return "Error (Head Up Sensor)";
case SENSOR_ERROR_MAIN_PINCH_DOWN:
return "Error (Main Pinch Down Sensor)";
case SENSOR_ERROR_MAIN_PINCH_UP:
return "Error (Main Pinch Up Sensor)";
case SENSOR_ERROR_FEED_PINCH_DOWN:
return "Error (Feed Pinch Down Sensor)";
case SENSOR_ERROR_FEED_PINCH_UP:
return "Error (Feed Pinch Up Sensor)";
case SENSOR_ERROR_EXIT_PINCH_DOWN:
return "Error (Exit Pinch Up Sensor)";
case SENSOR_ERROR_EXIT_PINCH_UP:
return "Error (Exit Pinch Up Sensor)";
case SENSOR_ERROR_LEFT_CUTTER:
return "Error (Left Cutter Sensor)";
case SENSOR_ERROR_RIGHT_CUTTER:
return "Error (Right Cutter Sensor)";
case SENSOR_ERROR_CENTER_CUTTER:
return "Error (Center Cutter Sensor)";
case SENSOR_ERROR_UPPER_CUTTER:
return "Error (Upper Cutter Sensor)";
case SENSOR_ERROR_PAPER_FEED_COVER:
return "Error (Paper Feed Cover)";
default:
return "Error (Unknown Sensor)";
}
2015-02-08 18:59:26 -05:00
case ERROR_STATUS2_COVER_OPEN:
switch (resp->state.error) {
case COVER_OPEN_ERROR_UPPER:
return "Error (Upper Cover Open)";
case COVER_OPEN_ERROR_LOWER:
return "Error (Lower Cover Open)";
default:
return "Error (Unknown Cover Open)";
}
2015-02-08 18:59:26 -05:00
case ERROR_STATUS2_TEMP_SENSOR:
switch (resp->state.error) {
case TEMP_SENSOR_ERROR_HEAD_HIGH:
return "Error (Head Temperature High)";
case TEMP_SENSOR_ERROR_HEAD_LOW:
return "Error (Head Temperature Low)";
case TEMP_SENSOR_ERROR_ENV_HIGH:
return "Error (Environmental Temperature High)";
case TEMP_SENSOR_ERROR_ENV_LOW:
return "Error (Environmental Temperature Low)";
default:
return "Error (Unknown Temperature)";
}
2015-02-08 18:59:26 -05:00
case ERROR_STATUS2_PAPER_JAM:
return "Error (Paper Jam)";
2015-02-08 18:59:26 -05:00
case ERROR_STATUS2_PAPER_EMPTY:
return "Error (Paper Empty)";
2015-02-08 18:59:26 -05:00
case ERROR_STATUS2_RIBBON_ERR:
return "Error (Ribbon)";
2015-02-08 18:59:26 -05:00
default:
return "Error (Unknown)";
2015-02-08 18:59:26 -05:00
}
default:
return "Unknown!";
}
}
static void shinkos1245_dump_status(struct shinkos1245_resp_status *sts)
{
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:
detail = "Unknown";
2015-02-08 18:59:26 -05:00
break;
}
INFO("Printer Status: %s\n", detail);
/* Byteswap */
sts->state.status2 = be32_to_cpu(sts->state.status2);
INFO("Printer State: %s # %02x %08x %02x\n",
shinkos1245_status_str(sts),
sts->state.status1, sts->state.status2, sts->state.error);
2015-02-08 18:59:26 -05:00
INFO("Counters:\n");
INFO("\tLifetime : %d\n", be32_to_cpu(sts->counters.lifetime));
INFO("\tThermal Head : %d\n", be32_to_cpu(sts->counters.maint));
INFO("\tMedia : %d\n", be32_to_cpu(sts->counters.media));
INFO("\tCutter : %d\n", be32_to_cpu(sts->counters.cutter));
INFO("Versions:\n");
INFO("\tUSB Boot : %d\n", sts->counters.ver_boot);
INFO("\tUSB Control : %d\n", sts->counters.ver_ctrl);
INFO("\tMain Boot : %d\n", be16_to_cpu(sts->versions.main_boot));
INFO("\tMain Control: %d\n", be16_to_cpu(sts->versions.main_control));
INFO("\tDSP Boot : %d\n", be16_to_cpu(sts->versions.dsp_boot));
INFO("\tDSP Control : %d\n", be16_to_cpu(sts->versions.dsp_control));
// INFO("USB TypeFlag: %02x\n", sts->counters.control_flag);
INFO("Bank 1 ID: %d\n", sts->counters2.bank1_id);
INFO("\tPrints: %d/%d (%d complete)\n",
sts->counters2.bank1_remain, sts->counters2.bank1_spec,
sts->counters2.bank1_complete);
INFO("Bank 2 ID: %d\n", sts->counters2.bank2_id);
INFO("\tPrints: %d/%d (%d complete)\n",
sts->counters2.bank2_remain, sts->counters2.bank2_spec,
sts->counters2.bank2_complete);
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);
}
static void shinkos1245_dump_media(struct shinkos1245_mediadesc *medias,
int count)
{
int i;
INFO("Supported print sizes: %d\n", count);
for (i = 0 ; i < count ; i++) {
INFO("\t %02x: %04d*%04d (%02x/%02d)\n",
medias[i].print_type,
medias[i].columns,
medias[i].rows,
medias[i].code, medias[i].type);
}
}
2015-02-18 20:54:57 -05:00
static int get_tonecurve(struct shinkos1245_ctx *ctx, int type, int table, char *fname)
{
int ret, num, remaining;
uint8_t *data, *ptr;
struct shinkos1245_cmd_tone cmd;
struct shinkos1245_resp_status resp;
INFO("Dump %d/%d Tone Curve to '%s'\n", type, table, fname); // XXX
/* 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;
cmd.cmd2[1] = 0x72;
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 */
remaining = TONE_CURVE_SIZE;
data = malloc(remaining);
if (!data) {
ERROR("Out of memory!\n");
return -11;
}
ptr = data;
while(remaining) {
/* Issue a tone_data message */
cmd.cmd2[1] = 0x20;
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
&resp, sizeof(resp), &num);
if (ret < 0) {
ERROR("Failed to execute TONE_DATA command\n");
return ret;
}
if (resp.code != CMD_CODE_OK) {
ERROR("Bad return code on TONE_DATA (%02x)\n",
resp.code);
return -99;
}
/* And read back 64-bytes of data */
ret = read_data(ctx->dev, ctx->endp_up,
ptr, TONE_CURVE_DATA_BLOCK_SIZE, &num);
if (num != TONE_CURVE_DATA_BLOCK_SIZE)
return -99;
if (ret < 0)
return ret;
ptr += num;
}
/* Issue a tone_end */
cmd.cmd2[1] = 0x65;
ret = shinkos1245_do_cmd(ctx, &cmd, sizeof(cmd),
&resp, sizeof(resp), &num);
if (ret < 0) {
ERROR("Failed to execute TONE_END command\n");
return ret;
}
if (resp.code != CMD_CODE_OK) {
ERROR("Bad return code on TONE_END (%02x)\n",
resp.code);
return -99;
}
/* Open file and write it out */
{
int tc_fd = open(fname, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
if (tc_fd < 0) {
return tc_fd;
}
ret = write(tc_fd, data, TONE_CURVE_SIZE);
if (ret < 0)
return ret;
close(tc_fd);
}
free(data);
return 0;
}
static int set_tonecurve(struct shinkos1245_ctx *ctx, int type, int table, char *fname)
{
int ret, num, remaining;
uint8_t *data, *ptr;
struct shinkos1245_cmd_tone cmd;
struct shinkos1245_resp_status resp;
INFO("Read %d/%d Tone Curve from '%s'\n", type, table, fname); // XXX
/* Allocate space */
remaining = TONE_CURVE_SIZE;
data = malloc(remaining);
if (!data) {
ERROR("Out of memory!\n");
return -11;
}
ptr = data;
/* Open file and read it in */
{
int tc_fd = open(fname, O_RDONLY);
if (tc_fd < 0) {