selphy_print/backend_mitsu70x.c

2658 lines
71 KiB
C
Raw Normal View History

/*
* Mitsubishi CP-D70/D707 Photo Printer CUPS backend -- libusb-1.0 version
*
* (c) 2013-2022 Solomon Peachy <pizza@shaftnet.org>
*
* The latest version of this program can be found at:
*
* https://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, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0+
*
*/
2019-09-28 11:05:42 -04:00
#define BACKEND mitsu70x_backend
2019-09-28 11:05:42 -04:00
#include "backend_common.h"
#include "backend_mitsu.h"
/* Width of the laminate data file */
#define LAMINATE_STRIDE 1864
/* Max size of data chunk sent over */
#define CHUNK_LEN (256*1024)
/* Private data structure */
struct mitsu70x_printjob {
struct dyesub_job_common common;
uint8_t *databuf;
uint32_t datalen;
uint8_t *spoolbuf;
int spoolbuflen;
uint16_t rows;
uint16_t cols;
uint32_t planelen;
uint32_t matte;
int raw_format;
int decks_exact[2]; /* Media is exact match */
int decks_ok[2]; /* Media can be used */
/* These are used only for the image processing */
int sharpen; /* ie mhdr.sharpen - 1 */
int reverse;
const char *laminatefname;
const char *lutfname;
const char *cpcfname;
const char *ecpcfname;
};
struct mitsu70x_ctx {
struct dyesub_connection *conn;
int is_s;
uint16_t jobid;
struct marker marker[2];
uint8_t medias[2];
uint8_t media_subtypes[2];
uint16_t last_l;
uint16_t last_u;
int num_decks;
char serno[7]; /* 6+null */
char fwver[7]; /* 6+null */
struct mitsu_lib lib;
const char *last_cpcfname;
const char *last_ecpcfname;
struct BandImage output;
};
/* Printer data structures */
struct mitsu70x_jobstatus {
uint8_t hdr[4]; /* E4 56 31 30 */
uint16_t jobid; /* BE */
uint16_t mecha_no; /* BE */
uint8_t job_status[4];
uint8_t memory;
uint8_t power;
uint8_t mecha_status[2];
uint8_t temperature;
uint8_t error_status[3];
uint8_t mecha_status_up[2];
uint8_t temperature_up;
uint8_t error_status_up[3];
2014-10-03 20:35:05 -04:00
} __attribute__((packed));
struct mitsu70x_job {
uint16_t id; /* BE */
uint8_t status[4];
2016-12-15 09:37:31 -05:00
} __attribute__((packed));
#define NUM_JOBS 170
struct mitsu70x_jobs {
uint8_t hdr[4]; /* E4 56 31 31 */
struct mitsu70x_job jobs[NUM_JOBS];
} __attribute__((packed));
#define MECHA_STATUS_INIT 0x80
#define MECHA_STATUS_FEED 0x50
#define MECHA_STATUS_LOAD 0x40
#define MECHA_STATUS_LOAD2 0x30
#define MECHA_STATUS_PRINT 0x20
#define MECHA_STATUS_IDLE 0x00
#define JOB_STATUS0_NONE 0x00
#define JOB_STATUS0_DATA 0x10
#define JOB_STATUS0_QUEUE 0x20
#define JOB_STATUS0_PRINT 0x50
#define JOB_STATUS0_ASSIGN 0x70 // XXX undefined.
#define JOB_STATUS0_END 0x80
#define JOB_STATUS1_PRINT_MEDIALOAD 0x10
#define JOB_STATUS1_PRINT_PRE_Y 0x20
#define JOB_STATUS1_PRINT_Y 0x30
#define JOB_STATUS1_PRINT_PRE_M 0x40
#define JOB_STATUS1_PRINT_M 0x50
#define JOB_STATUS1_PRINT_PRE_C 0x60
#define JOB_STATUS1_PRINT_C 0x70
#define JOB_STATUS1_PRINT_PRE_OC 0x80
#define JOB_STATUS1_PRINT_OC 0x90
#define JOB_STATUS1_PRINT_EJECT 0xA0
#define JOB_STATUS1_END_OK 0x00
#define JOB_STATUS1_END_MECHA 0x10 // 0x10...0x7f
#define JOB_STATUS1_END_HEADER 0x80
#define JOB_STATUS1_END_PRINT 0x90
#define JOB_STATUS1_END_INTERRUPT 0xA0
#define JOB_STATUS2_END_HEADER_ERROR 0x00
#define JOB_STATUS2_END_HEADER_MEMORY 0x10
#define JOB_STATUS2_END_PRINT_MEDIA 0x00
#define JOB_STATUS2_END_PRINT_PREVERR 0x10
#define JOB_STATUS2_END_INT_TIMEOUT 0x00
#define JOB_STATUS2_END_INT_CANCEL 0x10
#define JOB_STATUS2_END_INT_DISCON 0x20
/* Error codes */
#define ERROR_STATUS0_NOSTRIPBIN 0x01
#define ERROR_STATUS0_NORIBBON 0x02
#define ERROR_STATUS0_NOPAPER 0x03
#define ERROR_STATUS0_MEDIAMISMATCH 0x04
#define ERROR_STATUS0_RIBBONCNTEND 0x05
#define ERROR_STATUS0_BADRIBBON 0x06
#define ERROR_STATUS0_BADJOBPARAM 0x07
#define ERROR_STATUS0_PAPEREND 0x08
#define ERROR_STATUS0_RIBBONEND 0x09
#define ERROR_STATUS0_DOOROPEN_IDLE 0x0A
#define ERROR_STATUS0_DOOROPEN_PRNT 0x0B
#define ERROR_STATUS0_POWEROFF 0x0C // Powered off during printing..?
#define ERROR_STATUS0_NOMCOP 0x0D
#define ERROR_STATUS0_RIBBONSKIP1 0x0E
#define ERROR_STATUS0_RIBBONSKIP2 0x0F
#define ERROR_STATUS0_RIBBONJAM 0x10
#define ERROR_STATUS0_RIBBON_OTHER 0x11 // 0x11->0x1F
#define ERROR_STATUS0_PAPER_JAM 0x20 // 0x20->0x2F
#define ERROR_STATUS0_MECHANICAL 0x30 // 0x30->0x39
#define ERROR_STATUS0_RFID 0x3A
#define ERROR_STATUS0_FLASH 0x3B
#define ERROR_STATUS0_EEPROM 0x3C
#define ERROR_STATUS0_PREHEAT 0x3D
#define ERROR_STATUS0_MDASTATE 0x3E
#define ERROR_STATUS0_PSUFANLOCKED 0x3F
#define ERROR_STATUS0_OTHERS 0x40 // 0x40..?
/* Error classifications */
#define ERROR_STATUS1_PAPER 0x01
#define ERROR_STATUS1_RIBBON 0x02
#define ERROR_STATUS1_SETTING 0x03
#define ERROR_STATUS1_OPEN 0x05
#define ERROR_STATUS1_NOSTRIPBIN 0x06
#define ERROR_STATUS1_PAPERJAM 0x07
#define ERROR_STATUS1_RIBBONSYS 0x08
#define ERROR_STATUS1_MECHANICAL 0x09
#define ERROR_STATUS1_ELECTRICAL 0x0A
#define ERROR_STATUS1_FIRMWARE 0x0E
#define ERROR_STATUS1_OTHER 0x0F
/* Error recovery conditions */
#define ERROR_STATUS2_AUTO 0x00
#define ERROR_STATUS2_RELOAD_PAPER 0x01
#define ERROR_STATUS2_RELOAD_RIBBON 0x02
#define ERROR_STATUS2_CHANGE_BOTH 0x03
#define ERROR_STATUS2_CHANGE_ONE 0x04
#define ERROR_STATUS2_CLOSEUNIT 0x05
#define ERROR_STATUS2_ATTACHSTRIPBIN 0x06
#define ERROR_STATUS2_CLEARJAM 0x07
#define ERROR_STATUS2_CHECKRIBBON 0x08
#define ERROR_STATUS2_OPENCLOSEUNIT 0x0A
#define ERROR_STATUS2_POWEROFF 0x0F
struct mitsu70x_status_deck {
uint8_t mecha_status[2];
2017-04-26 10:06:13 -04:00
uint8_t temperature; /* D70/D80 family only, K60 no? */
uint8_t error_status[3];
uint8_t rsvd_a[3]; /* K60 [1] == temperature? */
uint8_t lifetime_prints[4];
uint8_t rsvd_b[3]; /* K60 [3] == ?? */
uint8_t media_brand;
uint8_t media_type;
uint8_t media_subtype; /* K60 only? */
uint8_t rsvd_c[1];
int16_t capacity; /* media capacity */
int16_t remain; /* media remaining */
uint8_t rsvd_d[2];
uint8_t unknown_ctr[4]; /* lifetime + 10 (EK305), lifetime+41 (D80), in BCD! */
uint8_t rsvd_e[2]; // Unknown
uint16_t rsvd_f[16]; /* all 80 00 */
} __attribute__((packed));
struct mitsu70x_status_ver {
char ver[6];
uint16_t checksum; /* Presumably BE */
2014-10-03 20:35:05 -04:00
} __attribute__((packed));
struct mitsu70x_printerstatus_resp {
uint8_t hdr[4]; /* E4 56 32 30 */
uint8_t memory;
uint8_t power;
uint8_t unk[20];
uint8_t sleeptime; /* In minutes, 0-60 */
uint8_t iserial; /* 0x00 for Enabled, 0x80 for Disabled */
uint8_t unk_b[5]; // [4] == 0x44 on D70x, 0x13 on D80, 0x02 on EK305.
uint8_t dual_deck; /* 0x80 for dual-deck D707, 0x00 otherwise */
uint8_t unk_c[2]; // always 00 00 ??
uint8_t subtype; /* 0x5f on D70x/K60/D80, 0x5e on D70xS/K60-S, 0x01 on EK305 */
uint8_t unk_d[3]; // [1:2] == 0x??bd on D70x, 0x0487 on EK305, 0x04d7 on D80
int16_t model[6]; /* LE, UTF-16 */
int16_t serno[6]; /* LE, UTF-16 */
struct mitsu70x_status_ver vers[7]; // components are 'MLRTF'
uint8_t null[2];
uint8_t user_serno[6]; /* XXX Supposedly. Don't know how to set it! */
struct mitsu70x_status_deck lower;
struct mitsu70x_status_deck upper;
2014-10-03 20:35:05 -04:00
} __attribute__((packed));
struct mitsu70x_memorystatus_resp {
uint8_t hdr[3]; /* E4 56 33 */
uint8_t memory;
uint8_t size;
uint8_t rsvd;
} __attribute__((packed));
struct mitsu70x_calinfo_resp { /* Interpretations valid for ASK300 */
uint8_t hdr[6]; /* e4 6a 36 34 31 00 */
/* Note! All values below are ASCII hex! ie 0x23 -> 0x32 0x33 */
uint8_t adj_horiz[2]; /* +- 128, units of 0.085 mm */
uint8_t adj_vertA[2]; /* +- 128 */
uint8_t adj_vertB[2]; /* values are in units of 0.085 mm */
uint8_t adj_vertC[2]; /* A is -1->9, B is -4->6, C is -1->9 */
uint8_t adj_fine[4]; /* 00DC */
uint8_t adj_m3[2]; /* -100 -> 100 (converted to hex) */
uint8_t unk_c[28];
// 30 30 30 30 46 46 36 34 35 35 30 30
// 46 46 36 34 35 35 30 30 44 43 30 30 30 30 30 30
uint8_t adj_density[4]; /* 6800 -> 9000, def 8000 */
uint8_t adj_24v[4]; /* 0000 -> 00FF */
} __attribute__((packed));
/*
NOTES: Other stuff seen:
1b 45 48 [30 31 32] <-- No resp [30 any deck, 31 is lower, 32 is upper?]
1b 45 4a [30 31 32] <-- No resp [30 any deck, 31 is lower, 32 is upper?]
1b 45 53 00 10 [ ...? ] XX XX . "set printer number"..
1b 45 53 90 00 0a [ ... 9 bytes of something ] 10
1b 52 XX 00 <-- XX = something + 0x51
1b 54 00 [00 31 32] <-- No resp [00 any, 31 lower, 32 upper???]
1b 54 31 00 "feed and cut"
1b 54 53 90 00 0a 00 00 00 00 00 00 00 00 00 00
1b 56 34 [31 32] <-- 6 byte response, last two bytes are value.
1b 5a 43 00 <-- No resp
1b 67 18 ... (??)
1b 6a ... Various test commands
1b 6e ... (??)
1b 72 45 [31 32]
1b 72 67 00 00 00
*/
2014-10-03 20:35:05 -04:00
struct mitsu70x_hdr {
uint8_t hdr[4]; /* 1b 5a 54 XX */ // XXX also, seen 1b 5a 43!
uint16_t jobid;
2017-04-26 10:06:13 -04:00
uint8_t rewind[2]; /* K60/EK305/D80 only */
uint8_t zero0[8];
2014-10-03 20:35:05 -04:00
uint16_t cols;
uint16_t rows;
uint16_t lamcols;
uint16_t lamrows;
uint8_t speed;
2014-10-03 20:35:05 -04:00
uint8_t zero1[7];
2017-04-26 10:06:13 -04:00
uint8_t deck; /* 0 = default, 1 = lower, 2 = upper -- Non-D70/D707 is always '1' */
2014-10-03 20:35:05 -04:00
uint8_t zero2[7];
2015-12-28 11:29:31 -05:00
uint8_t laminate; /* 00 == on, 01 == off */
2016-10-09 08:59:21 -04:00
uint8_t laminate_mode; /* 00 == glossy, 02 == matte */
2015-12-28 11:29:31 -05:00
uint8_t zero3[6];
2014-10-03 20:35:05 -04:00
uint8_t multicut;
2017-04-26 10:06:13 -04:00
uint8_t zero4[12]; /* NOTE: everything past this point is an extension */
uint8_t sharpen; /* 0-9. 5 is "normal", 0 is "off" */
uint8_t mode; /* 0 for cooked YMC planar, 1 for packed BGR */
uint8_t use_lut; /* in BGR mode, 0 disables, 1 enables */
uint8_t reversed; /* 1 tells the backend the row data is correct */
uint8_t pad[447];
2014-10-03 20:35:05 -04:00
} __attribute__((packed));
STATIC_ASSERT(sizeof(struct mitsu70x_hdr) == 512);
STATIC_ASSERT(sizeof(struct mitsu70x_calinfo_resp) == 56);
static int mitsu70x_get_printerstatus(struct mitsu70x_ctx *ctx, struct mitsu70x_printerstatus_resp *resp);
static int mitsu70x_main_loop(void *vctx, const void *vjob, int wait_for_return);
/* Error dumps, etc */
static const char *mitsu70x_mechastatus(uint8_t *sts)
{
switch(sts[0]) {
case MECHA_STATUS_INIT:
return "Initializing";
case MECHA_STATUS_FEED:
return "Paper Feeding/Cutting";
case MECHA_STATUS_LOAD:
case MECHA_STATUS_LOAD2:
return "Media Loading";
case MECHA_STATUS_PRINT:
return "Printing";
case MECHA_STATUS_IDLE:
return "Idle";
default:
break;
}
return "Unknown Mechanical Status";
}
2018-05-17 20:19:16 -04:00
static const char *mitsu70x_jobstatuses(uint8_t *sts)
{
switch(sts[0]) {
case JOB_STATUS0_NONE:
return "No Job";
case JOB_STATUS0_DATA:
return "Data transfer";
case JOB_STATUS0_QUEUE:
return "Queued for printing";
2017-07-10 20:15:56 -04:00
case JOB_STATUS0_PRINT:
switch(sts[1]) {
case JOB_STATUS1_PRINT_MEDIALOAD:
return "Media loading";
case JOB_STATUS1_PRINT_PRE_Y:
return "Waiting to print yellow plane";
case JOB_STATUS1_PRINT_Y:
2017-07-10 20:15:56 -04:00
return "Printing yellow plane";
case JOB_STATUS1_PRINT_PRE_M:
return "Waiting to print magenta plane";
case JOB_STATUS1_PRINT_M:
return "Printing magenta plane";
case JOB_STATUS1_PRINT_PRE_C:
return "Waiting to print cyan plane";
case JOB_STATUS1_PRINT_C:
return "Printing cyan plane";
case JOB_STATUS1_PRINT_PRE_OC:
return "Waiting to laminate page";
case JOB_STATUS1_PRINT_OC:
return "Laminating page";
case JOB_STATUS1_PRINT_EJECT:
return "Ejecting page";
default:
return "Unknown 'Print' status1";
}
break;
case JOB_STATUS0_ASSIGN:
return "Unknown 'Assignment' status1";
case JOB_STATUS0_END:
switch(sts[1]) {
case JOB_STATUS1_END_OK:
return "Normal End";
case JOB_STATUS1_END_HEADER:
switch(sts[2]) {
case JOB_STATUS2_END_HEADER_ERROR:
return "Incorrect Header data (bad print size?)";
case JOB_STATUS2_END_HEADER_MEMORY:
return "Insufficient printer memory";
default:
return "Unknown 'End Header' status2";
}
break;
case JOB_STATUS1_END_PRINT:
switch(sts[2]) {
case JOB_STATUS2_END_PRINT_MEDIA:
return "Incorrect mediasize";
case JOB_STATUS2_END_PRINT_PREVERR:
return "Previous job terminated abnormally";
default:
return "Unknown 'End Print' status2";
}
break;
case JOB_STATUS1_END_INTERRUPT:
switch(sts[2]) {
case JOB_STATUS2_END_INT_TIMEOUT:
return "Timeout";
case JOB_STATUS2_END_INT_CANCEL:
return "Job cancelled";
case JOB_STATUS2_END_INT_DISCON:
return "Printer disconnected";
default:
return "Unknown 'End Print' status2";
}
break;
default:
if (sts[1] >= 0x10 && sts[1] <= 0x7f)
return "Mechanical Error";
else
return "Unknown 'End' status1";
}
break;
default:
break;
}
return "Unknown status0";
}
2018-05-17 20:19:16 -04:00
static const char *mitsu70x_errorclass(uint8_t *err)
{
switch(err[1]) {
case ERROR_STATUS1_PAPER:
return "Paper";
case ERROR_STATUS1_RIBBON:
return "Ribbon";
case ERROR_STATUS1_SETTING:
return "Job settings";
case ERROR_STATUS1_OPEN:
return "Cover open";
case ERROR_STATUS1_NOSTRIPBIN:
return "No cut bin";
case ERROR_STATUS1_PAPERJAM:
return "Paper jam";
case ERROR_STATUS1_RIBBONSYS:
return "Ribbon system";
case ERROR_STATUS1_MECHANICAL:
return "Mechanical";
case ERROR_STATUS1_ELECTRICAL:
return "Electrical";
case ERROR_STATUS1_FIRMWARE:
return "Firmware";
case ERROR_STATUS1_OTHER:
return "Other";
default:
break;
}
return "Unknown error class";
}
2018-05-17 20:19:16 -04:00
static const char *mitsu70x_errorrecovery(uint8_t *err)
{
switch(err[1]) {
case ERROR_STATUS2_AUTO:
return "Automatic recovery";
case ERROR_STATUS2_RELOAD_PAPER:
return "Reload or change paper";
case ERROR_STATUS2_RELOAD_RIBBON:
return "Reload or change ribbon";
case ERROR_STATUS2_CHANGE_BOTH:
return "Change paper and ribbon";
case ERROR_STATUS2_CHANGE_ONE:
return "Change paper or ribbon";
case ERROR_STATUS2_CLOSEUNIT:
return "Close printer";
case ERROR_STATUS2_ATTACHSTRIPBIN:
return "Attach Strip Bin";
case ERROR_STATUS2_CLEARJAM:
return "Remove and reload paper";
case ERROR_STATUS2_CHECKRIBBON:
return "Check ribbon and reload paper";
case ERROR_STATUS2_OPENCLOSEUNIT:
return "Open then close printer";
case ERROR_STATUS2_POWEROFF:
return "Power-cycle printer";
default:
break;
}
return "Unknown recovery";
}
2018-05-17 20:19:16 -04:00
static const char *mitsu70x_errors(uint8_t *err)
{
switch(err[0]) {
case ERROR_STATUS0_NOSTRIPBIN:
return "Strip bin not attached";
case ERROR_STATUS0_NORIBBON:
return "No ribbon detected";
case ERROR_STATUS0_NOPAPER:
return "No paper loaded";
case ERROR_STATUS0_MEDIAMISMATCH:
return "Ribbon/Paper mismatch";
case ERROR_STATUS0_RIBBONCNTEND:
return "Ribbon count end";
case ERROR_STATUS0_BADRIBBON:
return "Illegal Ribbon";
case ERROR_STATUS0_BADJOBPARAM:
return "Job does not match loaded media";
case ERROR_STATUS0_PAPEREND:
return "End of paper detected";
case ERROR_STATUS0_RIBBONEND:
return "End of ribbon detected";
case ERROR_STATUS0_DOOROPEN_IDLE:
case ERROR_STATUS0_DOOROPEN_PRNT:
return "Printer door open";
case ERROR_STATUS0_POWEROFF:
return "Printer powered off"; // nonsense..
case ERROR_STATUS0_RIBBONSKIP1:
case ERROR_STATUS0_RIBBONSKIP2:
return "Ribbon skipped";
case ERROR_STATUS0_RIBBONJAM:
return "Ribbon stuck to paper";
case ERROR_STATUS0_RFID:
return "RFID read error";
case ERROR_STATUS0_FLASH:
return "FLASH read error";
case ERROR_STATUS0_EEPROM:
return "EEPROM read error";
case ERROR_STATUS0_PREHEAT:
return "Preheating unit time out";
case ERROR_STATUS0_MDASTATE:
return "Unknown MDA state";
case ERROR_STATUS0_PSUFANLOCKED:
return "Power supply fan locked up";
default:
break;
}
if (err[0] >= ERROR_STATUS0_RIBBON_OTHER &&
err[0] < ERROR_STATUS0_PAPER_JAM) {
return "Unknown ribbon error";
// XXX use err[1]/err[2] codes?
}
if (err[0] >= ERROR_STATUS0_PAPER_JAM &&
err[0] < ERROR_STATUS0_MECHANICAL) {
return "Paper jam";
// XXX use err[1]/err[2] codes?
}
if (err[0] >= ERROR_STATUS0_MECHANICAL &&
err[0] < ERROR_STATUS0_RFID) {
return "Unknown mechanical error";
// XXX use err[1]/err[2] codes?
}
return "Unknown error";
}
#define CMDBUF_LEN 512
#define READBACK_LEN 256
static void *mitsu70x_init(void)
{
struct mitsu70x_ctx *ctx = malloc(sizeof(struct mitsu70x_ctx));
if (!ctx) {
ERROR("Memory Allocation Failure!\n");
return NULL;
}
memset(ctx, 0, sizeof(struct mitsu70x_ctx));
return ctx;
}
static int mitsu70x_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct mitsu70x_ctx *ctx = vctx;
ctx->jobid = jobid;
if (!ctx->jobid)
jobid++;
2013-11-23 19:51:55 -05:00
ctx->conn = conn;
ctx->last_l = ctx->last_u = 65535;
#if defined(WITH_DYNAMIC)
/* Attempt to open the library */
if (mitsu_loadlib(&ctx->lib, ctx->conn->type))
#endif
WARNING("Dynamic library support not loaded, will be unable to print!\n");
struct mitsu70x_printerstatus_resp resp;
int ret;
2018-05-12 18:41:13 -04:00
if (test_mode < TEST_MODE_NOATTACH) {
ret = mitsu70x_get_printerstatus(ctx, &resp);
if (ret) {
ERROR("Unable to get printer status! (%d)\n", ret);
return CUPS_BACKEND_FAILED;
}
} else {
int media_code = 0xf;
if (getenv("MEDIA_CODE"))
media_code = atoi(getenv("MEDIA_CODE")) & 0xf;
2018-05-12 18:41:13 -04:00
resp.upper.mecha_status[0] = MECHA_STATUS_INIT;
resp.lower.mecha_status[0] = MECHA_STATUS_INIT;
resp.upper.capacity = cpu_to_be16(230);
resp.lower.capacity = cpu_to_be16(230);
resp.upper.remain = cpu_to_be16(200);
resp.lower.remain = cpu_to_be16(200);
resp.upper.media_brand = 0xff;
resp.lower.media_brand = 0xff;
resp.upper.media_type = media_code;
resp.lower.media_type = media_code;
resp.dual_deck = 0x80; /* Make it a dual deck */
resp.vers[0].ver[0] = 0;
resp.subtype = 0x5e;
}
/* Figure out if we're a D707 with two decks */
if (ctx->conn->type == P_MITSU_D70X &&
resp.dual_deck == 0x80)
ctx->num_decks = 2;
else
ctx->num_decks = 1;
/* Set up markers */
ctx->marker[0].color = "#00FFFF#FF00FF#FFFF00";
ctx->marker[0].name = mitsu_media_types(ctx->conn->type, resp.lower.media_brand, resp.lower.media_type);
ctx->marker[0].numtype = resp.lower.media_type;
ctx->marker[0].levelmax = be16_to_cpu(resp.lower.capacity);
ctx->marker[0].levelnow = be16_to_cpu(resp.lower.remain);
ctx->medias[0] = resp.lower.media_type & 0xf;
ctx->media_subtypes[0] = resp.lower.media_subtype;
if (ctx->num_decks == 2) {
ctx->marker[1].color = "#00FFFF#FF00FF#FFFF00";
ctx->marker[1].name = mitsu_media_types(ctx->conn->type, resp.upper.media_brand, resp.upper.media_type);
ctx->marker[1].numtype = resp.upper.media_type;
ctx->marker[1].levelmax = be16_to_cpu(resp.upper.capacity);
ctx->marker[1].levelnow = be16_to_cpu(resp.upper.remain);
ctx->medias[1] = resp.upper.media_type & 0xf;
ctx->media_subtypes[1] = resp.upper.media_subtype;
}
/* Store the FW version */
memcpy(ctx->fwver, resp.vers[0].ver, 6);
ctx->fwver[6] = 0;
/* Store the serial number */
for (int i = 0 ; i < 6 ; i++) {
ctx->serno[i] = le16_to_cpu(resp.serno[i]) & 0x7f;
}
ctx->serno[6] = 0;
/* Check for the -S variants */
if (resp.subtype == 0x5e)
ctx->is_s = 1;
/* FW sanity checking */
if (ctx->conn->type == P_KODAK_305) {
/* Known versions:
v1.02: M 316E81 1433 (Add Ultrafine and matte support)
v1.04: M 316F83 2878 (Add 2x6 strip and support new "Triton" media)
2018-10-24 21:42:56 -04:00
v3.01: M 443A12 8908 (add 5" media support)
v3.02: M 443B11 2647 (Unknown)
*/
if (strncmp(resp.vers[0].ver, "443B11", 6) < 0)
WARNING("Printer FW out of date. Highly recommend upgrading EK305 to v3.02 or newer!\n");
} else if (ctx->conn->type == P_MITSU_K60) {
/* Known versions:
v1.05: M 316M31 148C (Add HG media support)
*/
if (strncmp(resp.vers[0].ver, "316M31", 6) < 0)
WARNING("Printer FW out of date. Highly recommend upgrading K60 to v1.05 or newer!\n");
} else if (ctx->conn->type == P_MITSU_D70X) {
/* Known versions for D70/D707:
v1.10: M 316V11 064D (Add ultrafine mode, 6x6 support, 2x6 strip, and more?)
v1.12: M 316W11 9FC3 (??)
v1.13: (??)
Known versions for D70-S/D707-S
v??? M 316K11 E08A (??)
*/
if (strncmp(resp.vers[0].ver, "316W11", 6) < 0)
WARNING("Printer FW out of date. Highly recommend upgrading D70/D707 to v1.12 or newer!\n");
} else if (ctx->conn->type == P_FUJI_ASK300) {
/* Known versions:
v?.??: M 316A21 7998 (ancient. no matte or ultrafine)
v?.??: M 316H21 F8EB
v4.20a: M 316J21 4431 (Add 2x6 strip support)
*/
if (strncmp(resp.vers[0].ver, "316J21", 6) < 0)
WARNING("Printer FW out of date. Highly recommend upgrading ASK300 to v4.20a or newer!\n");
}
return CUPS_BACKEND_OK;
}
static void mitsu70x_cleanup_job(const void *vjob) {
const struct mitsu70x_printjob *job = vjob;
if (job->databuf)
free(job->databuf);
if (job->spoolbuf)
free(job->spoolbuf);
free((void*)job);
}
static void mitsu70x_teardown(void *vctx) {
struct mitsu70x_ctx *ctx = vctx;
if (!ctx)
return;
mitsu_destroylib(&ctx->lib);