2013-10-05 09:55:29 -04:00
|
|
|
/*
|
|
|
|
* Mitsubishi CP-D70/D707 Photo Printer CUPS backend -- libusb-1.0 version
|
|
|
|
*
|
2016-01-24 09:44:19 -05:00
|
|
|
* (c) 2013-2016 Solomon Peachy <pizza@shaftnet.org>
|
2013-10-05 09:55:29 -04:00
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
2013-10-05 11:52:37 -04:00
|
|
|
*
|
2013-10-05 09:55:29 -04:00
|
|
|
* http://git.shaftnet.org/cgit/selphy_print.git
|
2013-10-05 11:52:37 -04:00
|
|
|
*
|
2013-10-05 09:55:29 -04:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 3 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* 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>
|
|
|
|
|
2015-08-13 21:09:56 -04:00
|
|
|
#define BACKEND mitsu70x_backend
|
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
#include "backend_common.h"
|
|
|
|
|
|
|
|
#define USB_VID_MITSU 0x06D3
|
|
|
|
#define USB_PID_MITSU_D70X 0x3B30
|
2014-03-10 14:08:30 -04:00
|
|
|
#define USB_PID_MITSU_K60 0x3B31
|
2014-12-02 23:45:32 -05:00
|
|
|
//#define USB_PID_MITSU_D80 XXXXXX
|
2014-12-25 09:20:50 -05:00
|
|
|
#define USB_VID_KODAK 0x040a
|
|
|
|
#define USB_PID_KODAK305 0x404f
|
2015-12-28 11:29:31 -05:00
|
|
|
//#define USB_VID_FUJIFILM XXXXXX
|
|
|
|
//#define USB_PID_FUJI_ASK300 XXXXXX
|
2013-10-05 09:55:29 -04:00
|
|
|
|
2016-01-18 11:34:58 -05:00
|
|
|
//#define ENABLE_CORRTABLES
|
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
/* Private data stucture */
|
|
|
|
struct mitsu70x_ctx {
|
|
|
|
struct libusb_device_handle *dev;
|
|
|
|
uint8_t endp_up;
|
|
|
|
uint8_t endp_down;
|
2015-08-12 22:56:29 -04:00
|
|
|
int type;
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
uint8_t *databuf;
|
|
|
|
int datalen;
|
2014-10-03 20:30:09 -04:00
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
int matte;
|
|
|
|
|
2016-08-19 17:40:12 -04:00
|
|
|
uint16_t jobid;
|
2014-10-03 20:30:09 -04:00
|
|
|
uint16_t rows;
|
|
|
|
uint16_t cols;
|
2016-08-19 17:40:12 -04:00
|
|
|
|
|
|
|
uint16_t last_donor_l;
|
|
|
|
uint16_t last_donor_u;
|
|
|
|
int num_decks;
|
|
|
|
|
2016-01-18 11:34:58 -05:00
|
|
|
#ifdef ENABLE_CORRTABLES
|
|
|
|
struct mitsu70x_corrdata *corrdata;
|
|
|
|
struct mitsu70x_corrdatalens *corrdatalens;
|
|
|
|
char *laminatefname;
|
2016-08-19 17:40:12 -04:00
|
|
|
#endif
|
2013-10-05 09:55:29 -04:00
|
|
|
};
|
|
|
|
|
2014-09-19 20:39:04 -04:00
|
|
|
/* Printer data structures */
|
2015-12-25 16:21:06 -05:00
|
|
|
struct mitsu70x_jobstatus {
|
|
|
|
uint8_t hdr[4];
|
|
|
|
uint16_t jobid;
|
|
|
|
uint16_t mecha_no;
|
|
|
|
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 reserved[6];
|
2014-10-03 20:35:05 -04:00
|
|
|
} __attribute__((packed));
|
2014-12-29 14:21:39 -05:00
|
|
|
|
2015-12-25 17:48:55 -05:00
|
|
|
struct mitsu70x_jobs {
|
|
|
|
uint8_t hdr[4];
|
|
|
|
uint16_t dummy;
|
|
|
|
uint16_t jobid_0;
|
|
|
|
uint8_t job0_status[4];
|
|
|
|
uint16_t jobid_1;
|
|
|
|
uint8_t job1_status[4];
|
|
|
|
// XXX are there more?
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
#define TEMPERATURE_NORMAL 0x00
|
|
|
|
#define TEMPERATURE_PREHEAT 0x40
|
|
|
|
#define TEMPERATURE_COOLING 0x80
|
|
|
|
|
|
|
|
#define MECHA_STATUS_INIT 0x80
|
|
|
|
#define MECHA_STATUS_FEED 0x50
|
|
|
|
#define MECHA_STATUS_LOAD 0x40
|
|
|
|
#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 // nonsense.. heh.
|
|
|
|
#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
|
|
|
|
|
2014-09-19 20:39:04 -04:00
|
|
|
struct mitsu70x_status_deck {
|
2015-12-25 16:21:06 -05:00
|
|
|
uint8_t mecha_status[2];
|
|
|
|
uint8_t temperature;
|
|
|
|
uint8_t error_status[3];
|
|
|
|
uint8_t rsvd_a[10];
|
2016-08-19 17:40:12 -04:00
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
uint8_t media_brand;
|
|
|
|
uint8_t media_type;
|
|
|
|
uint8_t rsvd_b[2];
|
2014-12-29 18:57:40 -05:00
|
|
|
uint16_t capacity; /* media capacity */
|
|
|
|
uint16_t remain; /* media remaining */
|
2015-12-25 16:21:06 -05:00
|
|
|
uint8_t rsvd_c[2];
|
|
|
|
|
|
|
|
uint16_t rsvd_d;
|
2014-12-29 18:57:40 -05:00
|
|
|
uint16_t prints; /* lifetime prints on deck? */
|
2015-12-25 16:21:06 -05:00
|
|
|
uint16_t rsvd_e[17];
|
2014-12-29 14:21:39 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct mitsu70x_status_ver {
|
|
|
|
char ver[6];
|
2015-09-13 11:34:22 -04:00
|
|
|
uint16_t checksum; /* Presumably BE */
|
2014-10-03 20:35:05 -04:00
|
|
|
} __attribute__((packed));
|
2014-12-29 14:21:39 -05:00
|
|
|
|
2015-12-25 17:40:27 -05:00
|
|
|
struct mitsu70x_printerstatus_resp {
|
2014-12-29 14:21:39 -05:00
|
|
|
uint8_t hdr[4];
|
|
|
|
uint8_t unk[36];
|
|
|
|
int16_t model[6]; /* LE, UTF-16 */
|
|
|
|
int16_t serno[6]; /* LE, UTF-16 */
|
|
|
|
struct mitsu70x_status_ver vers[7];
|
|
|
|
uint8_t null[8];
|
2014-09-19 20:39:04 -04:00
|
|
|
struct mitsu70x_status_deck lower;
|
|
|
|
struct mitsu70x_status_deck upper;
|
2014-10-03 20:35:05 -04:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
struct mitsu70x_memorystatus_resp {
|
|
|
|
uint8_t hdr[3];
|
|
|
|
uint8_t memory;
|
|
|
|
uint8_t size;
|
|
|
|
uint8_t rsvd;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2014-10-03 20:35:05 -04:00
|
|
|
struct mitsu70x_hdr {
|
2015-12-28 11:29:31 -05:00
|
|
|
uint8_t hdr[4]; /* 1b 5a 54 XX */
|
2015-12-25 16:21:06 -05:00
|
|
|
uint16_t jobid;
|
|
|
|
uint8_t zero0[10];
|
2014-10-03 20:35:05 -04:00
|
|
|
|
|
|
|
uint16_t cols;
|
|
|
|
uint16_t rows;
|
|
|
|
uint16_t lamcols;
|
|
|
|
uint16_t lamrows;
|
2016-01-18 11:34:58 -05:00
|
|
|
uint8_t speed;
|
2014-10-03 20:35:05 -04:00
|
|
|
uint8_t zero1[7];
|
|
|
|
|
2016-08-19 17:40:12 -04:00
|
|
|
uint8_t deck; /* 0 = default, 1 = lower, 2 = upper */
|
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 */
|
|
|
|
uint8_t laminate_mode;
|
|
|
|
uint8_t zero3[6];
|
2014-10-03 20:35:05 -04:00
|
|
|
|
|
|
|
uint8_t multicut;
|
2015-12-28 11:29:31 -05:00
|
|
|
uint8_t zero4[15];
|
2014-10-03 20:35:05 -04:00
|
|
|
|
2015-12-28 11:29:31 -05:00
|
|
|
uint8_t pad[448];
|
2014-10-03 20:35:05 -04:00
|
|
|
} __attribute__((packed));
|
2014-09-19 20:39:04 -04:00
|
|
|
|
2016-01-18 11:34:58 -05:00
|
|
|
#ifdef ENABLE_CORRTABLES
|
|
|
|
/* Correction data definitions */
|
|
|
|
#define CORRDATA_DEF
|
|
|
|
struct mitsu70x_corrdata {
|
|
|
|
uint16_t liney[2730];
|
|
|
|
uint16_t linem[2730];
|
|
|
|
uint16_t linec[2730];
|
|
|
|
uint16_t gnmby[256]; // B->Y conversion matrix
|
|
|
|
uint16_t gnmgm[256]; // G->M conversion matrix
|
|
|
|
uint16_t gnmrc[256]; // R->C conversion matrix
|
|
|
|
double fm[256];
|
|
|
|
double ksp[128];
|
|
|
|
double ksm[128];
|
|
|
|
double osp[128];
|
|
|
|
double osm[128];
|
|
|
|
double kp[11];
|
|
|
|
double km[11];
|
|
|
|
double hk[4];
|
|
|
|
uint16_t speed[3];
|
|
|
|
double fh[5]; /* only 4 in length on D70 Normal/Superfine */
|
|
|
|
double shk[72];
|
|
|
|
double uh[101];
|
|
|
|
uint16_t rolk[13]; /* Missing on D70x family */
|
|
|
|
uint32_t rev[76]; /* Missing on D70x and ASK300 */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mitsu70x_corrdatalens {
|
|
|
|
size_t liney;
|
|
|
|
size_t linem;
|
|
|
|
size_t linec;
|
|
|
|
size_t gnmby;
|
|
|
|
size_t gnmgm;
|
|
|
|
size_t gnmrc;
|
|
|
|
size_t fm;
|
|
|
|
size_t ksp;
|
|
|
|
size_t ksm;
|
|
|
|
size_t osp;
|
|
|
|
size_t osm;
|
|
|
|
size_t kp;
|
|
|
|
size_t km;
|
|
|
|
size_t hk;
|
|
|
|
size_t speed;
|
|
|
|
size_t fh;
|
|
|
|
size_t shk;
|
|
|
|
size_t uh;
|
|
|
|
size_t rolk;
|
|
|
|
size_t rev;
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "D70/CPD70N01.h" // Normal/Fine
|
|
|
|
#include "D70/CPD70S01.h" // Superfine
|
|
|
|
#include "D70/CPD70U01.h" // Ultrafine
|
|
|
|
//#include "D70/CPD80E01.h" // ???
|
|
|
|
#include "D70/CPD80N01.h" // Normal/Fine
|
|
|
|
#include "D70/CPD80S01.h" // Superfine
|
|
|
|
#include "D70/CPD80U01.h" // Ultrafine
|
|
|
|
#include "D70/ASK300T1.h" // Normal/Fine
|
|
|
|
#include "D70/ASK300T3.h" // Superfine/Ultrafine
|
|
|
|
#include "D70/CPS60T01.h" // Normal/Fine
|
|
|
|
#include "D70/CPS60T03.h" // Superfine/Ultrafine
|
|
|
|
#include "D70/EK305T01.h" // Normal/Fine
|
|
|
|
#include "D70/EK305T03.h" // Superfine/Ultrafine
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Error dumps, etc */
|
|
|
|
|
2015-12-25 23:27:35 -05:00
|
|
|
static 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:
|
|
|
|
return "Media Loading";
|
|
|
|
case MECHA_STATUS_PRINT:
|
|
|
|
return "Printing";
|
|
|
|
case MECHA_STATUS_IDLE:
|
|
|
|
return "Idle";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "Unknown Mechanical Status";
|
|
|
|
}
|
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
static 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";
|
|
|
|
case JOB_STATUS0_PRINT:
|
|
|
|
switch(sts[1]) {
|
|
|
|
case JOB_STATUS1_PRINT_MEDIALOAD:
|
|
|
|
return "Media loading\n";
|
|
|
|
case JOB_STATUS1_PRINT_PRE_Y:
|
|
|
|
return "Waiting to print yellow plane";
|
|
|
|
case JOB_STATUS1_PRINT_Y:
|
|
|
|
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\n";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case JOB_STATUS0_ASSIGN:
|
|
|
|
return "Unknown 'Assignment' status1\n";
|
|
|
|
case JOB_STATUS0_END:
|
|
|
|
switch(sts[1]) {
|
|
|
|
case JOB_STATUS1_END_OK:
|
|
|
|
return "Normal End";
|
|
|
|
case JOB_STATUS1_END_HEADER:
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2015-12-25 17:23:48 -05:00
|
|
|
static 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";
|
|
|
|
}
|
|
|
|
|
|
|
|
static 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";
|
|
|
|
}
|
|
|
|
|
|
|
|
static 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";
|
|
|
|
}
|
2015-12-25 16:21:06 -05:00
|
|
|
|
2016-08-19 17:40:12 -04:00
|
|
|
static const char *mitsu70x_media_types(uint8_t brand, uint8_t type)
|
|
|
|
{
|
|
|
|
if (brand == 0xff && type == 0x02)
|
|
|
|
return "CKD746 (4x6)";
|
|
|
|
else if (brand == 0xff && type == 0x0f)
|
|
|
|
return "CKD768 (6x8)";
|
|
|
|
else if (brand == 0x61 && type == 0x8f)
|
|
|
|
return "CKK76R (6x8)";
|
|
|
|
else if (brand == 0x6c && type == 0x8f)
|
|
|
|
return "CKK76R (6x8)";
|
|
|
|
else
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
#define CMDBUF_LEN 512
|
|
|
|
#define READBACK_LEN 256
|
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
static void *mitsu70x_init(void)
|
|
|
|
{
|
|
|
|
struct mitsu70x_ctx *ctx = malloc(sizeof(struct mitsu70x_ctx));
|
2015-06-23 20:32:41 -04:00
|
|
|
if (!ctx) {
|
|
|
|
ERROR("Memory Allocation Failure!\n");
|
2013-10-05 09:55:29 -04:00
|
|
|
return NULL;
|
2015-06-23 20:32:41 -04:00
|
|
|
}
|
2013-10-05 09:55:29 -04:00
|
|
|
memset(ctx, 0, sizeof(struct mitsu70x_ctx));
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2013-10-05 11:52:37 -04:00
|
|
|
static void mitsu70x_attach(void *vctx, struct libusb_device_handle *dev,
|
|
|
|
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
|
2013-10-05 09:55:29 -04:00
|
|
|
{
|
|
|
|
struct mitsu70x_ctx *ctx = vctx;
|
2014-10-02 19:29:47 -04:00
|
|
|
struct libusb_device *device;
|
|
|
|
struct libusb_device_descriptor desc;
|
2013-10-05 09:55:29 -04:00
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
ctx->jobid = jobid;
|
2016-01-15 08:24:23 -05:00
|
|
|
if (!ctx->jobid)
|
|
|
|
jobid++;
|
2013-11-23 19:51:55 -05:00
|
|
|
|
2013-10-05 11:52:37 -04:00
|
|
|
ctx->dev = dev;
|
2013-10-05 09:55:29 -04:00
|
|
|
ctx->endp_up = endp_up;
|
|
|
|
ctx->endp_down = endp_down;
|
2014-10-02 19:29:47 -04:00
|
|
|
|
|
|
|
device = libusb_get_device(dev);
|
|
|
|
libusb_get_device_descriptor(device, &desc);
|
|
|
|
|
2015-08-12 22:56:29 -04:00
|
|
|
ctx->type = lookup_printer_type(&mitsu70x_backend,
|
|
|
|
desc.idVendor, desc.idProduct);
|
2016-08-19 17:40:12 -04:00
|
|
|
|
|
|
|
ctx->last_donor_l = ctx->last_donor_u = 65535;}
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
static void mitsu70x_teardown(void *vctx) {
|
|
|
|
struct mitsu70x_ctx *ctx = vctx;
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ctx->databuf)
|
|
|
|
free(ctx->databuf);
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mitsu70x_read_parse(void *vctx, int data_fd) {
|
|
|
|
struct mitsu70x_ctx *ctx = vctx;
|
2014-01-17 22:50:29 -05:00
|
|
|
int i, remain;
|
2016-04-28 09:29:45 -04:00
|
|
|
struct mitsu70x_hdr mhdr;
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
if (!ctx)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-10-05 09:55:29 -04:00
|
|
|
|
2014-01-21 20:34:00 -05:00
|
|
|
if (ctx->databuf) {
|
2014-01-17 22:50:29 -05:00
|
|
|
free(ctx->databuf);
|
2014-01-21 20:34:00 -05:00
|
|
|
ctx->databuf = NULL;
|
|
|
|
}
|
2014-01-17 22:50:29 -05:00
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
ctx->matte = 0;
|
2016-04-28 09:29:45 -04:00
|
|
|
|
|
|
|
repeat:
|
2014-01-17 22:50:29 -05:00
|
|
|
/* Read in initial header */
|
2016-04-28 09:29:45 -04:00
|
|
|
remain = sizeof(mhdr);
|
2014-01-17 22:50:29 -05:00
|
|
|
while (remain > 0) {
|
2016-04-28 09:29:45 -04:00
|
|
|
i = read(data_fd, ((uint8_t*)&mhdr) + sizeof(mhdr) - remain, remain);
|
2014-01-20 19:41:52 -05:00
|
|
|
if (i == 0)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-01-17 22:50:29 -05:00
|
|
|
if (i < 0)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-01-17 22:50:29 -05:00
|
|
|
remain -= i;
|
2014-01-13 18:30:30 -05:00
|
|
|
}
|
2014-01-17 22:50:29 -05:00
|
|
|
|
2016-04-28 09:29:45 -04:00
|
|
|
/* Skip over wakeup header if it's present. */
|
|
|
|
if (mhdr.hdr[0] == 0x1b &&
|
|
|
|
mhdr.hdr[1] == 0x45 &&
|
|
|
|
mhdr.hdr[2] == 0x57 &&
|
|
|
|
mhdr.hdr[3] == 0x55) {
|
|
|
|
goto repeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check header */
|
|
|
|
if (mhdr.hdr[0] != 0x1b &&
|
|
|
|
mhdr.hdr[1] != 0x5a &&
|
|
|
|
mhdr.hdr[2] != 0x54) {
|
2013-10-05 09:55:29 -04:00
|
|
|
ERROR("Unrecognized data format!\n");
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2013-10-05 09:55:29 -04:00
|
|
|
}
|
|
|
|
|
2016-08-19 17:40:12 -04:00
|
|
|
#ifdef ENABLE_CORRTABLES
|
2016-01-18 11:34:58 -05:00
|
|
|
/* Figure out the correction data table to use */
|
|
|
|
if (ctx->type == P_MITSU_D70X) {
|
|
|
|
struct mitsu70x_hdr *print = (struct mitsu70x_hdr *) &hdr[512];
|
|
|
|
ctx->laminatefname = "D70MAT01.raw";
|
|
|
|
|
|
|
|
if (print->speed == 3) {
|
|
|
|
ctx->corrdata = &CPD70S01_data;
|
|
|
|
ctx->corrdatalens = &CPD70S01_lengths;
|
|
|
|
} else if (print->speed == 4) {
|
|
|
|
ctx->corrdata = &CPD70U01_data;
|
|
|
|
ctx->corrdatalens = &CPD70U01_lengths;
|
|
|
|
} else {
|
|
|
|
ctx->corrdata = &CPD70N01_data;
|
|
|
|
ctx->corrdatalens = &CPD70N01_lengths;
|
|
|
|
}
|
|
|
|
} else if (ctx->type == P_MITSU_D80) {
|
|
|
|
struct mitsu70x_hdr *print = (struct mitsu70x_hdr *) &hdr[512];
|
|
|
|
ctx->laminatefname = "D80MAT01.raw";
|
|
|
|
|
|
|
|
if (print->speed == 3) {
|
|
|
|
ctx->corrdata = &CPD80S01_data;
|
|
|
|
ctx->corrdatalens = &CPD80S01_lengths;
|
|
|
|
} else if (print->speed == 4) {
|
|
|
|
ctx->corrdata = &CPD80U01_data;
|
|
|
|
ctx->corrdatalens = &CPD80U01_lengths;
|
|
|
|
} else {
|
|
|
|
ctx->corrdata = &CPD80N01_data;
|
|
|
|
ctx->corrdatalens = &CPD80N01_lengths;
|
|
|
|
}
|
|
|
|
// XXX what about CPD80**E**01?
|
|
|
|
} else if (ctx->type == P_MITSU_K60) {
|
|
|
|
struct mitsu70x_hdr *print = (struct mitsu70x_hdr *) &hdr[512];
|
|
|
|
|
|
|
|
if (print->speed == 3 || print->speed == 4) {
|
|
|
|
ctx->corrdata = &CPS60T03_data;
|
|
|
|
ctx->corrdatalens = &CPS60T03_lengths;
|
|
|
|
} else {
|
|
|
|
ctx->corrdata = &CPS60T01_data;
|
|
|
|
ctx->corrdatalens = &CPS60T01_lengths;
|
|
|
|
}
|
|
|
|
ctx->laminatefname = "S60MAT02.raw";
|
|
|
|
} else if (ctx->type == P_KODAK_305) {
|
|
|
|
struct mitsu70x_hdr *print = (struct mitsu70x_hdr *) &hdr[512];
|
|
|
|
ctx->laminatefname = "EK305MAT.raw"; // XXX same as K60
|
|
|
|
|
|
|
|
if (print->speed == 3 || print->speed == 4) {
|
|
|
|
ctx->corrdata = &EK305T03_data;
|
|
|
|
ctx->corrdatalens = &EK305T03_lengths;
|
|
|
|
} else {
|
|
|
|
ctx->corrdata = &EK305T01_data;
|
|
|
|
ctx->corrdatalens = &EK305T01_lengths;
|
|
|
|
}
|
|
|
|
} else if (ctx->type == P_FUJI_ASK300) {
|
|
|
|
struct mitsu70x_hdr *print = (struct mitsu70x_hdr *) &hdr[512];
|
|
|
|
ctx->laminatefname = "ASK300M2.raw"; // XXX same as D70
|
|
|
|
|
|
|
|
if (print->speed == 3 || print->speed == 4) {
|
|
|
|
ctx->corrdata = &ASK300T3_data;
|
|
|
|
ctx->corrdatalens = &ASK300T3_lengths;
|
|
|
|
} else {
|
|
|
|
ctx->corrdata = &ASK300T1_data;
|
|
|
|
ctx->corrdatalens = &ASK300T1_lengths;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-17 22:50:29 -05:00
|
|
|
/* Work out printjob size */
|
2016-04-28 09:29:45 -04:00
|
|
|
ctx->cols = be16_to_cpu(mhdr.cols);
|
|
|
|
ctx->rows = be16_to_cpu(mhdr.rows);
|
2014-10-03 20:30:09 -04:00
|
|
|
|
2014-12-29 08:54:14 -05:00
|
|
|
remain = ctx->rows * ctx->cols * 2;
|
2014-01-17 22:50:29 -05:00
|
|
|
remain = (remain + 511) / 512 * 512; /* Round to nearest 512 bytes. */
|
|
|
|
remain *= 3; /* One for each plane */
|
2014-03-11 15:07:48 -04:00
|
|
|
|
2016-04-28 09:29:45 -04:00
|
|
|
if (!mhdr.laminate && mhdr.laminate_mode) {
|
|
|
|
i = be16_to_cpu(mhdr.lamcols) * be16_to_cpu(mhdr.lamrows) * 2;
|
2014-01-17 22:50:29 -05:00
|
|
|
i = (i + 511) / 512 * 512; /* Round to nearest 512 bytes. */
|
|
|
|
remain += i;
|
2015-12-25 16:21:06 -05:00
|
|
|
ctx->matte = 1;
|
2014-01-17 22:50:29 -05:00
|
|
|
}
|
|
|
|
|
2016-04-28 09:29:45 -04:00
|
|
|
ctx->databuf = malloc(sizeof(mhdr) + remain);
|
2013-10-05 09:55:29 -04:00
|
|
|
if (!ctx->databuf) {
|
|
|
|
ERROR("Memory allocation failure!\n");
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-10-05 09:55:29 -04:00
|
|
|
}
|
|
|
|
|
2016-04-28 09:29:45 -04:00
|
|
|
memcpy(ctx->databuf, &mhdr, sizeof(mhdr));
|
|
|
|
ctx->datalen += sizeof(mhdr);
|
2014-01-17 22:50:29 -05:00
|
|
|
|
|
|
|
/* Read in the spool data */
|
|
|
|
while(remain) {
|
2014-03-11 15:07:48 -04:00
|
|
|
i = read(data_fd, ctx->databuf + ctx->datalen, remain);
|
|
|
|
if (i == 0)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-01-17 22:50:29 -05:00
|
|
|
if (i < 0)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-03-11 15:07:48 -04:00
|
|
|
ctx->datalen += i;
|
2014-01-17 22:50:29 -05:00
|
|
|
remain -= i;
|
|
|
|
}
|
2013-10-05 09:55:29 -04:00
|
|
|
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-10-05 09:55:29 -04:00
|
|
|
}
|
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
static int mitsu70x_get_jobstatus(struct mitsu70x_ctx *ctx, struct mitsu70x_jobstatus *resp, uint16_t jobid)
|
2014-10-03 20:30:09 -04:00
|
|
|
{
|
|
|
|
uint8_t cmdbuf[CMDBUF_LEN];
|
|
|
|
int num, ret;
|
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
/* Send Printer Query */
|
2014-10-03 20:30:09 -04:00
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x56;
|
2015-12-25 16:21:06 -05:00
|
|
|
cmdbuf[2] = 0x31;
|
|
|
|
cmdbuf[3] = 0x30; // XXX 30 == specific, 31 = "all"
|
|
|
|
|
|
|
|
cmdbuf[4] = (jobid >> 8) & 0xff;
|
|
|
|
cmdbuf[5] = jobid & 0xff;
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
2015-12-25 16:21:06 -05:00
|
|
|
cmdbuf, 6)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
memset(resp, 0, sizeof(*resp));
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
2015-12-25 16:21:06 -05:00
|
|
|
(uint8_t*) resp, sizeof(*resp), &num);
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
if (ret < 0)
|
2015-12-25 16:21:06 -05:00
|
|
|
return ret;
|
|
|
|
if (num != sizeof(*resp)) {
|
|
|
|
ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp));
|
|
|
|
return 4;
|
2014-10-03 20:30:09 -04:00
|
|
|
}
|
2016-08-19 17:40:12 -04:00
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-25 17:48:55 -05:00
|
|
|
static int mitsu70x_get_jobs(struct mitsu70x_ctx *ctx, struct mitsu70x_jobs *resp)
|
|
|
|
{
|
|
|
|
uint8_t cmdbuf[CMDBUF_LEN];
|
|
|
|
int num, ret;
|
|
|
|
|
|
|
|
/* Send Printer Query */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x56;
|
|
|
|
cmdbuf[2] = 0x31;
|
|
|
|
cmdbuf[3] = 0x31;
|
|
|
|
cmdbuf[4] = 0x00;
|
|
|
|
cmdbuf[5] = 0x00;
|
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmdbuf, 6)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
memset(resp, 0, sizeof(*resp));
|
|
|
|
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
(uint8_t*) resp, sizeof(*resp), &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (num != sizeof(*resp)) {
|
|
|
|
ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp));
|
|
|
|
return 4;
|
|
|
|
}
|
2016-08-19 17:40:12 -04:00
|
|
|
|
2015-12-25 17:48:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
static int mitsu70x_get_memorystatus(struct mitsu70x_ctx *ctx, struct mitsu70x_memorystatus_resp *resp)
|
2014-10-03 20:30:09 -04:00
|
|
|
{
|
|
|
|
uint8_t cmdbuf[CMDBUF_LEN];
|
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
uint16_t tmp;
|
|
|
|
|
|
|
|
int num;
|
|
|
|
int ret;
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x56;
|
2015-12-25 16:21:06 -05:00
|
|
|
cmdbuf[2] = 0x33;
|
|
|
|
cmdbuf[3] = 0x00;
|
|
|
|
tmp = cpu_to_be16(ctx->cols);
|
|
|
|
memcpy(cmdbuf + 4, &tmp, 2);
|
|
|
|
tmp = cpu_to_be16(ctx->rows);
|
|
|
|
memcpy(cmdbuf + 6, &tmp, 2);
|
|
|
|
cmdbuf[8] = ctx->matte ? 0x80 : 0x00;
|
|
|
|
cmdbuf[9] = 0x00;
|
2014-10-03 20:30:09 -04:00
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
2015-12-25 16:21:06 -05:00
|
|
|
cmdbuf, 10)))
|
|
|
|
return CUPS_BACKEND_FAILED;
|
2014-10-03 20:30:09 -04:00
|
|
|
|
2015-12-25 16:21:06 -05:00
|
|
|
/* Read in the printer status */
|
2014-10-03 20:30:09 -04:00
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
(uint8_t*) resp, sizeof(*resp), &num);
|
|
|
|
if (ret < 0)
|
2015-12-25 16:21:06 -05:00
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
if (num != sizeof(*resp)) {
|
|
|
|
ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp));
|
2015-12-25 16:21:06 -05:00
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure response is sane */
|
|
|
|
if (resp->hdr[0] != 0xe4 ||
|
|
|
|
resp->hdr[1] != 0x56 ||
|
|
|
|
resp->hdr[2] != 0x33) {
|
|
|
|
ERROR("Unknown response from printer\n");
|
|
|
|
return CUPS_BACKEND_FAILED;
|
2014-10-03 20:30:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|