| 1 | /* |
| 2 | * Canon SELPHY CPneo series CUPS backend |
| 3 | * |
| 4 | * (c) 2016-2024 Solomon Peachy <[email protected]> |
| 5 | * |
| 6 | * The latest version of this program can be found at: |
| 7 | * |
| 8 | * https://git.shaftnet.org/gitea/slp/selphy_print.git |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 17 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 18 | * for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, see <https://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | * SPDX-License-Identifier: GPL-2.0+ |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #define BACKEND canonselphyneo_backend |
| 28 | |
| 29 | #include "backend_common.h" |
| 30 | |
| 31 | /* Header data structure */ |
| 32 | struct selphyneo_hdr { |
| 33 | uint8_t data[24]; |
| 34 | uint32_t cols; /* LE */ |
| 35 | uint32_t rows; /* LE */ |
| 36 | } __attribute((packed)); |
| 37 | |
| 38 | /* Readback data structure */ |
| 39 | struct selphyneo_readback { |
| 40 | uint8_t data[12]; |
| 41 | } __attribute((packed)); |
| 42 | |
| 43 | /* Private data structure */ |
| 44 | struct selphyneo_printjob { |
| 45 | struct dyesub_job_common common; |
| 46 | |
| 47 | uint8_t *databuf; |
| 48 | uint32_t datalen; |
| 49 | }; |
| 50 | |
| 51 | struct selphyneo_ctx { |
| 52 | struct dyesub_connection *conn; |
| 53 | |
| 54 | struct marker marker; |
| 55 | }; |
| 56 | |
| 57 | static const char *selphyneo_statuses(uint8_t sts) |
| 58 | { |
| 59 | switch(sts) { |
| 60 | case 0x01: |
| 61 | return "Idle"; |
| 62 | case 0x02: |
| 63 | return "Feeding Paper"; |
| 64 | case 0x04: |
| 65 | return "Printing YELLOW"; |
| 66 | case 0x08: |
| 67 | return "Printing MAGENTA"; |
| 68 | case 0x10: |
| 69 | return "Printing CYAN"; |
| 70 | case 0x20: |
| 71 | return "Printing LAMINATE"; |
| 72 | default: |
| 73 | return "Unknown state!"; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | static const char *selphyneo_errors(uint8_t err) |
| 78 | { |
| 79 | switch(err) { |
| 80 | case 0x00: |
| 81 | return "None"; |
| 82 | case 0x01: |
| 83 | return "Low battery"; |
| 84 | case 0x02: |
| 85 | return "Paper Feed (No Paper?)"; |
| 86 | case 0x03: |
| 87 | return "No Paper Tray"; |
| 88 | case 0x04: |
| 89 | return "Incorrect Paper Tray"; |
| 90 | case 0x05: |
| 91 | return "Incorrect Paper loaded"; |
| 92 | case 0x06: |
| 93 | return "Ink Cassette Empty"; |
| 94 | case 0x07: |
| 95 | return "No Ink"; |
| 96 | case 0x08: |
| 97 | return "Incorrect Ink loaded"; |
| 98 | case 0x09: |
| 99 | return "No Paper and Ink"; |
| 100 | case 0x0A: |
| 101 | return "Incorrect paper tray and ink for job"; |
| 102 | case 0x0B: |
| 103 | return "Paper jam"; |
| 104 | case 0x0C: |
| 105 | return "Ink jam"; |
| 106 | case 0x0D: |
| 107 | return "Ink illegal"; |
| 108 | case 0x0E: |
| 109 | return "Unknown Ink"; |
| 110 | case 0x0F: |
| 111 | return "Unknown Paper"; |
| 112 | case 0x10: |
| 113 | return "Unknown Command"; |
| 114 | default: |
| 115 | return "Unknown Error"; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | static const char *selphynew_pgcodes(uint8_t type) { |
| 120 | |
| 121 | switch (type & 0xf) { |
| 122 | case 0x01: |
| 123 | return "P"; |
| 124 | case 0x02: |
| 125 | return "L"; |
| 126 | case 0x03: |
| 127 | return "C"; |
| 128 | case 0x00: |
| 129 | return "None"; |
| 130 | default: |
| 131 | return "Unknown"; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | static const char *selphyneo_powers(uint8_t sts) { |
| 136 | |
| 137 | switch (sts & 0x3) { |
| 138 | case 0x00: |
| 139 | return "Line Power"; |
| 140 | case 0x01: |
| 141 | return "Battery OK"; |
| 142 | case 0x03: |
| 143 | return "Battery Low"; |
| 144 | default: |
| 145 | return "Unknown"; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | static int selphyneo_send_reset(struct selphyneo_ctx *ctx) |
| 150 | { |
| 151 | uint8_t rstcmd[12] = { 0x40, 0x10, 0x00, 0x00, |
| 152 | 0x00, 0x00, 0x00, 0x00, |
| 153 | 0x00, 0x00, 0x00, 0x00 }; |
| 154 | int ret; |
| 155 | |
| 156 | if ((ret = send_data(ctx->conn, |
| 157 | rstcmd, sizeof(rstcmd)))) |
| 158 | return CUPS_BACKEND_FAILED; |
| 159 | |
| 160 | return CUPS_BACKEND_OK; |
| 161 | } |
| 162 | |
| 163 | static int selphyneo_get_status(struct selphyneo_ctx *ctx) |
| 164 | { |
| 165 | struct selphyneo_readback rdback; |
| 166 | int ret, num; |
| 167 | |
| 168 | /* Read in the printer status to clear last state */ |
| 169 | ret = read_data(ctx->conn, |
| 170 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 171 | |
| 172 | if (ret < 0) |
| 173 | return CUPS_BACKEND_FAILED; |
| 174 | |
| 175 | /* And again, for the markers */ |
| 176 | ret = read_data(ctx->conn, |
| 177 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 178 | |
| 179 | if (ret < 0) |
| 180 | return CUPS_BACKEND_FAILED; |
| 181 | |
| 182 | INFO("Printer state: %s\n", selphyneo_statuses(rdback.data[0])); |
| 183 | INFO("Printer power state: %s\n", selphyneo_powers(rdback.data[7])); |
| 184 | INFO("Media type: %s\n", selphynew_pgcodes(rdback.data[6])); |
| 185 | if (rdback.data[2]) { |
| 186 | INFO("Printer error: %s\n", selphyneo_errors(rdback.data[2])); |
| 187 | } |
| 188 | |
| 189 | return CUPS_BACKEND_OK; |
| 190 | } |
| 191 | |
| 192 | static void *selphyneo_init(void) |
| 193 | { |
| 194 | struct selphyneo_ctx *ctx = malloc(sizeof(struct selphyneo_ctx)); |
| 195 | if (!ctx) { |
| 196 | ERROR("Memory Allocation Failure!\n"); |
| 197 | return NULL; |
| 198 | } |
| 199 | memset(ctx, 0, sizeof(struct selphyneo_ctx)); |
| 200 | |
| 201 | return ctx; |
| 202 | } |
| 203 | |
| 204 | static int selphyneo_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid) |
| 205 | { |
| 206 | struct selphyneo_ctx *ctx = vctx; |
| 207 | struct selphyneo_readback rdback; |
| 208 | int ret, num; |
| 209 | |
| 210 | UNUSED(jobid); |
| 211 | |
| 212 | ctx->conn = conn; |
| 213 | |
| 214 | if (test_mode < TEST_MODE_NOATTACH) { |
| 215 | /* Read in the printer status to clear last state */ |
| 216 | ret = read_data(ctx->conn, |
| 217 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 218 | |
| 219 | if (ret < 0) |
| 220 | return CUPS_BACKEND_FAILED; |
| 221 | |
| 222 | /* And again, for the markers */ |
| 223 | ret = read_data(ctx->conn, |
| 224 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 225 | |
| 226 | if (ret < 0) |
| 227 | return CUPS_BACKEND_FAILED; |
| 228 | } else { |
| 229 | rdback.data[2] = 0; |
| 230 | rdback.data[6] = 0x01; |
| 231 | if (getenv("MEDIA_CODE")) |
| 232 | rdback.data[6] = strtol(getenv("MEDIA_CODE"), NULL, 16); |
| 233 | } |
| 234 | |
| 235 | ctx->marker.color = "#00FFFF#FF00FF#FFFF00"; |
| 236 | ctx->marker.name = selphynew_pgcodes(rdback.data[6]); |
| 237 | ctx->marker.numtype = rdback.data[6]; |
| 238 | ctx->marker.levelmax = CUPS_MARKER_UNAVAILABLE; |
| 239 | if (rdback.data[2]) { |
| 240 | ctx->marker.levelnow = 0; |
| 241 | } else { |
| 242 | ctx->marker.levelnow = CUPS_MARKER_UNKNOWN_OK; |
| 243 | } |
| 244 | |
| 245 | return CUPS_BACKEND_OK; |
| 246 | } |
| 247 | |
| 248 | static void selphyneo_cleanup_job(const void *vjob) { |
| 249 | const struct selphyneo_printjob *job = vjob; |
| 250 | |
| 251 | if (job->databuf) |
| 252 | free(job->databuf); |
| 253 | |
| 254 | free((void*)job); |
| 255 | } |
| 256 | |
| 257 | static int selphyneo_read_parse(void *vctx, const void **vjob, int data_fd, int copies) |
| 258 | { |
| 259 | struct selphyneo_ctx *ctx = vctx; |
| 260 | struct selphyneo_hdr hdr; |
| 261 | int i, remain; |
| 262 | |
| 263 | struct selphyneo_printjob *job = NULL; |
| 264 | |
| 265 | if (!ctx) |
| 266 | return CUPS_BACKEND_FAILED; |
| 267 | |
| 268 | job = malloc(sizeof(*job)); |
| 269 | if (!job) { |
| 270 | ERROR("Memory allocation failure!\n"); |
| 271 | return CUPS_BACKEND_RETRY_CURRENT; |
| 272 | } |
| 273 | memset(job, 0, sizeof(*job)); |
| 274 | job->common.jobsize = sizeof(*job); |
| 275 | job->common.copies = copies; |
| 276 | |
| 277 | /* Read the header.. */ |
| 278 | i = read(data_fd, &hdr, sizeof(hdr)); |
| 279 | if (i != sizeof(hdr)) { |
| 280 | if (i == 0) { |
| 281 | selphyneo_cleanup_job(job); |
| 282 | return CUPS_BACKEND_CANCEL; |
| 283 | } |
| 284 | ERROR("Read failed (%d/%d)\n", |
| 285 | i, (int)sizeof(hdr)); |
| 286 | perror("ERROR: Read failed"); |
| 287 | selphyneo_cleanup_job(job); |
| 288 | return CUPS_BACKEND_FAILED; |
| 289 | } |
| 290 | |
| 291 | /* Determine job length */ |
| 292 | switch(hdr.data[18]) { |
| 293 | case 0x50: /* P */ |
| 294 | case 0x4c: /* L */ |
| 295 | case 0x43: /* C */ |
| 296 | remain = le32_to_cpu(hdr.cols) * le32_to_cpu(hdr.rows) * 3; |
| 297 | break; |
| 298 | default: |
| 299 | ERROR("Unknown print size! (%02x, %ux%u)\n", |
| 300 | hdr.data[10], le32_to_cpu(hdr.cols), le32_to_cpu(hdr.rows)); |
| 301 | selphyneo_cleanup_job(job); |
| 302 | return CUPS_BACKEND_CANCEL; |
| 303 | } |
| 304 | |
| 305 | // XXX Sanity check job against loaded media? |
| 306 | |
| 307 | /* Allocate a buffer */ |
| 308 | job->datalen = 0; |
| 309 | job->databuf = malloc(remain + sizeof(hdr)); |
| 310 | if (!job->databuf) { |
| 311 | ERROR("Memory allocation failure!\n"); |
| 312 | selphyneo_cleanup_job(job); |
| 313 | return CUPS_BACKEND_RETRY_CURRENT; |
| 314 | } |
| 315 | |
| 316 | /* Store the read-in header */ |
| 317 | memcpy(job->databuf, &hdr, sizeof(hdr)); |
| 318 | job->datalen += sizeof(hdr); |
| 319 | |
| 320 | /* Read in data */ |
| 321 | while (remain > 0) { |
| 322 | i = read(data_fd, job->databuf + job->datalen, remain); |
| 323 | if (i < 0) { |
| 324 | selphyneo_cleanup_job(job); |
| 325 | return CUPS_BACKEND_CANCEL; |
| 326 | } |
| 327 | remain -= i; |
| 328 | job->datalen += i; |
| 329 | } |
| 330 | |
| 331 | *vjob = job; |
| 332 | |
| 333 | return CUPS_BACKEND_OK; |
| 334 | } |
| 335 | |
| 336 | static int selphyneo_main_loop(void *vctx, const void *vjob, int wait_for_return) { |
| 337 | struct selphyneo_ctx *ctx = vctx; |
| 338 | struct selphyneo_readback rdback; |
| 339 | |
| 340 | int ret, num; |
| 341 | int copies; |
| 342 | |
| 343 | const struct selphyneo_printjob *job = vjob; |
| 344 | |
| 345 | if (!ctx) |
| 346 | return CUPS_BACKEND_FAILED; |
| 347 | if (!job) |
| 348 | return CUPS_BACKEND_FAILED; |
| 349 | |
| 350 | copies = job->common.copies; |
| 351 | |
| 352 | /* Read in the printer status to clear last state */ |
| 353 | ret = read_data(ctx->conn, |
| 354 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 355 | |
| 356 | if (ret < 0) |
| 357 | return CUPS_BACKEND_FAILED; |
| 358 | |
| 359 | top: |
| 360 | INFO("Waiting for printer idle\n"); |
| 361 | |
| 362 | do { |
| 363 | ret = read_data(ctx->conn, |
| 364 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 365 | |
| 366 | if (ret < 0) |
| 367 | return CUPS_BACKEND_FAILED; |
| 368 | |
| 369 | if (rdback.data[0] == 0x01) |
| 370 | break; |
| 371 | |
| 372 | INFO("Printer state: %s\n", selphyneo_statuses(rdback.data[0])); |
| 373 | |
| 374 | switch (rdback.data[2]) { |
| 375 | case 0x00: |
| 376 | break; |
| 377 | case 0x0A: |
| 378 | ERROR("Printer error: %s (%02x)\n", selphyneo_errors(rdback.data[2]), rdback.data[2]); |
| 379 | ctx->marker.levelnow = 0; |
| 380 | dump_markers(&ctx->marker, 1, 0); |
| 381 | return CUPS_BACKEND_CANCEL; |
| 382 | default: |
| 383 | ERROR("Printer error: %s (%02x)\n", selphyneo_errors(rdback.data[2]), rdback.data[2]); |
| 384 | ctx->marker.levelnow = 0; |
| 385 | dump_markers(&ctx->marker, 1, 0); |
| 386 | return CUPS_BACKEND_STOP; |
| 387 | } |
| 388 | |
| 389 | sleep(1); |
| 390 | } while(1); |
| 391 | |
| 392 | dump_markers(&ctx->marker, 1, 0); |
| 393 | |
| 394 | INFO("Sending spool data\n"); |
| 395 | /* Send the data over in 256K chunks */ |
| 396 | { |
| 397 | int chunk = 256*1024; |
| 398 | int sent = 0; |
| 399 | while (chunk > 0) { |
| 400 | if ((ret = send_data(ctx->conn, |
| 401 | job->databuf + sent, chunk))) |
| 402 | return CUPS_BACKEND_FAILED; |
| 403 | sent += chunk; |
| 404 | chunk = job->datalen - sent; |
| 405 | if (chunk > 256*1024) |
| 406 | chunk = 256*1024; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | /* Read in the printer status to clear last state */ |
| 411 | ret = read_data(ctx->conn, |
| 412 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 413 | |
| 414 | if (ret < 0) |
| 415 | return CUPS_BACKEND_FAILED; |
| 416 | |
| 417 | INFO("Waiting for printer acknowledgement\n"); |
| 418 | do { |
| 419 | ret = read_data(ctx->conn, |
| 420 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 421 | |
| 422 | if (ret < 0) |
| 423 | return CUPS_BACKEND_FAILED; |
| 424 | |
| 425 | if (rdback.data[0] == 0x01) |
| 426 | break; |
| 427 | |
| 428 | INFO("Printer state: %s\n", selphyneo_statuses(rdback.data[0])); |
| 429 | |
| 430 | switch (rdback.data[2]) { |
| 431 | case 0x00: |
| 432 | break; |
| 433 | case 0x0A: |
| 434 | ERROR("Printer error: %s (%02x)\n", selphyneo_errors(rdback.data[2]), rdback.data[2]); |
| 435 | ctx->marker.levelnow = 0; |
| 436 | dump_markers(&ctx->marker, 1, 0); |
| 437 | return CUPS_BACKEND_CANCEL; |
| 438 | default: |
| 439 | ERROR("Printer error: %s (%02x)\n", selphyneo_errors(rdback.data[2]), rdback.data[2]); |
| 440 | ctx->marker.levelnow = 0; |
| 441 | dump_markers(&ctx->marker, 1, 0); |
| 442 | return CUPS_BACKEND_STOP; |
| 443 | } |
| 444 | |
| 445 | if (rdback.data[0] > 0x02 && !wait_for_return && copies <= 1) { |
| 446 | INFO("Fast return mode enabled.\n"); |
| 447 | break; |
| 448 | } |
| 449 | |
| 450 | sleep(1); |
| 451 | } while(1); |
| 452 | |
| 453 | /* Clean up */ |
| 454 | if (terminate) |
| 455 | copies = 1; |
| 456 | |
| 457 | INFO("Print complete (%d copies remaining)\n", copies - 1); |
| 458 | |
| 459 | if (copies && --copies) { |
| 460 | goto top; |
| 461 | } |
| 462 | |
| 463 | return CUPS_BACKEND_OK; |
| 464 | } |
| 465 | |
| 466 | static int selphyneo_cmdline_arg(void *vctx, int argc, char **argv) |
| 467 | { |
| 468 | struct selphyneo_ctx *ctx = vctx; |
| 469 | int i, j = 0; |
| 470 | |
| 471 | if (!ctx) |
| 472 | return -1; |
| 473 | |
| 474 | while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "Rs")) >= 0) { |
| 475 | switch(i) { |
| 476 | GETOPT_PROCESS_GLOBAL |
| 477 | case 'R': |
| 478 | selphyneo_send_reset(ctx); |
| 479 | break; |
| 480 | case 's': |
| 481 | selphyneo_get_status(ctx); |
| 482 | break; |
| 483 | } |
| 484 | |
| 485 | if (j) return j; |
| 486 | } |
| 487 | |
| 488 | return CUPS_BACKEND_OK; |
| 489 | } |
| 490 | |
| 491 | static void selphyneo_cmdline(void) |
| 492 | { |
| 493 | DEBUG("\t\t[ -R ] # Reset printer\n"); |
| 494 | DEBUG("\t\t[ -s ] # Query printer status\n"); |
| 495 | } |
| 496 | |
| 497 | static int selphyneo_query_markers(void *vctx, struct marker **markers, int *count) |
| 498 | { |
| 499 | struct selphyneo_ctx *ctx = vctx; |
| 500 | struct selphyneo_readback rdback; |
| 501 | int ret, num; |
| 502 | |
| 503 | /* Read in the printer status to clear last state */ |
| 504 | ret = read_data(ctx->conn, |
| 505 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 506 | |
| 507 | if (ret < 0) |
| 508 | return CUPS_BACKEND_FAILED; |
| 509 | |
| 510 | /* And again, for the markers */ |
| 511 | ret = read_data(ctx->conn, |
| 512 | (uint8_t*) &rdback, sizeof(rdback), &num); |
| 513 | |
| 514 | if (ret < 0) |
| 515 | return CUPS_BACKEND_FAILED; |
| 516 | |
| 517 | if (rdback.data[2]) |
| 518 | ctx->marker.levelnow = 0; |
| 519 | else |
| 520 | ctx->marker.levelnow = CUPS_MARKER_UNKNOWN_OK; |
| 521 | |
| 522 | *markers = &ctx->marker; |
| 523 | *count = 1; |
| 524 | |
| 525 | return CUPS_BACKEND_OK; |
| 526 | } |
| 527 | |
| 528 | static const char *canonselphyneo_prefixes[] = { |
| 529 | "canonselphyneo", // Family name |
| 530 | // backwards compatibility |
| 531 | "selphycp820", "selphycp910", "selphycp1000", "selphycp1200", "selphycp1300", |
| 532 | NULL |
| 533 | }; |
| 534 | |
| 535 | static const struct device_id selphyneo_devices[] = { |
| 536 | { 0x04a9, 0x327b, P_CP910, NULL, "canon-cp820"}, |
| 537 | { 0x04a9, 0x327a, P_CP910, NULL, "canon-cp910"}, |
| 538 | { 0x04a9, 0x32ae, P_CP910, NULL, "canon-cp1000"}, |
| 539 | { 0x04a9, 0x32b1, P_CP910, NULL, "canon-cp1200"}, |
| 540 | { 0x04a9, 0x32db, P_CP910, NULL, "canon-cp1300"}, |
| 541 | { 0x04a9, 0x3302, P_CP910, NULL, "canon-cp1500"}, |
| 542 | { 0, 0, 0, NULL, NULL} |
| 543 | }; |
| 544 | |
| 545 | const struct dyesub_backend canonselphyneo_backend = { |
| 546 | .name = "Canon SELPHY CP (new)", |
| 547 | .version = "0.24", |
| 548 | .uri_prefixes = canonselphyneo_prefixes, |
| 549 | .cmdline_usage = selphyneo_cmdline, |
| 550 | .cmdline_arg = selphyneo_cmdline_arg, |
| 551 | .init = selphyneo_init, |
| 552 | .attach = selphyneo_attach, |
| 553 | .cleanup_job = selphyneo_cleanup_job, |
| 554 | .read_parse = selphyneo_read_parse, |
| 555 | .main_loop = selphyneo_main_loop, |
| 556 | .query_markers = selphyneo_query_markers, |
| 557 | .devices = selphyneo_devices, |
| 558 | }; |
| 559 | /* |
| 560 | |
| 561 | *************************************************************************** |
| 562 | |
| 563 | Stream formats and readback codes for supported printers |
| 564 | |
| 565 | *************************************************************************** |
| 566 | Selphy CP820/CP910/CP1000/CP1200/CP1300/CP1500: |
| 567 | |
| 568 | Radically different spool file format from older Selphy models. |
| 569 | 300dpi, same nominal print sizes but slightly different dimensions. |
| 570 | |
| 571 | There is also a "mini" 50mm sticker media, but I think the printer |
| 572 | treats them as 'C' size. |
| 573 | |
| 574 | 32-byte header: |
| 575 | |
| 576 | 0f 00 00 40 00 00 00 00 00 00 00 00 00 00 01 00 |
| 577 | 01 00 TT 00 00 00 00 ZZ XX XX XX XX YY YY YY YY |
| 578 | |
| 579 | size cols (le32) rows (le32) |
| 580 | 50 e0 04 50 07 1248 * 1872 (P) |
| 581 | 4c 80 04 c0 05 1152 * 1472 (L) |
| 582 | 43 40 04 9c 02 1088 * 668 (C) |
| 583 | |
| 584 | ZZ == 00 YUV444 data follows |
| 585 | == 01 CMY data follows |
| 586 | |
| 587 | Followed by three planes of image data: |
| 588 | |
| 589 | P == 7008800 (2336256 * 3) |
| 590 | L == 5087264 (1695744 * 3) |
| 591 | C == 2180384 (726784 * 3) |
| 592 | |
| 593 | RGB -> YUV444 is as follows: |
| 594 | |
| 595 | Y = ( 77 * R + 150 * G + 29 * B + 128 ) >> 8 |
| 596 | U = ( ( -43 * R + 85 * G + 128 * B + 128 ) >> 8 ) + 128 |
| 597 | V = ( ( 128 * R - 107 * G - 21 * B + 128 ) >> 8 ) + 128 |
| 598 | |
| 599 | Other questions: |
| 600 | |
| 601 | * Printer supports different lamination types, how to control? |
| 602 | - Glossy |
| 603 | - Pattern 1 (Matte) |
| 604 | - Pattern 2 (Fine Matte) |
| 605 | - Pattern 3 (Grid - not all models?) |
| 606 | |
| 607 | Data Readback: |
| 608 | |
| 609 | XX 00 YY 00 00 00 ZZ PP 00 00 00 00 |
| 610 | |
| 611 | XX == Status |
| 612 | |
| 613 | 01 Idle |
| 614 | 02 Feeding Paper |
| 615 | 04 Printing Y |
| 616 | 08 Printing M |
| 617 | 10 Printing C |
| 618 | 20 Printing L |
| 619 | |
| 620 | YY == Error |
| 621 | |
| 622 | 00 None |
| 623 | 02 No Paper (?) |
| 624 | 03 No Paper |
| 625 | 05 Wrong Paper |
| 626 | 07 No Ink |
| 627 | 09 No Paper and Ink |
| 628 | 0A Media/Job mismatch |
| 629 | 0B Paper Jam |
| 630 | |
| 631 | ZZ == Media |
| 632 | |
| 633 | 01 |
| 634 | 10 |
| 635 | 11 |
| 636 | ^-- Ribbon |
| 637 | ^-- Paper |
| 638 | |
| 639 | 1 == P |
| 640 | 2 == L |
| 641 | 3 == C |
| 642 | |
| 643 | PP == Power state |
| 644 | |
| 645 | 00 = A/C power |
| 646 | 01 = Battery OK |
| 647 | 03 = Battery Low |
| 648 | |
| 649 | Also, the first time a readback happens after plugging in the printer: |
| 650 | |
| 651 | 34 44 35 31 01 00 01 00 01 00 45 00 "4D51" ...?? |
| 652 | 34 44 35 31 01 00 01 00 01 00 54 00 [also seen..] |
| 653 | |
| 654 | |
| 655 | ** ** ** ** This is what windows sends if you print over the network: |
| 656 | |
| 657 | 00 00 00 00 40 00 00 00 02 00 00 00 00 00 04 00 Header [unknown] |
| 658 | 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 659 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 660 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 661 | |
| 662 | 00 00 01 00 HH HH HH HH 02 00 00 00 PP PP PP PP Header2 [unknown] PP == payload len, HH == payload + header2 len [ie + 3 ] |
| 663 | CC CC CC CC RR RR RR RR 00 00 00 00 LL LL LL LL CC == cols, RR == rows, LL == plane len (ie RR * CC) |
| 664 | L2 L2 L2 L2 L2 == LL * 2, apparently. |
| 665 | |
| 666 | [ ..followed by three planes of LL bytes, totalling PP bytes.. ] |
| 667 | |
| 668 | */ |