hiti: Rework paper/ribbon queries a little

* Read the paper type from the correct offset of CMD_RDS_RSUS
 * Use structs instead of byte arrays for RIS and RSUS queries

Unable to test for regressions at the moment.
This commit is contained in:
Solomon Peachy 2022-09-16 14:55:01 -04:00
parent 04d85d4887
commit 9c93ee1091
1 changed files with 48 additions and 36 deletions

View File

@ -391,6 +391,27 @@ struct hiti_matrix {
/* @100 */
} __attribute__((packed));
struct hiti_ribbon {
uint16_t unk;
uint8_t type; /* RIBBON_TYPE_XXX */
uint16_t unk2;
} __attribute__((packed));
#define RIBBON_TYPE_4x6 0x01
#define RIBBON_TYPE_5x7 0x02
#define RIBBON_TYPE_6x9 0x03
#define RIBBON_TYPE_6x8 0x04
struct hiti_paper {
uint8_t unk;
uint8_t type; /* PAPER_TYPE_XXX */
uint16_t unk2;
} __attribute__((packed));
#define PAPER_TYPE_5INCH 0x02
#define PAPER_TYPE_6INCH 0x01
#define PAPER_TYPE_NONE 0x00
/* Private data structure */
struct hiti_printjob {
struct dyesub_job_common common;
@ -416,8 +437,8 @@ struct hiti_ctx {
char version[256];
char id[256];
uint8_t matrix[256]; // XXX convert to struct matrix */
uint8_t supplies[5]; /* Ribbon */ // XXX convert to struct
uint8_t supplies2[4]; /* Paper */ // XXX convert to struct
struct hiti_ribbon ribbon;
struct hiti_paper paper;
struct hiti_calibration calibration;
uint8_t led_calibration[10]; // XXX convert to struct
uint8_t unk_8010[15]; // XXX
@ -634,11 +655,6 @@ static const char *hiti_jobstatuses(uint8_t code)
}
}
#define RIBBON_TYPE_4x6 0x01
#define RIBBON_TYPE_5x7 0x02
#define RIBBON_TYPE_6x9 0x03
#define RIBBON_TYPE_6x8 0x04
static const char* hiti_ribbontypes(uint8_t code)
{
switch (code) {
@ -661,10 +677,6 @@ static unsigned int hiti_ribboncounts(uint8_t code)
}
}
#define PAPER_TYPE_5INCH 0x02
#define PAPER_TYPE_6INCH 0x01
#define PAPER_TYPE_NONE 0x00
static const char* hiti_papers(uint8_t code)
{
switch (code) {
@ -929,13 +941,13 @@ static int hiti_get_status(struct hiti_ctx *ctx)
hiti_errors(err), err);
INFO("Media: %s (%02x / %04x) : %03u/%03u\n",
hiti_ribbontypes(ctx->supplies[2]),
ctx->supplies[2],
hiti_ribbontypes(ctx->ribbon.type),
ctx->ribbon.type,
ctx->ribbonvendor,
ctx->media_remain, hiti_ribboncounts(ctx->supplies[2]));
ctx->media_remain, hiti_ribboncounts(ctx->ribbon.type));
INFO("Paper: %s (%02x)\n",
hiti_papers(ctx->supplies2[0]),
ctx->supplies2[0]);
hiti_papers(ctx->paper.type),
ctx->paper.type);
/* Find out if we have any jobs outstanding */
struct hiti_job job = { 0 };
@ -1031,21 +1043,21 @@ static int hiti_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid
}
// do real stuff
} else {
ctx->supplies2[0] = PAPER_TYPE_6INCH;
ctx->supplies[2] = RIBBON_TYPE_4x6;
ctx->paper.type = PAPER_TYPE_6INCH;
ctx->ribbon.type = RIBBON_TYPE_4x6;
if (getenv("MEDIA_CODE")) {
// set fake fw version?
ctx->supplies[2] = atoi(getenv("MEDIA_CODE"));
if (ctx->supplies[2] == RIBBON_TYPE_5x7)
ctx->supplies2[0] = PAPER_TYPE_5INCH;
ctx->ribbon.type = atoi(getenv("MEDIA_CODE"));
if (ctx->ribbon.type == RIBBON_TYPE_5x7)
ctx->paper.type = PAPER_TYPE_5INCH;
}
}
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
ctx->marker.name = hiti_ribbontypes(ctx->supplies[2]);
ctx->marker.numtype = ctx->supplies[2];
ctx->marker.levelmax = hiti_ribboncounts(ctx->supplies[2]);
ctx->marker.name = hiti_ribbontypes(ctx->ribbon.type);
ctx->marker.numtype = ctx->ribbon.type;
ctx->marker.levelmax = hiti_ribboncounts(ctx->ribbon.type);
ctx->marker.levelnow = 0;
return CUPS_BACKEND_OK;
@ -1852,7 +1864,7 @@ static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copie
}
/* Sanity check against paper */
switch (ctx->supplies2[0]) {
switch (ctx->paper.type) {
case PAPER_TYPE_5INCH:
if (job->hdr.cols != 1548) {
ERROR("Illegal job on 5-inch paper!\n");
@ -1868,19 +1880,19 @@ static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copie
}
break;
default:
ERROR("Unknown paper type (%d)!\n", ctx->supplies2[0]);
ERROR("Unknown paper type (%d)!\n", ctx->paper.type);
hiti_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* Sanity check against ribbon type */
switch (ctx->supplies[2]) {
switch (ctx->ribbon.type) {
case RIBBON_TYPE_4x6:
if (job->hdr.code != PRINT_TYPE_6x4 &&
job->hdr.code != PRINT_TYPE_6x4_2UP &&
job->hdr.code != PRINT_TYPE_6x2) {
ERROR("Invalid ribbon type vs job (%02x/%02x)\n",
ctx->supplies[2], job->hdr.code);
ctx->ribbon.type, job->hdr.code);
hiti_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1890,7 +1902,7 @@ static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copie
job->hdr.code != PRINT_TYPE_5x3_5 &&
job->hdr.code != PRINT_TYPE_5x7_2UP) {
ERROR("Invalid ribbon type vs job (%02x/%02x)\n",
ctx->supplies[2], job->hdr.code);
ctx->ribbon.type, job->hdr.code);
hiti_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1901,7 +1913,7 @@ static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copie
job->hdr.code != PRINT_TYPE_6x8 &&
job->hdr.code != PRINT_TYPE_6x2) {
ERROR("Invalid ribbon type vs job (%02x/%02x)\n",
ctx->supplies[2], job->hdr.code);
ctx->ribbon.type, job->hdr.code);
hiti_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -1914,7 +1926,7 @@ static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copie
job->hdr.code != PRINT_TYPE_6x9 &&
job->hdr.code != PRINT_TYPE_6x9_2UP) {
ERROR("Invalid ribbon type vs job (%02x/%02x)\n",
ctx->supplies[2], job->hdr.code);
ctx->ribbon.type, job->hdr.code);
hiti_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -2471,15 +2483,15 @@ static int hiti_query_tphv(struct hiti_ctx *ctx)
static int hiti_query_supplies(struct hiti_ctx *ctx)
{
int ret;
uint16_t len = 5;
uint16_t len = sizeof(ctx->ribbon);
uint8_t arg = 0;
ret = hiti_docmd_resp(ctx, CMD_RDS_RSUS, &arg, sizeof(arg), ctx->supplies, &len);
ret = hiti_docmd_resp(ctx, CMD_RDS_RSUS, &arg, sizeof(arg), (uint8_t*)&ctx->ribbon, &len);
if (ret)
return ret;
len = 4;
ret = hiti_docmd_resp(ctx, CMD_RDS_RIS, NULL, 0, ctx->supplies2, &len);
len = sizeof(ctx->paper);
ret = hiti_docmd_resp(ctx, CMD_RDS_RIS, NULL, 0, (uint8_t*)&ctx->paper, &len);
if (ret)
return ret;
@ -2698,7 +2710,7 @@ static const char *hiti_prefixes[] = {
const struct dyesub_backend hiti_backend = {
.name = "HiTi Photo Printers",
.version = "0.41",
.version = "0.42",
.uri_prefixes = hiti_prefixes,
.cmdline_usage = hiti_cmdline,
.cmdline_arg = hiti_cmdline_arg,