shinkos2145: Add support for CUPS marker attributes.

* Guessimate remaining ribbon into a percentage.
This commit is contained in:
Solomon Peachy 2016-08-17 20:46:00 -04:00
parent 4d490b60bb
commit fcdcc6de60

View file

@ -103,6 +103,9 @@ struct shinkos2145_ctx {
uint8_t *databuf;
int datalen;
uint16_t last_donor;
uint16_t last_remain;
};
/* Structs for printer */
@ -1394,6 +1397,9 @@ static void shinkos2145_attach(void *vctx, struct libusb_device_handle *dev,
ctx->jobid = (jobid & 0x7f);
if (!ctx->jobid)
ctx->jobid++;
/* Initialize donor */
ctx->last_donor = ctx->last_remain = 65535;
}
static void shinkos2145_teardown(void *vctx) {
@ -1530,6 +1536,13 @@ static int shinkos2145_main_loop(void *vctx, int copies) {
return CUPS_BACKEND_HOLD;
}
/* Tell CUPS about the consumables we report */
ATTR("marker-colors=#00FFFF#FF00FF#FFFF00\n");
ATTR("marker-high-levels=100\n");
ATTR("marker-low-levels=10\n");
ATTR("marker-names=Ribbon\n");
ATTR("marker-types=ribbon\n");
// XXX check copies against remaining media!
top:
@ -1552,10 +1565,25 @@ top:
}
if (memcmp(rdbuf, rdbuf2, READBACK_LEN)) {
uint16_t donor, remain;
memcpy(rdbuf2, rdbuf, READBACK_LEN);
INFO("Printer Status: 0x%02x (%s)\n",
sts->hdr.status, status_str(sts->hdr.status));
/* Guessimate a percentage for the remaining media */
donor = le32_to_cpu(sts->count_ribbon_left) * 100 / (le32_to_cpu(sts->count_ribbon_left)+le32_to_cpu(sts->count_paper));
if (donor != ctx->last_donor) {
ctx->last_donor = donor;
ATTR("marker-levels=%d\n", donor);
}
remain = le32_to_cpu(sts->count_ribbon_left);
if (remain != ctx->last_remain) {
ctx->last_remain = remain;
ATTR("marker-message=\"%d prints remaining on ribbon\"\n", remain);
}
if (sts->hdr.result != RESULT_SUCCESS)
goto printer_error;
if (sts->hdr.error == ERROR_PRINTER)
@ -1702,7 +1730,7 @@ static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t end
struct dyesub_backend shinkos2145_backend = {
.name = "Shinko/Sinfonia CHC-S2145",
.version = "0.47",
.version = "0.48",
.uri_prefix = "shinkos2145",
.cmdline_usage = shinkos2145_cmdline,
.cmdline_arg = shinkos2145_cmdline_arg,