sonyupneo: We now know how to query remaining media quantity!

(Lifetime counts still unknown..)
This commit is contained in:
Solomon Peachy 2020-12-01 22:47:40 -05:00
parent 4e7f19691a
commit 55593d7f72

View file

@ -48,6 +48,11 @@ struct sony_updsts {
uint8_t percent; /* 0-99, if job is printing (UP-D89x) */
} __attribute__((packed));
struct sony_prints {
uint8_t zero[4];
uint16_t remain; /* BE, remaining prints on media */
} __attribute((packed));
#define UPD_PRINTING_BW 0xe0 /* UPD-895/897 only */
#define UPD_PRINTING_Y 0x40
#define UPD_PRINTING_M 0x80
@ -87,7 +92,8 @@ struct upd_ctx {
int native_bpp;
struct sony_updsts stsbuf;
struct sony_updsts stsbuf;
struct sony_prints printbuf;
struct marker marker;
};
@ -106,6 +112,21 @@ static const char *upd_ribbons(int type, uint8_t code)
return "Unknown";
}
static int sonyupd_media_maxes(uint8_t type, uint8_t media)
{
if (type == P_SONY_UPDR150) {
if (media == UPD_RIBBON_R206)
return 350;
else
return 700; // XXX guess until we have more codes?
// XXX also differs for DR200 vs DR150?
} else if (type == P_SONY_UPCR10) {
return 300;
}
return CUPS_MARKER_UNAVAILABLE;
}
// UP-DR200
// 2UPC-R203 3.5x5 (770)
// 2UPC-R204 4x6 (700)
@ -188,8 +209,28 @@ static int sony_get_status(struct upd_ctx *ctx, struct sony_updsts *buf)
return CUPS_BACKEND_FAILED;
#endif
ctx->stsbuf.max_cols = be16_to_cpu(ctx->stsbuf.max_cols);
ctx->stsbuf.max_rows = be16_to_cpu(ctx->stsbuf.max_rows);
buf->max_cols = be16_to_cpu(buf->max_cols);
buf->max_rows = be16_to_cpu(buf->max_rows);
return CUPS_BACKEND_OK;
}
static int sony_get_prints(struct upd_ctx *ctx, struct sony_prints *buf)
{
int ret, num = 0;
uint8_t query[7] = { 0x1b, 0xef, 0, 0, 0, 0x06, 0 };
if ((ret = send_data(ctx->conn,
query, sizeof(query))))
return CUPS_BACKEND_FAILED;
ret = read_data(ctx->conn, (uint8_t*) buf, sizeof(*buf),
&num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
buf->remain = be16_to_cpu(buf->remain);
return CUPS_BACKEND_OK;
}
@ -226,17 +267,26 @@ static int upd_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
if ((ret = sony_get_status(ctx, &ctx->stsbuf))) {
return ret;
}
if ((ctx->conn->type != P_SONY_UPD895 && ctx->conn->type != P_SONY_UPD897) && (ret = sony_get_prints(ctx, &ctx->printbuf))) {
return ret;
}
}
if (test_mode >= TEST_MODE_NOATTACH && getenv("MEDIA_CODE")) {
ctx->marker.numtype = atoi(getenv("MEDIA_CODE"));
} else {
ctx->marker.numtype = ctx->stsbuf.paper;
ctx->marker.numtype = ctx->stsbuf.ribbon;
}
ctx->marker.name = upd_ribbons(ctx->conn->type, ctx->stsbuf.ribbon);
ctx->marker.levelmax = CUPS_MARKER_UNAVAILABLE;
ctx->marker.levelnow = CUPS_MARKER_UNKNOWN;
if (test_mode >= TEST_MODE_NOATTACH || ctx->conn->type == P_SONY_UPD895 || ctx->conn->type == P_SONY_UPD897) {
ctx->marker.levelmax = CUPS_MARKER_UNAVAILABLE;
ctx->marker.levelnow = CUPS_MARKER_UNKNOWN;
} else {
ctx->marker.levelmax = sonyupd_media_maxes(ctx->conn->type, ctx->stsbuf.paper);
ctx->marker.levelnow = ctx->printbuf.remain;
}
return CUPS_BACKEND_OK;
}
@ -392,6 +442,8 @@ static int upd_read_parse(void *vctx, const void **vjob, int data_fd, int copies
case 0x15: /* Print dimensions */
param_offset = job->datalen + 16 + offset;
break;
// XXX case 0xc0:
// for param 03, take the value at offset 4 -- for (eg) 4x6 on 8x6 media, needs to be set to 0x02
case 0xee:
copies_offset = job->datalen + 7 + offset;
break;
@ -644,9 +696,17 @@ static int upd_query_markers(void *vctx, struct marker **markers, int *count)
if (ret)
return CUPS_BACKEND_FAILED;
if (ctx->conn->type != P_SONY_UPD895 && ctx->conn->type != P_SONY_UPD897 && (ret = sony_get_prints(ctx, &ctx->printbuf))) {
return CUPS_BACKEND_FAILED;
}
if (ctx->stsbuf.sts1 == UPD_STS1_NOPAPER ||
ctx->stsbuf.sts1 == UPD_STS1_DOOROPEN) {
ctx->marker.levelnow = 0;
if (ctx->conn->type == P_SONY_UPD895 || ctx->conn->type == P_SONY_UPD897) {
ctx->marker.levelnow = 0;
} else {
ctx->marker.levelnow = ctx->printbuf.remain;
}
} else {
ctx->marker.levelnow = CUPS_MARKER_UNKNOWN_OK;
}
@ -672,7 +732,7 @@ static const char *sonyupd_prefixes[] = {
const struct dyesub_backend sonyupd_backend = {
.name = "Sony UP-D",
.version = "0.43",
.version = "0.44",
.uri_prefixes = sonyupd_prefixes,
.cmdline_arg = upd_cmdline_arg,
.cmdline_usage = upd_cmdline,
@ -725,7 +785,7 @@ const struct dyesub_backend sonyupd_backend = {
UNKNOWN QUERY [possibly media?]
<- 1b 03 00 00 00 13 00
<- 1b 03 00 00 00 13 00
-> 70 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00
00 00 00
@ -735,11 +795,11 @@ const struct dyesub_backend sonyupd_backend = {
PRINT DIMENSIONS
<- 1b 15 00 00 00 0d 00
<- 1b 15 00 00 00 0d 00
<- 00 00 00 00 ZZ QQ QQ WW WW YY YY XX XX
QQ/WW/YY/XX are (origin_cols/origin_rows/cols/rows) in BE.
ZZ is 0x07 on UP-DR series, 0x01 on UP-D89x series.
ZZ is 0x07 on UP-DR series, 0x01 on UP-D89x series. plane mask maybe?
RESET
@ -755,12 +815,12 @@ const struct dyesub_backend sonyupd_backend = {
SET PARAM
<- 1b c0 00 NN LL 00 00 # LL is response length, NN is number.
<- 1b c0 00 NN 00 LL 00 # LL is response length, NN is number.
<- [ LL bytes]
QUERY PARAM
<- 1b c1 00 NN LL 00 00 # LL is response length, NN is number.
<- 1b c1 00 NN 00 LL 00 # LL is response length, NN is number.
-> [ LL bytes ]
PARAMS SEEN:
@ -771,22 +831,22 @@ const struct dyesub_backend sonyupd_backend = {
STATUS QUERY
<- 1b e0 00 00 00 XX 00 # XX = 0xe (UP-D895), 0xf (All others)
<- 1b e0 00 00 00 XX 00 # XX = 0xe (UP-D895), 0xf (All others)
-> [14 or 15 bytes, see 'struct sony_updsts' ]
IMAGE DIMENSIONS & OVERCOAT
<- 1b e1 00 00 00 0b 00
<- 1b e1 00 00 00 0b 00
<- 00 ZZ QQ 00 00 00 00 XX XX YY YY # XX = cols, YY == rows, ZZ == 0x04 on UP-DP10, otherwise 0x80. QQ == 00 glossy, 08 texture (UP-DP10 + UP-DR150), 0c matte, +0x10 for "nocorrection" on UP-DR200..
UNKNOWN
<- 1b e5 00 00 00 08 00
<- 1b e5 00 00 00 08 00
<- 00 00 00 00 00 00 00 XX 00 # Seen 01, 12, 0d, etc.
UNKNOWN (UP-D897)
<- 1b e6 00 00 00 08 00
<- 1b e6 00 00 00 08 00
<- 07 00 00 00 00 00 00 00
DATA TRANSFER
@ -796,21 +856,21 @@ const struct dyesub_backend sonyupd_backend = {
UNKNOWN CMD (UP-DR and UP-D)
<- 1b ed 00 00 00 00 00
<- 1b ed 00 00 00 00 00
UNKNOWN (UPDR series)
QUERY REMAINING PRINTS (UPDR series)
<- 1b ef 00 00 00 06 00
-> 05 00 00 00 00 22
<- 1b ef 00 00 00 06 00
-> 05 00 00 00 NN NN # NN NN print count on media remaining
COPIES
<- 1b ee 00 00 00 02 00
<- 1b ee 00 00 00 02 00
<- NN NN # Number of copies (BE, 1-???)
UNKNOWN (UPDR series)
<- 1b f5 00 00 00 02 00
<- 1b f5 00 00 00 02 00
<- ?? ??
************************************************************************