| 1 | /* |
| 2 | * Canon SELPHY ES/CP series CUPS backend |
| 3 | * |
| 4 | * (c) 2007-2026 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 canonselphy_backend |
| 28 | |
| 29 | #include "backend_common.h" |
| 30 | |
| 31 | #define P_ES40_CP790 (P_END + 1) // used for detection only |
| 32 | |
| 33 | #define READBACK_LEN 12 |
| 34 | |
| 35 | struct printer_data { |
| 36 | int type; /* P_??? */ |
| 37 | const char *model; /* eg "SELPHY ES1" */ |
| 38 | uint16_t init_length; |
| 39 | uint16_t foot_length; |
| 40 | int16_t init_readback[READBACK_LEN]; |
| 41 | int16_t ready_y_readback[READBACK_LEN]; |
| 42 | int16_t ready_m_readback[READBACK_LEN]; |
| 43 | int16_t ready_c_readback[READBACK_LEN]; |
| 44 | int16_t done_c_readback[READBACK_LEN]; |
| 45 | uint8_t clear_error[READBACK_LEN]; |
| 46 | uint8_t clear_error_len; |
| 47 | int16_t paper_codes[256]; |
| 48 | int8_t pgcode_offset; /* Offset into printjob for paper type */ |
| 49 | int8_t paper_code_offset; /* Offset in readback for paper type */ |
| 50 | int8_t paper_code_offset2; /* Offset in readback for paper type (2nd) */ |
| 51 | uint8_t (*error_detect)(const uint8_t *rdbuf); |
| 52 | const char *(*pgcode_names)(const uint8_t *rdbuf, const struct printer_data *printer, int *numtype); |
| 53 | }; |
| 54 | |
| 55 | static const char *generic_pgcode_names(const uint8_t *rdbuf, const struct printer_data *printer, int *numtype) |
| 56 | { |
| 57 | uint8_t pgcode = 0, pgcode2 = 0; |
| 58 | |
| 59 | if (printer->paper_code_offset != -1) |
| 60 | pgcode = rdbuf[printer->paper_code_offset]; |
| 61 | if (printer->paper_code_offset2 != -1) |
| 62 | pgcode2 = rdbuf[printer->paper_code_offset2]; |
| 63 | |
| 64 | *numtype = pgcode & 0xf; |
| 65 | |
| 66 | switch(pgcode & 0xf) { |
| 67 | case 0x01: return "P"; |
| 68 | case 0x02: return "L"; |
| 69 | case 0x03: return pgcode2 ? "Cl" : "C"; |
| 70 | case 0x04: return "W"; |
| 71 | case 0x0f: return "None"; |
| 72 | default: return "Unknown"; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | static uint8_t es1_error_detect(const uint8_t *rdbuf) |
| 77 | { |
| 78 | if (rdbuf[1] == 0x01) { |
| 79 | if (rdbuf[9] == 0x00) |
| 80 | ERROR("Cover open!\n"); |
| 81 | else |
| 82 | ERROR("Unknown error %02x\n", rdbuf[9]); |
| 83 | return 1; |
| 84 | } else if (rdbuf[4] == 0x01 && rdbuf[5] == 0xff && |
| 85 | rdbuf[6] == 0xff && rdbuf[7] == 0xff) { |
| 86 | ERROR("No media loaded!\n"); |
| 87 | return 1; |
| 88 | } else if (rdbuf[0] == 0x0f) { |
| 89 | ERROR("Out of media!\n"); |
| 90 | return 1; |
| 91 | } |
| 92 | |
| 93 | return CUPS_BACKEND_OK; |
| 94 | } |
| 95 | |
| 96 | static uint8_t es2_error_detect(const uint8_t *rdbuf) |
| 97 | { |
| 98 | if (rdbuf[0] == 0x16 && |
| 99 | rdbuf[1] == 0x01) { |
| 100 | ERROR("Printer cover open!\n"); |
| 101 | return 1; |
| 102 | } |
| 103 | |
| 104 | if (rdbuf[0] == 0x02 && |
| 105 | rdbuf[4] == 0x05 && |
| 106 | rdbuf[5] == 0x05 && |
| 107 | rdbuf[6] == 0x02) { |
| 108 | ERROR("No media loaded!\n"); |
| 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | if (rdbuf[0] == 0x14) { |
| 113 | ERROR("Out of media!\n"); |
| 114 | return 1; |
| 115 | } |
| 116 | |
| 117 | return CUPS_BACKEND_OK; |
| 118 | } |
| 119 | |
| 120 | static uint8_t es3_error_detect(const uint8_t *rdbuf) |
| 121 | { |
| 122 | if (rdbuf[8] == 0x01) { |
| 123 | if (rdbuf[10] == 0x0f) |
| 124 | ERROR("Communications Error\n"); |
| 125 | else if (rdbuf[10] == 0x01) |
| 126 | ERROR("No media loaded!\n"); |
| 127 | else |
| 128 | ERROR("Unknown error - %02x + %02x\n", |
| 129 | rdbuf[8], rdbuf[10]); |
| 130 | return 1; |
| 131 | } else if (rdbuf[8] == 0x03 && |
| 132 | rdbuf[10] == 0x02) { |
| 133 | ERROR("No media loaded!\n"); |
| 134 | return 1; |
| 135 | } else if (rdbuf[8] == 0x08 && |
| 136 | rdbuf[10] == 0x04) { |
| 137 | ERROR("Printer cover open!\n"); |
| 138 | return 1; |
| 139 | } else if (rdbuf[8] == 0x05 && |
| 140 | rdbuf[10] == 0x01) { |
| 141 | ERROR("Incorrect media loaded!\n"); |
| 142 | return 1; |
| 143 | } else if (rdbuf[8] == 0x03 && |
| 144 | rdbuf[10] == 0x04) { |
| 145 | ERROR("Paper jam!\n"); |
| 146 | return 1; |
| 147 | } |
| 148 | |
| 149 | if (rdbuf[8] || rdbuf[10]) { |
| 150 | ERROR("Unknown error - %02x + %02x\n", |
| 151 | rdbuf[8], rdbuf[10]); |
| 152 | return 1; |
| 153 | } |
| 154 | |
| 155 | return CUPS_BACKEND_OK; |
| 156 | } |
| 157 | |
| 158 | static uint8_t es40_error_detect(const uint8_t *rdbuf) |
| 159 | { |
| 160 | /* ES40 */ |
| 161 | if (!rdbuf[3]) |
| 162 | return CUPS_BACKEND_OK; |
| 163 | |
| 164 | if (rdbuf[3] == 0x01) |
| 165 | ERROR("Generic communication error\n"); |
| 166 | else if (rdbuf[3] == 0x32) |
| 167 | ERROR("Cover open or media empty!\n"); |
| 168 | else |
| 169 | ERROR("Unknown error - %02x\n", rdbuf[3]); |
| 170 | |
| 171 | return 1; |
| 172 | } |
| 173 | |
| 174 | static const char *cp790_pgcode_names(const uint8_t *rdbuf, const struct printer_data *printer, int *numtype) |
| 175 | { |
| 176 | UNUSED(printer); |
| 177 | UNUSED(numtype); |
| 178 | |
| 179 | switch(rdbuf[5]) { |
| 180 | case 0x00: return "P"; |
| 181 | case 0x01: return "L"; |
| 182 | case 0x02: return "C"; |
| 183 | case 0x03: return "W"; |
| 184 | case 0x0f: return "None"; |
| 185 | default: return "Unknown"; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | static uint8_t cp790_error_detect(const uint8_t *rdbuf) |
| 190 | { |
| 191 | /* CP790 */ |
| 192 | if (rdbuf[5] == 0xff) { |
| 193 | ERROR("No ribbon loaded!\n"); |
| 194 | return 1; |
| 195 | } else if (rdbuf[4] == 0xff) { |
| 196 | ERROR("No paper tray loaded!\n"); |
| 197 | return 1; |
| 198 | } else if (rdbuf[3]) { |
| 199 | if ((rdbuf[3] & 0xf) == 0x02) // 0x12 0x22 |
| 200 | ERROR("No paper tray loaded!\n"); |
| 201 | else if ((rdbuf[3] & 0xf) == 0x03) // 0x13 0x23 |
| 202 | ERROR("Empty paper tray or feed error!\n"); |
| 203 | else if (rdbuf[3] == 0x11) |
| 204 | ERROR("Paper feed error!\n"); |
| 205 | else if (rdbuf[3] == 0x21) |
| 206 | ERROR("Ribbon depleted!\n"); |
| 207 | else |
| 208 | ERROR("Unknown error - %02x\n", rdbuf[3]); |
| 209 | return 1; |
| 210 | } |
| 211 | |
| 212 | return CUPS_BACKEND_OK; |
| 213 | } |
| 214 | |
| 215 | static const char *cp10_pgcode_names(const uint8_t *rdbuf, const struct printer_data *printer, int *numtype) |
| 216 | { |
| 217 | UNUSED(rdbuf); |
| 218 | UNUSED(printer); |
| 219 | |
| 220 | *numtype = 3; |
| 221 | return "C"; /* Printer only supports one media type */ |
| 222 | } |
| 223 | |
| 224 | static uint8_t cp10_error_detect(const uint8_t *rdbuf) |
| 225 | { |
| 226 | if (!rdbuf[2]) |
| 227 | return CUPS_BACKEND_OK; |
| 228 | |
| 229 | if (rdbuf[2] == 0x80) |
| 230 | ERROR("No ribbon loaded\n"); |
| 231 | else if (rdbuf[2] == 0x08) |
| 232 | ERROR("Ribbon depleted!\n"); |
| 233 | else if (rdbuf[2] == 0x01) |
| 234 | ERROR("No paper loaded!\n"); |
| 235 | else |
| 236 | ERROR("Unknown error - %02x\n", rdbuf[2]); |
| 237 | return 1; |
| 238 | } |
| 239 | |
| 240 | static uint8_t cpxxx_error_detect(const uint8_t *rdbuf) |
| 241 | { |
| 242 | if (!rdbuf[2]) |
| 243 | return CUPS_BACKEND_OK; |
| 244 | |
| 245 | if (rdbuf[2] == 0x01) |
| 246 | ERROR("Paper feed problem!\n"); |
| 247 | else if (rdbuf[2] == 0x04) |
| 248 | ERROR("Ribbon problem!\n"); |
| 249 | else if (rdbuf[2] == 0x08) |
| 250 | ERROR("Ribbon depleted!\n"); |
| 251 | else |
| 252 | ERROR("Unknown error - %02x\n", rdbuf[2]); |
| 253 | return 1; |
| 254 | } |
| 255 | |
| 256 | static struct printer_data selphy_printers[] = { |
| 257 | { .type = P_ES1, |
| 258 | .model = "SELPHY ES1", |
| 259 | .init_length = 12, |
| 260 | .foot_length = 0, |
| 261 | .init_readback = { 0x02, 0x00, 0x00, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 }, |
| 262 | .ready_y_readback = { 0x04, 0x00, 0x01, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 }, |
| 263 | .ready_m_readback = { 0x04, 0x00, 0x03, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 }, |
| 264 | .ready_c_readback = { 0x04, 0x00, 0x07, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 }, |
| 265 | .done_c_readback = { 0x04, 0x00, 0x00, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 }, |
| 266 | .clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 267 | .clear_error_len = 12, |
| 268 | .pgcode_offset = 3, |
| 269 | .paper_code_offset = 6, |
| 270 | .paper_code_offset2 = -1, |
| 271 | .error_detect = es1_error_detect, |
| 272 | .pgcode_names = generic_pgcode_names, |
| 273 | }, |
| 274 | { .type = P_ES2_20, |
| 275 | .model = "SELPHY ES2/ES20", |
| 276 | .init_length = 16, |
| 277 | .foot_length = 0, |
| 278 | .init_readback = { 0x02, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 }, |
| 279 | .ready_y_readback = { 0x03, 0x00, 0x01, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 }, |
| 280 | .ready_m_readback = { 0x06, 0x00, 0x03, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 }, |
| 281 | .ready_c_readback = { 0x09, 0x00, 0x07, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 }, |
| 282 | .done_c_readback = { 0x09, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 }, |
| 283 | .clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 284 | .clear_error_len = 12, |
| 285 | .pgcode_offset = 2, |
| 286 | .paper_code_offset = 4, |
| 287 | .paper_code_offset2 = 6, |
| 288 | .error_detect = es2_error_detect, |
| 289 | .pgcode_names = generic_pgcode_names, |
| 290 | }, |
| 291 | { .type = P_ES3_30, |
| 292 | .model = "SELPHY ES3/ES30", |
| 293 | .init_length = 16, |
| 294 | .foot_length = 12, |
| 295 | .init_readback = { 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, |
| 296 | .ready_y_readback = { 0x01, 0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, |
| 297 | .ready_m_readback = { 0x03, 0xff, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, |
| 298 | .ready_c_readback = { 0x05, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, |
| 299 | .done_c_readback = { 0x00, 0xff, 0x10, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, |
| 300 | .clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 301 | .clear_error_len = 12, |
| 302 | .pgcode_offset = 2, |
| 303 | .paper_code_offset = -1, |
| 304 | .paper_code_offset2 = -1, |
| 305 | .error_detect = es3_error_detect, |
| 306 | .pgcode_names = NULL, |
| 307 | }, |
| 308 | { .type = P_ES40, |
| 309 | .model = "SELPHY ES40", |
| 310 | .init_length = 16, |
| 311 | .foot_length = 12, |
| 312 | .init_readback = { 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, |
| 313 | .ready_y_readback = { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, |
| 314 | .ready_m_readback = { 0x00, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, |
| 315 | .ready_c_readback = { 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, |
| 316 | .done_c_readback = { 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1 }, |
| 317 | .clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 318 | .clear_error_len = 12, |
| 319 | .pgcode_offset = 2, |
| 320 | .paper_code_offset = 11, |
| 321 | .paper_code_offset2 = -1, |
| 322 | .error_detect = es40_error_detect, |
| 323 | .pgcode_names = generic_pgcode_names, |
| 324 | }, |
| 325 | { .type = P_CP790, |
| 326 | .model = "SELPHY CP790", |
| 327 | .init_length = 16, |
| 328 | .foot_length = 12, |
| 329 | .init_readback = { 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, |
| 330 | .ready_y_readback = { 0x00, 0x01, 0x01, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, |
| 331 | .ready_m_readback = { 0x00, 0x03, 0x02, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, |
| 332 | .ready_c_readback = { 0x00, 0x05, 0x03, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, |
| 333 | .done_c_readback = { 0x00, 0x00, 0x10, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, |
| 334 | .clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 335 | .clear_error_len = 12, |
| 336 | .pgcode_offset = 2, |
| 337 | .paper_code_offset = -1, /* Uses a different technique */ |
| 338 | .paper_code_offset2 = -1, |
| 339 | .error_detect = cp790_error_detect, |
| 340 | .pgcode_names = cp790_pgcode_names, |
| 341 | }, |
| 342 | { .type = P_CPGENERIC, |
| 343 | .model = "SELPHY CP Series (!CP-10/CP790)", |
| 344 | .init_length = 12, |
| 345 | .foot_length = 0, /* CP900 has four-byte NULL footer that can be safely ignored */ |
| 346 | .init_readback = { 0x01, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 }, |
| 347 | .ready_y_readback = { 0x02, 0x00, 0x00, 0x00, 0x70, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 }, |
| 348 | .ready_m_readback = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 }, |
| 349 | .ready_c_readback = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 }, |
| 350 | .done_c_readback = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, -1, -1, 0x00, 0x00, 0x00, -1 }, |
| 351 | .clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 352 | .clear_error_len = 12, |
| 353 | .pgcode_offset = 3, |
| 354 | .paper_code_offset = 6, |
| 355 | .paper_code_offset2 = -1, |
| 356 | .error_detect = cpxxx_error_detect, |
| 357 | .pgcode_names = generic_pgcode_names, |
| 358 | }, |
| 359 | { .type = P_CP10, |
| 360 | .model = "SELPHY CP-10", |
| 361 | .init_length = 12, |
| 362 | .foot_length = 0, |
| 363 | .init_readback = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 364 | .ready_y_readback = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 365 | .ready_m_readback = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 366 | .ready_c_readback = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 367 | .done_c_readback = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 368 | .clear_error = { 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 369 | .clear_error_len = 12, |
| 370 | .pgcode_offset = 2, |
| 371 | .paper_code_offset = -1, |
| 372 | .paper_code_offset2 = -1, |
| 373 | .error_detect = cp10_error_detect, |
| 374 | .pgcode_names = cp10_pgcode_names, |
| 375 | }, |
| 376 | { .type = -1 }, |
| 377 | }; |
| 378 | |
| 379 | #define MAX_HEADER 28 |
| 380 | |
| 381 | static const uint32_t es40_cp790_plane_lengths[4] = { 2227456, 1601600, 698880, 2976512 }; |
| 382 | |
| 383 | static void setup_paper_codes(void) |
| 384 | { |
| 385 | int i, j; |
| 386 | for (i = 0 ; ; i++) { |
| 387 | if (selphy_printers[i].type == -1) |
| 388 | break; |
| 389 | /* Default all to IGNORE */ |
| 390 | for (j = 0 ; j < 256 ; j++) |
| 391 | selphy_printers[i].paper_codes[j] = -1; |
| 392 | |
| 393 | /* Set up specifics */ |
| 394 | switch (selphy_printers[i].type) { |
| 395 | case P_ES1: |
| 396 | selphy_printers[i].paper_codes[0x11] = 0x01; |
| 397 | selphy_printers[i].paper_codes[0x12] = 0x02; |
| 398 | selphy_printers[i].paper_codes[0x13] = 0x03; |
| 399 | break; |
| 400 | case P_ES2_20: |
| 401 | selphy_printers[i].paper_codes[0x01] = 0x01; |
| 402 | selphy_printers[i].paper_codes[0x02] = 0x02; |
| 403 | selphy_printers[i].paper_codes[0x03] = 0x03; |
| 404 | break; |
| 405 | case P_ES40: |
| 406 | selphy_printers[i].paper_codes[0x00] = 0x11; |
| 407 | selphy_printers[i].paper_codes[0x01] = 0x22; |
| 408 | selphy_printers[i].paper_codes[0x02] = 0x33; |
| 409 | break; |
| 410 | case P_CPGENERIC: |
| 411 | selphy_printers[i].paper_codes[0x01] = 0x11; |
| 412 | selphy_printers[i].paper_codes[0x02] = 0x22; |
| 413 | selphy_printers[i].paper_codes[0x03] = 0x33; |
| 414 | selphy_printers[i].paper_codes[0x04] = 0x44; |
| 415 | break; |
| 416 | case P_CP790: |
| 417 | selphy_printers[i].paper_codes[0x00] = 0x00; |
| 418 | selphy_printers[i].paper_codes[0x01] = 0x01; |
| 419 | selphy_printers[i].paper_codes[0x02] = 0x02; |
| 420 | selphy_printers[i].paper_codes[0x03] = 0x03; |
| 421 | break; |
| 422 | case P_ES3_30: |
| 423 | /* N/A, printer does not report types */ |
| 424 | case P_CP10: |
| 425 | /* N/A, printer supports one type only */ |
| 426 | break; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | #define INCORRECT_PAPER -999 |
| 432 | |
| 433 | /* Program states */ |
| 434 | enum { |
| 435 | S_IDLE = 0, |
| 436 | S_PRINTER_READY, |
| 437 | S_PRINTER_INIT_SENT, |
| 438 | S_PRINTER_READY_Y, |
| 439 | S_PRINTER_Y_SENT, |
| 440 | S_PRINTER_READY_M, |
| 441 | S_PRINTER_M_SENT, |
| 442 | S_PRINTER_READY_C, |
| 443 | S_PRINTER_C_SENT, |
| 444 | S_PRINTER_CP900_FOOTER, |
| 445 | S_PRINTER_DONE, |
| 446 | S_FINISHED, |
| 447 | }; |
| 448 | |
| 449 | static int fancy_memcmp(const uint8_t *buf_a, const int16_t *buf_b, uint16_t len) |
| 450 | { |
| 451 | uint16_t i; |
| 452 | |
| 453 | for (i = 0 ; i < len ; i++) { |
| 454 | if (buf_b[i] == -1) |
| 455 | continue; |
| 456 | else if (buf_a[i] > buf_b[i]) |
| 457 | return 1; |
| 458 | else if (buf_a[i] < buf_b[i]) |
| 459 | return -1; |
| 460 | } |
| 461 | return CUPS_BACKEND_OK; |
| 462 | } |
| 463 | |
| 464 | static int parse_printjob(uint8_t *buffer, uint8_t *bw_mode, uint32_t *plane_len) |
| 465 | { |
| 466 | int printer_type = -1; |
| 467 | |
| 468 | if (buffer[0] != 0x40 && |
| 469 | buffer[1] != 0x00) { |
| 470 | goto done; |
| 471 | } |
| 472 | |
| 473 | if (buffer[12] == 0x40 && |
| 474 | buffer[13] == 0x01) { |
| 475 | *plane_len = *(uint32_t*)(&buffer[16]); |
| 476 | *plane_len = le32_to_cpu(*plane_len); |
| 477 | |
| 478 | if (buffer[2] == 0x00) { |
| 479 | if (*plane_len == 688480) |
| 480 | printer_type = P_CP10; |
| 481 | else |
| 482 | printer_type = P_CPGENERIC; |
| 483 | } else { |
| 484 | printer_type = P_ES1; |
| 485 | *bw_mode = (buffer[2] == 0x20); |
| 486 | } |
| 487 | goto done; |
| 488 | } |
| 489 | |
| 490 | *plane_len = *(uint32_t*)(&buffer[12]); |
| 491 | *plane_len = le32_to_cpu(*plane_len); |
| 492 | |
| 493 | if (buffer[16] == 0x40 && |
| 494 | buffer[17] == 0x01) { |
| 495 | |
| 496 | if (buffer[4] == 0x02) { |
| 497 | printer_type = P_ES2_20; |
| 498 | *bw_mode = (buffer[7] == 0x01); |
| 499 | goto done; |
| 500 | } |
| 501 | |
| 502 | if (es40_cp790_plane_lengths[buffer[2]] == *plane_len) { |
| 503 | printer_type = P_ES40_CP790; |
| 504 | *bw_mode = (buffer[3] == 0x01); |
| 505 | goto done; |
| 506 | } else { |
| 507 | printer_type = P_ES3_30; |
| 508 | *bw_mode = (buffer[3] == 0x01); |
| 509 | goto done; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | done: |
| 514 | return printer_type; |
| 515 | } |
| 516 | |
| 517 | /* Private data structure */ |
| 518 | struct canonselphy_printjob { |
| 519 | struct dyesub_job_common common; |
| 520 | |
| 521 | int16_t paper_code; |
| 522 | uint8_t bw_mode; |
| 523 | |
| 524 | uint32_t plane_len; |
| 525 | |
| 526 | uint8_t *header; |
| 527 | uint8_t *plane_y; |
| 528 | uint8_t *plane_m; |
| 529 | uint8_t *plane_c; |
| 530 | uint8_t *footer; |
| 531 | }; |
| 532 | |
| 533 | struct canonselphy_ctx { |
| 534 | struct dyesub_connection *conn; |
| 535 | |
| 536 | struct printer_data *printer; |
| 537 | struct marker marker; |
| 538 | |
| 539 | uint8_t cp900; |
| 540 | }; |
| 541 | |
| 542 | static int canonselphy_get_status(struct canonselphy_ctx *ctx) |
| 543 | { |
| 544 | uint8_t rdbuf[READBACK_LEN]; |
| 545 | int ret, num; |
| 546 | |
| 547 | /* Read in the printer status, twice. */ |
| 548 | ret = read_data(ctx->conn, |
| 549 | (uint8_t*) rdbuf, READBACK_LEN, &num); |
| 550 | if (ret < 0) |
| 551 | return CUPS_BACKEND_FAILED; |
| 552 | |
| 553 | ret = read_data(ctx->conn, |
| 554 | (uint8_t*) rdbuf, READBACK_LEN, &num); |
| 555 | |
| 556 | if (ret < 0) |
| 557 | return CUPS_BACKEND_FAILED; |
| 558 | |
| 559 | INFO("Media type: %s\n", ctx->printer->pgcode_names? ctx->printer->pgcode_names(rdbuf, ctx->printer, &ret) : "Unknown"); |
| 560 | ctx->printer->error_detect(rdbuf); |
| 561 | |
| 562 | return CUPS_BACKEND_OK; |
| 563 | } |
| 564 | |
| 565 | static int canonselphy_send_reset(struct canonselphy_ctx *ctx) |
| 566 | { |
| 567 | uint8_t rstcmd[12] = { 0x40, 0x10, 0x00, 0x00, |
| 568 | 0x00, 0x00, 0x00, 0x00, |
| 569 | 0x00, 0x00, 0x00, 0x00 }; |
| 570 | int ret; |
| 571 | |
| 572 | if ((ret = send_data(ctx->conn, |
| 573 | rstcmd, sizeof(rstcmd)))) |
| 574 | return CUPS_BACKEND_FAILED; |
| 575 | |
| 576 | return CUPS_BACKEND_OK; |
| 577 | } |
| 578 | |
| 579 | static void *canonselphy_init(void) |
| 580 | { |
| 581 | struct canonselphy_ctx *ctx = malloc(sizeof(struct canonselphy_ctx)); |
| 582 | if (!ctx) { |
| 583 | ERROR("Memory Allocation Failure!\n"); |
| 584 | return NULL; |
| 585 | } |
| 586 | memset(ctx, 0, sizeof(struct canonselphy_ctx)); |
| 587 | |
| 588 | /* Static initialization */ |
| 589 | setup_paper_codes(); |
| 590 | |
| 591 | return ctx; |
| 592 | } |
| 593 | |
| 594 | static int canonselphy_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid) |
| 595 | { |
| 596 | struct canonselphy_ctx *ctx = vctx; |
| 597 | int i, num; |
| 598 | uint8_t rdbuf[READBACK_LEN]; |
| 599 | UNUSED(jobid); |
| 600 | |
| 601 | ctx->conn = conn; |
| 602 | |
| 603 | if (ctx->conn->type == P_CP900) { |
| 604 | ctx->conn->type = P_CPGENERIC; |
| 605 | ctx->cp900 = 1; |
| 606 | } |
| 607 | for (i = 0 ; selphy_printers[i].type != -1; i++) { |
| 608 | if (selphy_printers[i].type == ctx->conn->type) { |
| 609 | ctx->printer = &selphy_printers[i]; |
| 610 | } |
| 611 | } |
| 612 | if (!ctx->printer) { |
| 613 | ERROR("Error looking up printer type!\n"); |
| 614 | return CUPS_BACKEND_FAILED; |
| 615 | } |
| 616 | |
| 617 | /* Fill out marker structure */ |
| 618 | ctx->marker.color = "#00FFFF#FF00FF#FFFF00"; |
| 619 | ctx->marker.levelmax = CUPS_MARKER_UNAVAILABLE; |
| 620 | |
| 621 | if (test_mode < TEST_MODE_NOATTACH) { |
| 622 | /* Read printer status. Twice. */ |
| 623 | i = read_data(ctx->conn, |
| 624 | rdbuf, READBACK_LEN, &num); |
| 625 | if (i < 0) |
| 626 | return CUPS_BACKEND_FAILED; |
| 627 | |
| 628 | i = read_data(ctx->conn, |
| 629 | rdbuf, READBACK_LEN, &num); |
| 630 | if (i < 0) |
| 631 | return CUPS_BACKEND_FAILED; |
| 632 | |
| 633 | if (ctx->printer->error_detect(rdbuf)) |
| 634 | ctx->marker.levelnow = 0; |
| 635 | else |
| 636 | ctx->marker.levelnow = CUPS_MARKER_UNKNOWN_OK; |
| 637 | |
| 638 | ctx->marker.name = ctx->printer->pgcode_names? ctx->printer->pgcode_names(rdbuf, ctx->printer, &ctx->marker.numtype) : "Unknown"; |
| 639 | } else { |
| 640 | // XXX handle MEDIA_CODE at some point. |
| 641 | // we don't do any error checking here. |
| 642 | ctx->marker.name = "Unknown"; |
| 643 | ctx->marker.numtype = -1; |
| 644 | } |
| 645 | |
| 646 | return CUPS_BACKEND_OK; |
| 647 | } |
| 648 | |
| 649 | static void canonselphy_cleanup_job(const void *vjob) { |
| 650 | const struct canonselphy_printjob *job = vjob; |
| 651 | |
| 652 | if (job->header) |
| 653 | free(job->header); |
| 654 | if (job->plane_y) |
| 655 | free(job->plane_y); |
| 656 | if (job->plane_m) |
| 657 | free(job->plane_m); |
| 658 | if (job->plane_c) |
| 659 | free(job->plane_c); |
| 660 | if (job->footer) |
| 661 | free(job->footer); |
| 662 | |
| 663 | free((void*)vjob); |
| 664 | } |
| 665 | |
| 666 | static int canonselphy_read_parse(void *vctx, const void **vjob, int data_fd, int copies) |
| 667 | { |
| 668 | struct canonselphy_ctx *ctx = vctx; |
| 669 | int i, remain; |
| 670 | int printer_type; |
| 671 | int offset = 0; |
| 672 | uint8_t rdbuf[MAX_HEADER]; |
| 673 | |
| 674 | struct canonselphy_printjob *job = NULL; |
| 675 | |
| 676 | if (!ctx) |
| 677 | return CUPS_BACKEND_FAILED; |
| 678 | |
| 679 | job = malloc(sizeof(*job)); |
| 680 | if (!job) { |
| 681 | ERROR("Memory allocation failure!\n"); |
| 682 | return CUPS_BACKEND_RETRY_CURRENT; |
| 683 | } |
| 684 | memset(job, 0, sizeof(*job)); |
| 685 | job->common.jobsize = sizeof(*job); |
| 686 | job->common.copies = copies; |
| 687 | |
| 688 | /* The CP900 job *may* have a 4-byte null footer after the |
| 689 | job contents. Ignore it if it comes through here.. */ |
| 690 | i = read(data_fd, rdbuf, 4); |
| 691 | if (i != 4) { |
| 692 | if (i == 0) { |
| 693 | canonselphy_cleanup_job(job); |
| 694 | return CUPS_BACKEND_CANCEL; |
| 695 | } |
| 696 | ERROR("Read failed (%d/%d)\n", i, 4); |
| 697 | perror("ERROR: Read failed"); |
| 698 | canonselphy_cleanup_job(job); |
| 699 | return CUPS_BACKEND_FAILED; |
| 700 | } |
| 701 | /* if it's not the null header.. don't ignore! */ |
| 702 | if (rdbuf[0] != 0 || |
| 703 | rdbuf[1] != 0 || |
| 704 | rdbuf[2] != 0 || |
| 705 | rdbuf[3] != 0) { |
| 706 | offset = 4; |
| 707 | } |
| 708 | |
| 709 | /* Read the rest of the header.. */ |
| 710 | i = read(data_fd, rdbuf + offset, MAX_HEADER - offset); |
| 711 | if (i != MAX_HEADER - offset) { |
| 712 | if (i == 0) { |
| 713 | canonselphy_cleanup_job(job); |
| 714 | return CUPS_BACKEND_CANCEL; |
| 715 | } |
| 716 | ERROR("Read failed (%d/%d)\n", |
| 717 | i, MAX_HEADER - offset); |
| 718 | perror("ERROR: Read failed"); |
| 719 | canonselphy_cleanup_job(job); |
| 720 | return CUPS_BACKEND_FAILED; |
| 721 | } |
| 722 | |
| 723 | /* Figure out printer this file is intended for */ |
| 724 | printer_type = parse_printjob(rdbuf, &job->bw_mode, &job->plane_len); |
| 725 | /* Special cases for some models */ |
| 726 | if (printer_type == P_ES40_CP790) { |
| 727 | if (ctx->conn->type == P_CP790 || |
| 728 | ctx->conn->type == P_ES40) |
| 729 | printer_type = ctx->conn->type; |
| 730 | } |
| 731 | |
| 732 | if (printer_type != ctx->conn->type) { |
| 733 | ERROR("Printer/Job mismatch (%d/%d/%d)\n", ctx->conn->type, ctx->printer->type, printer_type); |
| 734 | canonselphy_cleanup_job(job); |
| 735 | return CUPS_BACKEND_CANCEL; |
| 736 | } |
| 737 | |
| 738 | INFO("%sFile intended for a '%s' printer\n", job->bw_mode? "B/W " : "", ctx->printer->model); |
| 739 | |
| 740 | /* Paper code setup */ |
| 741 | if (ctx->printer->pgcode_offset != -1) |
| 742 | job->paper_code = ctx->printer->paper_codes[rdbuf[ctx->printer->pgcode_offset]]; |
| 743 | else |
| 744 | job->paper_code = -1; |
| 745 | |
| 746 | /* Add in plane header length! */ |
| 747 | job->plane_len += 12; |
| 748 | |
| 749 | /* Set up buffers */ |
| 750 | job->plane_y = malloc(job->plane_len); |
| 751 | job->plane_m = malloc(job->plane_len); |
| 752 | job->plane_c = malloc(job->plane_len); |
| 753 | job->header = malloc(ctx->printer->init_length); |
| 754 | job->footer = malloc(ctx->printer->foot_length); |
| 755 | if (!job->plane_y || !job->plane_m || !job->plane_c || !job->header || |
| 756 | (ctx->printer->foot_length && !job->footer)) { |
| 757 | ERROR("Memory allocation failure!\n"); |
| 758 | canonselphy_cleanup_job(job); |
| 759 | return CUPS_BACKEND_RETRY_CURRENT; |
| 760 | } |
| 761 | |
| 762 | /* Move over chunks already read in */ |
| 763 | memcpy(job->header, rdbuf, ctx->printer->init_length); |
| 764 | memcpy(job->plane_y, rdbuf+ctx->printer->init_length, |
| 765 | MAX_HEADER-ctx->printer->init_length); |
| 766 | |
| 767 | /* Read in YELLOW plane */ |
| 768 | remain = job->plane_len - (MAX_HEADER-ctx->printer->init_length); |
| 769 | while (remain > 0) { |
| 770 | i = read(data_fd, job->plane_y + (job->plane_len - remain), remain); |
| 771 | if (i < 0) { |
| 772 | canonselphy_cleanup_job(job); |
| 773 | return CUPS_BACKEND_CANCEL; |
| 774 | } |
| 775 | remain -= i; |
| 776 | } |
| 777 | |
| 778 | /* Read in MAGENTA plane */ |
| 779 | remain = job->plane_len; |
| 780 | while (remain > 0) { |
| 781 | i = read(data_fd, job->plane_m + (job->plane_len - remain), remain); |
| 782 | if (i < 0) { |
| 783 | canonselphy_cleanup_job(job); |
| 784 | return CUPS_BACKEND_CANCEL; |
| 785 | } |
| 786 | remain -= i; |
| 787 | } |
| 788 | |
| 789 | /* Read in CYAN plane */ |
| 790 | remain = job->plane_len; |
| 791 | while (remain > 0) { |
| 792 | i = read(data_fd, job->plane_c + (job->plane_len - remain), remain); |
| 793 | if (i < 0) { |
| 794 | canonselphy_cleanup_job(job); |
| 795 | return CUPS_BACKEND_CANCEL; |
| 796 | } |
| 797 | remain -= i; |
| 798 | } |
| 799 | |
| 800 | /* Read in footer */ |
| 801 | if (ctx->printer->foot_length) { |
| 802 | remain = ctx->printer->foot_length; |
| 803 | while (remain > 0) { |
| 804 | i = read(data_fd, job->footer + (ctx->printer->foot_length - remain), remain); |
| 805 | if (i < 0) { |
| 806 | canonselphy_cleanup_job(job); |
| 807 | return CUPS_BACKEND_CANCEL; |
| 808 | } |
| 809 | remain -= i; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | *vjob = job; |
| 814 | |
| 815 | return CUPS_BACKEND_OK; |
| 816 | } |
| 817 | |
| 818 | static int canonselphy_main_loop(void *vctx, const void *vjob, int wait_for_return) { |
| 819 | struct canonselphy_ctx *ctx = vctx; |
| 820 | |
| 821 | uint8_t rdbuf[READBACK_LEN], rdbuf2[READBACK_LEN]; |
| 822 | int last_state = -1, state = S_IDLE; |
| 823 | int ret, num; |
| 824 | int copies; |
| 825 | (void)wait_for_return; |
| 826 | |
| 827 | const struct canonselphy_printjob *job = vjob; |
| 828 | |
| 829 | if (!ctx) |
| 830 | return CUPS_BACKEND_FAILED; |
| 831 | if (!job) |
| 832 | return CUPS_BACKEND_FAILED; |
| 833 | |
| 834 | copies = job->common.copies; |
| 835 | |
| 836 | /* Read in the printer status to clear last state */ |
| 837 | ret = read_data(ctx->conn, |
| 838 | rdbuf, READBACK_LEN, &num); |
| 839 | |
| 840 | if (ret < 0) |
| 841 | return CUPS_BACKEND_FAILED; |
| 842 | top: |
| 843 | |
| 844 | if (state != last_state) { |
| 845 | if (dyesub_debug) |
| 846 | DEBUG("last_state %d new %d\n", last_state, state); |
| 847 | } |
| 848 | |
| 849 | /* Read in the printer status */ |
| 850 | ret = read_data(ctx->conn, |
| 851 | rdbuf, READBACK_LEN, &num); |
| 852 | if (ret < 0) |
| 853 | return CUPS_BACKEND_FAILED; |
| 854 | |
| 855 | if (num != READBACK_LEN) { |
| 856 | ERROR("Short read! (%d/%d)\n", num, READBACK_LEN); |
| 857 | return CUPS_BACKEND_FAILED; |
| 858 | } |
| 859 | |
| 860 | /* Error detection */ |
| 861 | if (ctx->printer->error_detect(rdbuf)) { |
| 862 | dump_markers(&ctx->marker, 1, 0); |
| 863 | if (ctx->printer->clear_error_len) |
| 864 | /* Try to clear error state */ |
| 865 | if ((ret = send_data(ctx->conn, ctx->printer->clear_error, ctx->printer->clear_error_len))) |
| 866 | return CUPS_BACKEND_FAILED; |
| 867 | return CUPS_BACKEND_STOP; |
| 868 | } |
| 869 | |
| 870 | if (memcmp(rdbuf, rdbuf2, READBACK_LEN)) { |
| 871 | memcpy(rdbuf2, rdbuf, READBACK_LEN); |
| 872 | } else if (state == last_state) { |
| 873 | sleep(1); |
| 874 | } |
| 875 | last_state = state; |
| 876 | |
| 877 | fflush(logger); |
| 878 | |
| 879 | switch(state) { |
| 880 | case S_IDLE: |
| 881 | INFO("Waiting for printer idle\n"); |
| 882 | if (fancy_memcmp(rdbuf, ctx->printer->init_readback, READBACK_LEN)) |
| 883 | break; |
| 884 | |
| 885 | /* Make sure paper/ribbon is correct */ |
| 886 | if (job->paper_code != -1) { |
| 887 | uint8_t ribbon, paper; |
| 888 | uint8_t job_ribbon = job->paper_code & 0x0f; |
| 889 | uint8_t job_paper = (job->paper_code >> 4) & 0xf; |
| 890 | |
| 891 | switch(ctx->conn->type) { |
| 892 | case P_CPGENERIC: |
| 893 | ribbon = rdbuf[ctx->printer->paper_code_offset] & 0xf; |
| 894 | paper = rdbuf[ctx->printer->paper_code_offset] >> 4; |
| 895 | if (paper == 0x0) { |
| 896 | ERROR("No paper tray loaded, aborting!\n"); |
| 897 | return CUPS_BACKEND_STOP; |
| 898 | } |
| 899 | if (ribbon == 0x0) { |
| 900 | ERROR("No ribbon loaded, aborting!\n"); |
| 901 | return CUPS_BACKEND_STOP; |
| 902 | } |
| 903 | if (paper != job_paper) { |
| 904 | ERROR("Incorrect paper loaded (%02x vs %02x), aborting job!\n", paper, job_paper); |
| 905 | return CUPS_BACKEND_HOLD; |
| 906 | } |
| 907 | if (ribbon != job_ribbon) { |
| 908 | ERROR("Incorrect ribbon loaded (%02x vs %02x), aborting job!\n", ribbon, job_ribbon); |
| 909 | return CUPS_BACKEND_HOLD; |
| 910 | } |
| 911 | break; |
| 912 | case P_CP790: |
| 913 | ribbon = rdbuf[4] >> 4; |
| 914 | paper = rdbuf[5] & 0xf; |
| 915 | if (paper == 0xf) { |
| 916 | ERROR("No paper tray loaded, aborting!\n"); |
| 917 | return CUPS_BACKEND_STOP; |
| 918 | } |
| 919 | if (ribbon == 0xf) { |
| 920 | ERROR("No ribbon loaded, aborting!\n"); |
| 921 | return CUPS_BACKEND_STOP; |
| 922 | } |
| 923 | if (paper != job_paper) { |
| 924 | ERROR("Incorrect paper loaded (%02x vs %02x), aborting job!\n", paper, job_paper); |
| 925 | return CUPS_BACKEND_HOLD; |
| 926 | } |
| 927 | if (ribbon != job_ribbon) { |
| 928 | ERROR("Incorrect ribbon loaded (%02x vs %02x), aborting job!\n", ribbon, job_ribbon); |
| 929 | return CUPS_BACKEND_HOLD; |
| 930 | } |
| 931 | break; |
| 932 | default: |
| 933 | if (ctx->printer->paper_code_offset != -1 && |
| 934 | rdbuf[ctx->printer->paper_code_offset] != job->paper_code) { |
| 935 | ERROR("Incorrect media/ribbon loaded (%02x vs %02x), aborting job!\n", |
| 936 | job->paper_code, |
| 937 | rdbuf[ctx->printer->paper_code_offset]); |
| 938 | return CUPS_BACKEND_HOLD; /* Hold this job, don't stop queue */ |
| 939 | } |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | state = S_PRINTER_READY; |
| 945 | break; |
| 946 | case S_PRINTER_READY: |
| 947 | INFO("Printing started; Sending init sequence\n"); |
| 948 | /* Send printer init */ |
| 949 | if ((ret = send_data(ctx->conn, job->header, ctx->printer->init_length))) |
| 950 | return CUPS_BACKEND_FAILED; |
| 951 | |
| 952 | state = S_PRINTER_INIT_SENT; |
| 953 | break; |
| 954 | case S_PRINTER_INIT_SENT: |
| 955 | if (!fancy_memcmp(rdbuf, ctx->printer->ready_y_readback, READBACK_LEN)) { |
| 956 | state = S_PRINTER_READY_Y; |
| 957 | } |
| 958 | break; |
| 959 | case S_PRINTER_READY_Y: |
| 960 | if (job->bw_mode) |
| 961 | INFO("Sending BLACK plane\n"); |
| 962 | else |
| 963 | INFO("Sending YELLOW plane\n"); |
| 964 | |
| 965 | if ((ret = send_data(ctx->conn, job->plane_y, job->plane_len))) |
| 966 | return CUPS_BACKEND_FAILED; |
| 967 | |
| 968 | state = S_PRINTER_Y_SENT; |
| 969 | break; |
| 970 | case S_PRINTER_Y_SENT: |
| 971 | if (!fancy_memcmp(rdbuf, ctx->printer->ready_m_readback, READBACK_LEN)) { |
| 972 | if (job->bw_mode) |
| 973 | state = S_PRINTER_DONE; |
| 974 | else |
| 975 | state = S_PRINTER_READY_M; |
| 976 | } |
| 977 | break; |
| 978 | case S_PRINTER_READY_M: |
| 979 | INFO("Sending MAGENTA plane\n"); |
| 980 | |
| 981 | if ((ret = send_data(ctx->conn, job->plane_m, job->plane_len))) |
| 982 | return CUPS_BACKEND_FAILED; |
| 983 | |
| 984 | state = S_PRINTER_M_SENT; |
| 985 | break; |
| 986 | case S_PRINTER_M_SENT: |
| 987 | if (!fancy_memcmp(rdbuf, ctx->printer->ready_c_readback, READBACK_LEN)) { |
| 988 | state = S_PRINTER_READY_C; |
| 989 | } |
| 990 | break; |
| 991 | case S_PRINTER_READY_C: |
| 992 | INFO("Sending CYAN plane\n"); |
| 993 | |
| 994 | if ((ret = send_data(ctx->conn, job->plane_c, job->plane_len))) |
| 995 | return CUPS_BACKEND_FAILED; |
| 996 | |
| 997 | state = S_PRINTER_C_SENT; |
| 998 | break; |
| 999 | case S_PRINTER_C_SENT: |
| 1000 | if (!fancy_memcmp(rdbuf, ctx->printer->done_c_readback, READBACK_LEN)) { |
| 1001 | if (ctx->cp900) |
| 1002 | state = S_PRINTER_CP900_FOOTER; |
| 1003 | else |
| 1004 | state = S_PRINTER_DONE; |
| 1005 | } |
| 1006 | break; |
| 1007 | case S_PRINTER_CP900_FOOTER: { |
| 1008 | uint32_t empty = 0; |
| 1009 | |
| 1010 | INFO("Sending CP900 Footer\n"); |
| 1011 | if ((ret = send_data(ctx->conn, |
| 1012 | (uint8_t*)&empty, sizeof(empty)))) |
| 1013 | return CUPS_BACKEND_FAILED; |
| 1014 | |
| 1015 | state = S_PRINTER_DONE; |
| 1016 | break; |
| 1017 | } |
| 1018 | case S_PRINTER_DONE: |
| 1019 | if (ctx->printer->foot_length) { |
| 1020 | INFO("Cleaning up\n"); |
| 1021 | |
| 1022 | if ((ret = send_data(ctx->conn, job->footer, ctx->printer->foot_length))) |
| 1023 | return CUPS_BACKEND_FAILED; |
| 1024 | } |
| 1025 | state = S_FINISHED; |
| 1026 | /* Intentional Fallthrough */ |
| 1027 | case S_FINISHED: |
| 1028 | INFO("All data sent to printer!\n"); |
| 1029 | break; |
| 1030 | } |
| 1031 | if (state != S_FINISHED) |
| 1032 | goto top; |
| 1033 | |
| 1034 | /* Clean up */ |
| 1035 | if (terminate) |
| 1036 | copies = 1; |
| 1037 | |
| 1038 | INFO("Print complete (%d copies remaining)\n", copies - 1); |
| 1039 | |
| 1040 | if (copies && --copies) { |
| 1041 | state = S_IDLE; |
| 1042 | goto top; |
| 1043 | } |
| 1044 | |
| 1045 | return CUPS_BACKEND_OK; |
| 1046 | } |
| 1047 | |
| 1048 | static int canonselphy_cmdline_arg(void *vctx, int argc, char **argv) |
| 1049 | { |
| 1050 | struct canonselphy_ctx *ctx = vctx; |
| 1051 | int i, j = 0; |
| 1052 | |
| 1053 | if (!ctx) |
| 1054 | return -1; |
| 1055 | |
| 1056 | while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "Rs")) >= 0) { |
| 1057 | switch(i) { |
| 1058 | GETOPT_PROCESS_GLOBAL |
| 1059 | case 'R': |
| 1060 | canonselphy_send_reset(ctx); |
| 1061 | break; |
| 1062 | case 's': |
| 1063 | canonselphy_get_status(ctx); |
| 1064 | break; |
| 1065 | } |
| 1066 | |
| 1067 | if (j) return j; |
| 1068 | } |
| 1069 | |
| 1070 | return CUPS_BACKEND_OK; |
| 1071 | } |
| 1072 | |
| 1073 | static void canonselphy_cmdline(void) |
| 1074 | { |
| 1075 | DEBUG("\t\t[ -R ] # Reset printer\n"); |
| 1076 | DEBUG("\t\t[ -s ] # Query printer status\n"); |
| 1077 | } |
| 1078 | |
| 1079 | static int canonselphy_query_markers(void *vctx, struct marker **markers, int *count) |
| 1080 | { |
| 1081 | struct canonselphy_ctx *ctx = vctx; |
| 1082 | uint8_t rdbuf[READBACK_LEN]; |
| 1083 | int ret, num; |
| 1084 | |
| 1085 | /* Read in the printer status, twice. */ |
| 1086 | ret = read_data(ctx->conn, |
| 1087 | (uint8_t*) rdbuf, READBACK_LEN, &num); |
| 1088 | if (ret < 0) |
| 1089 | return CUPS_BACKEND_FAILED; |
| 1090 | |
| 1091 | ret = read_data(ctx->conn, |
| 1092 | (uint8_t*) rdbuf, READBACK_LEN, &num); |
| 1093 | |
| 1094 | if (ret < 0) |
| 1095 | return CUPS_BACKEND_FAILED; |
| 1096 | |
| 1097 | if (ctx->printer->error_detect(rdbuf)) |
| 1098 | ctx->marker.levelnow = 0; |
| 1099 | else |
| 1100 | ctx->marker.levelnow = CUPS_MARKER_UNKNOWN_OK; |
| 1101 | |
| 1102 | *markers = &ctx->marker; |
| 1103 | *count = 1; |
| 1104 | |
| 1105 | return CUPS_BACKEND_OK; |
| 1106 | } |
| 1107 | |
| 1108 | static const char *canonselphy_prefixes[] = { |
| 1109 | "canonselphy", // Family name |
| 1110 | // backwards compatibility |
| 1111 | "selphycp10", "selphycp100", "selphycp200", "selphycp220", |
| 1112 | "selphycp300", "selphycp330", "selphycp400", "selphycp500", |
| 1113 | "selphycp510", "selphycp520", "selphycp530", "selphycp600", |
| 1114 | "selphycp710", "selphycp720", "selphycp730", "selphycp740", |
| 1115 | "selphycp750", "selphycp760", "selphycp770", "selphycp780", |
| 1116 | "selphycp790", "selphycp800", "selphycp810", "selphycp900", |
| 1117 | "selphyes1", "selphyes2", "selphyes20", "selphyes3", |
| 1118 | "selphyes30", "selphyes40", |
| 1119 | NULL |
| 1120 | }; |
| 1121 | static const struct device_id canonselphy_devices[] = { |
| 1122 | { 0x04a9, 0x304a, P_CP10, NULL, "canon-cp10"}, |
| 1123 | { 0x04a9, 0x3063, P_CPGENERIC, NULL, "canon-cp100"}, |
| 1124 | { 0x04a9, 0x307c, P_CPGENERIC, NULL, "canon-cp200"}, |
| 1125 | { 0x04a9, 0x30bd, P_CPGENERIC, NULL, "canon-cp220"}, |
| 1126 | { 0x04a9, 0x307d, P_CPGENERIC, NULL, "canon-cp300"}, |
| 1127 | { 0x04a9, 0x30be, P_CPGENERIC, NULL, "canon-cp330"}, |
| 1128 | { 0x04a9, 0x30f6, P_CPGENERIC, NULL, "canon-cp400"}, |
| 1129 | { 0x04a9, 0x30f5, P_CPGENERIC, NULL, "canon-cp500"}, |
| 1130 | { 0x04a9, 0x3128, P_CPGENERIC, NULL, "canon-cp510"}, |
| 1131 | { 0x04a9, 0x3172, P_CPGENERIC, NULL, "canon-cp520"}, |
| 1132 | { 0x04a9, 0x31b1, P_CPGENERIC, NULL, "canon-cp530"}, |
| 1133 | { 0x04a9, 0x310b, P_CPGENERIC, NULL, "canon-cp600"}, |
| 1134 | { 0x04a9, 0x3127, P_CPGENERIC, NULL, "canon-cp710"}, |
| 1135 | { 0x04a9, 0x3143, P_CPGENERIC, NULL, "canon-cp720"}, |
| 1136 | { 0x04a9, 0x3142, P_CPGENERIC, NULL, "canon-cp730"}, |
| 1137 | { 0x04a9, 0x3171, P_CPGENERIC, NULL, "canon-cp740"}, |
| 1138 | { 0x04a9, 0x3170, P_CPGENERIC, NULL, "canon-cp750"}, |
| 1139 | { 0x04a9, 0x31ab, P_CPGENERIC, NULL, "canon-cp760"}, |
| 1140 | { 0x04a9, 0x31aa, P_CPGENERIC, NULL, "canon-cp770"}, |
| 1141 | { 0x04a9, 0x31dd, P_CPGENERIC, NULL, "canon-cp780"}, |
| 1142 | { 0x04a9, 0x31e7, P_CP790, NULL, "canon-cp790"}, |
| 1143 | { 0x04a9, 0x3214, P_CPGENERIC, NULL, "canon-cp800"}, |
| 1144 | { 0x04a9, 0x3256, P_CPGENERIC, NULL, "canon-cp810"}, |
| 1145 | { 0x04a9, 0x3255, P_CPGENERIC, NULL, "canon-cp900"}, |
| 1146 | { 0x04a9, 0x3141, P_ES1, NULL, "canon-es1"}, |
| 1147 | { 0x04a9, 0x3185, P_ES2_20, NULL, "canon-es2"}, |
| 1148 | { 0x04a9, 0x3186, P_ES2_20, NULL, "canon-es20"}, |
| 1149 | { 0x04a9, 0x31af, P_ES3_30, NULL, "canon-es3"}, |
| 1150 | { 0x04a9, 0x31b0, P_ES3_30, NULL, "canon-es30"}, |
| 1151 | { 0x04a9, 0x31ee, P_ES40, NULL, "canon-es40"}, |
| 1152 | { 0, 0, 0, NULL, NULL} |
| 1153 | }; |
| 1154 | |
| 1155 | const struct dyesub_backend canonselphy_backend = { |
| 1156 | .name = "Canon SELPHY CP/ES (legacy)", |
| 1157 | .version = "0.114", |
| 1158 | .uri_prefixes = canonselphy_prefixes, |
| 1159 | .devices = canonselphy_devices, |
| 1160 | .cmdline_usage = canonselphy_cmdline, |
| 1161 | .cmdline_arg = canonselphy_cmdline_arg, |
| 1162 | .init = canonselphy_init, |
| 1163 | .attach = canonselphy_attach, |
| 1164 | .read_parse = canonselphy_read_parse, |
| 1165 | .cleanup_job = canonselphy_cleanup_job, |
| 1166 | .main_loop = canonselphy_main_loop, |
| 1167 | .query_markers = canonselphy_query_markers, |
| 1168 | }; |
| 1169 | /* |
| 1170 | |
| 1171 | *************************************************************************** |
| 1172 | |
| 1173 | Stream formats and readback codes for supported printers |
| 1174 | |
| 1175 | *************************************************************************** |
| 1176 | Selphy ES1: |
| 1177 | |
| 1178 | Init func: 40 00 [typeA] [pgcode] 00 00 00 00 00 00 00 00 |
| 1179 | Plane func: 40 01 [typeB] [plane] [length, 32-bit LE] 00 00 00 00 |
| 1180 | |
| 1181 | TypeA codes are 0x10 for Color papers, 0x20 for B&W papers. |
| 1182 | TypeB codes are 0x01 for Color papers, 0x02 for B&W papers. |
| 1183 | |
| 1184 | Plane codes are 0x01, 0x03, 0x07 for Y, M, and C, respectively. |
| 1185 | B&W Jobs have a single plane code of 0x01. |
| 1186 | |
| 1187 | 'P' papers pgcode of 0x11 and a plane length of 2227456 bytes |
| 1188 | 'L' pgcode of 0x12 and a plane length of 1601600 bytes. |
| 1189 | 'C' pgcode of 0x13 and a plane length of 698880 bytes. |
| 1190 | |
| 1191 | Readback values seen: |
| 1192 | |
| 1193 | 02 00 00 00 02 01 [pg] 01 00 00 00 00 [idle, waiting for init seq] |
| 1194 | 04 00 00 00 02 01 [pg] 01 00 00 00 00 [init received, not ready..] |
| 1195 | 04 00 01 00 02 01 [pg] 01 00 00 00 00 [waiting for Y data] |
| 1196 | 04 00 03 00 02 01 [pg] 01 00 00 00 00 [waiting for M data] |
| 1197 | 04 00 07 00 02 01 [pg] 01 00 00 00 00 [waiting for C data] |
| 1198 | 04 00 00 00 02 01 [pg] 01 00 00 00 00 [all data sent; not ready..] |
| 1199 | 05 00 00 00 02 01 [pg] 01 00 00 00 00 [?? transitions to this] |
| 1200 | 06 00 00 00 02 01 [pg] 01 00 00 00 00 [?? transitions to this] |
| 1201 | 02 00 00 00 02 01 [pg] 01 00 00 00 00 [..transitions back to idle] |
| 1202 | |
| 1203 | 02 01 00 00 01 ff ff ff 00 80 00 00 [error, no media] |
| 1204 | 02 00 00 00 01 ff ff ff 00 00 00 00 [error, cover open] |
| 1205 | 0f 00 00 00 02 01 01 01 00 00 00 00 [error, out of media] |
| 1206 | |
| 1207 | Known paper types for all ES printers: P, Pbw, L, C, Cl |
| 1208 | Additional types for ES3/30/40: Pg, Ps |
| 1209 | |
| 1210 | [pg] is: 0x01 for P-papers |
| 1211 | 0x02 for L-papers |
| 1212 | 0x03 for C-papers |
| 1213 | |
| 1214 | *************************************************************************** |
| 1215 | Selphy ES2/20: |
| 1216 | |
| 1217 | Init func: 40 00 [pgcode] 00 02 00 00 [type] 00 00 00 [pg2] [length, 32-bit LE] |
| 1218 | Plane func: 40 01 [plane] 00 00 00 00 00 00 00 00 00 |
| 1219 | |
| 1220 | Type codes are 0x00 for Color papers, 0x01 for B&W papers. |
| 1221 | |
| 1222 | Plane codes are 0x01, 0x02, 0x03 for Y, M, and C, respectively. |
| 1223 | B&W Jobs have a single plane code of 0x01. |
| 1224 | |
| 1225 | 'P' papers pgcode of 0x01 and a plane length of 2227456 bytes |
| 1226 | 'L' pgcode of 0x02 and a plane length of 1601600 bytes. |
| 1227 | 'C' pgcode of 0x03 and a plane length of 698880 bytes. |
| 1228 | |
| 1229 | pg2 is 0x00 for all media types except for 'C', which is 0x01. |
| 1230 | |
| 1231 | Readback values seen on an ES2: |
| 1232 | |
| 1233 | 02 00 00 00 [pg] 00 [pg2] [xx] 00 00 00 00 [idle, waiting for init seq] |
| 1234 | 03 00 01 00 [pg] 00 [pg2] [xx] 00 00 00 00 [init complete, ready for Y] |
| 1235 | 04 00 01 00 [pg] 00 [pg2] [xx] 00 00 00 00 [? paper loaded] |
| 1236 | 05 00 01 00 [pg] 00 [pg2] [xx] 00 00 00 00 [? transitions to this] |
| 1237 | 06 00 03 00 [pg] 00 [pg2] [xx] 00 00 00 00 [ready for M] |
| 1238 | 08 00 03 00 [pg] 00 [pg2] [xx] 00 00 00 00 [? transitions to this] |
| 1239 | 09 00 07 00 [pg] 00 [pg2] [xx] 00 00 00 00 [ready for C] |
| 1240 | 09 00 00 00 [pg] 00 [pg2] 00 00 00 00 00 [? transitions to this] |
| 1241 | 0b 00 00 00 [pg] 00 [pg2] 00 00 00 00 00 [? transitions to this] |
| 1242 | 0c 00 00 00 [pg] 00 [pg2] 00 00 00 00 00 [? transitions to this] |
| 1243 | 0f 00 00 00 [pg] 00 [pg2] 00 00 00 00 00 [? transitions to this] |
| 1244 | 13 00 00 00 [pg] 00 [pg2] 00 00 00 00 00 [? transitions to this] |
| 1245 | |
| 1246 | 14 00 00 00 [pg] 00 [pg2] 00 00 00 00 00 [out of paper/ink] |
| 1247 | 14 00 01 00 [pg] 00 [pg2] 00 01 00 00 00 [out of paper/ink] |
| 1248 | |
| 1249 | 16 01 00 00 [pg] 00 [pg2] 00 00 00 00 00 [error, cover open] |
| 1250 | 02 00 00 00 05 05 02 00 00 00 00 00 [error, no media] |
| 1251 | |
| 1252 | [xx] can be 0x00 or 0xff, depending on if a previous print job has |
| 1253 | completed or not. |
| 1254 | |
| 1255 | [pg] is: 0x01 for P-papers |
| 1256 | 0x02 for L-papers |
| 1257 | 0x03 for C-papers |
| 1258 | |
| 1259 | [pg2] is: 0x00 for Normal papers |
| 1260 | 0x01 for Label papers |
| 1261 | |
| 1262 | *************************************************************************** |
| 1263 | Selphy ES3/30: |
| 1264 | |
| 1265 | Init func: 40 00 [pgcode] [type] 00 00 00 00 00 00 00 00 [length, 32-bit LE] |
| 1266 | Plane func: 40 01 [plane] 00 00 00 00 00 00 00 00 00 |
| 1267 | |
| 1268 | End func: 40 20 00 00 00 00 00 00 00 00 00 00 |
| 1269 | |
| 1270 | Type codes are 0x00 for Color papers, 0x01 for B&W papers. |
| 1271 | |
| 1272 | Plane codes are 0x01, 0x02, 0x03 for Y, M, and C, respectively. |
| 1273 | B&W Jobs have a single plane code of 0x01. |
| 1274 | |
| 1275 | 'P' papers pgcode of 0x01 and a plane length of 2227456 bytes. |
| 1276 | 'L' pgcode of 0x02 and a plane length of 1601600 bytes. |
| 1277 | 'C' pgcode of 0x03 and a plane length of 698880 bytes. |
| 1278 | |
| 1279 | Readback values seen on an ES3 & ES30: |
| 1280 | |
| 1281 | 00 ff 00 00 ff ff ff ff 00 00 00 00 [idle, waiting for init seq] |
| 1282 | 01 ff 01 00 ff ff ff ff 00 00 00 00 [init complete, ready for Y] |
| 1283 | 03 ff 01 00 ff ff ff ff 00 00 00 00 [?] |
| 1284 | 03 ff 02 00 ff ff ff ff 00 00 00 00 [ready for M] |
| 1285 | 05 ff 02 00 ff ff ff ff 00 00 00 00 [?] |
| 1286 | 05 ff 03 00 ff ff ff ff 00 00 00 00 [ready for C] |
| 1287 | 07 ff 03 00 ff ff ff ff 00 00 00 00 [?] |
| 1288 | 0b ff 03 00 ff ff ff ff 00 00 00 00 [?] |
| 1289 | 13 ff 03 00 ff ff ff ff 00 00 00 00 [?] |
| 1290 | 00 ff 10 00 ff ff ff ff 00 00 00 00 [ready for footer] |
| 1291 | |
| 1292 | 01 ff 10 00 ff ff ff ff 01 00 0f 00 [communication error] |
| 1293 | 00 ff 01 00 ff ff ff ff 01 00 01 00 [error, no media/ink] |
| 1294 | 00 ff 01 00 ff ff ff ff 05 00 01 00 [error, incorrect media] |
| 1295 | 00 ff 01 00 ff ff ff ff 03 00 02 00 [attempt to print with no media] |
| 1296 | 00 ff 01 00 ff ff ff ff 08 00 04 00 [attempt to print with cover open] |
| 1297 | |
| 1298 | There appears to be no paper code in the readback; codes were identical for |
| 1299 | the standard 'P-Color' and 'Cl' cartridges: |
| 1300 | |
| 1301 | *************************************************************************** |
| 1302 | Selphy ES40: |
| 1303 | |
| 1304 | Init func: 40 00 [pgcode] [type] 00 00 00 00 00 00 00 00 [length, 32-bit LE] |
| 1305 | Plane func: 40 01 [plane] 00 00 00 00 00 00 00 00 00 |
| 1306 | |
| 1307 | End func: 40 20 00 00 00 00 00 00 00 00 00 00 |
| 1308 | |
| 1309 | Type codes are 0x00 for Color papers, 0x01 for B&W papers. |
| 1310 | |
| 1311 | Plane codes are 0x01, 0x02, 0x03 for Y, M, and C, respectively. |
| 1312 | B&W Jobs have a single plane code of 0x01. |
| 1313 | |
| 1314 | 'P' papers pgcode of 0x00 and a plane length of 2227456 bytes. |
| 1315 | 'L' pgcode of 0x01 and a plane length of 1601600 bytes. |
| 1316 | 'C' pgcode of 0x02 and a plane length of 698880 bytes. |
| 1317 | |
| 1318 | Readback values seen on an ES40: |
| 1319 | |
| 1320 | 00 00 ff 00 00 00 00 00 00 00 00 [pg] |
| 1321 | 00 00 00 00 00 00 00 00 00 00 00 [pg] [idle, ready for header] |
| 1322 | 00 01 01 00 00 00 00 00 00 00 00 [pg] [ready for Y data] |
| 1323 | 00 03 01 00 00 00 00 00 00 00 00 [pg] [transitions to this] |
| 1324 | 00 03 02 00 00 00 00 00 00 00 00 [pg] [ready for M data] |
| 1325 | 00 05 02 00 00 00 00 00 00 00 00 [pg] [transitions to this] |
| 1326 | 00 05 03 00 00 00 00 00 00 00 00 [pg] [ready for C data] |
| 1327 | 00 07 03 00 00 00 00 00 00 00 00 [pg] [transitions to this] |
| 1328 | 00 0b ff 00 00 00 00 00 00 00 00 [pg] [transitions to this] |
| 1329 | 00 0e ff 00 00 00 00 00 00 00 00 [pg] [transitions to this] |
| 1330 | 00 00 10 00 00 00 00 00 00 00 00 [pg] [ready for footer] |
| 1331 | |
| 1332 | 00 ** ** [xx] 00 00 00 00 00 00 00 [pg] [error] |
| 1333 | |
| 1334 | [xx]: |
| 1335 | 01: Generic communication error |
| 1336 | 32: Cover open / media empty |
| 1337 | |
| 1338 | [pg] is as follows: |
| 1339 | |
| 1340 | 'P' paper 0x11 |
| 1341 | 'L' paper 0x22 |
| 1342 | 'C' paper 0x33 |
| 1343 | |
| 1344 | *************************************************************************** |
| 1345 | Selphy CP790: |
| 1346 | |
| 1347 | Init func: 40 00 [pgcode] 00 00 00 00 00 00 00 00 00 [length, 32-bit LE] |
| 1348 | Plane func: 40 01 [plane] 00 00 00 00 00 00 00 00 00 |
| 1349 | |
| 1350 | End func: 40 20 00 00 00 00 00 00 00 00 00 00 |
| 1351 | |
| 1352 | Reset func: 40 10 00 00 00 00 00 00 00 00 00 00 |
| 1353 | |
| 1354 | Plane codes are 0x01, 0x02, 0x03 for Y, M, and C, respectively. |
| 1355 | |
| 1356 | 'P' papers pgcode of 0x00 and a plane length of 2227456 bytes. |
| 1357 | 'L' pgcode of 0x01 and a plane length of 1601600 bytes. |
| 1358 | 'C' pgcode of 0x02 and a plane length of 698880 bytes. |
| 1359 | 'W' pgcode of 0x03 and a plane length of 2976512 bytes. |
| 1360 | |
| 1361 | Readback values seen on an CP790: |
| 1362 | |
| 1363 | 00 00 ff 00 [pg1] [pg2] 00 00 00 00 00 02 |
| 1364 | 00 00 00 00 [pg1] [pg2] 00 00 00 00 00 02 [idle, ready for header] |
| 1365 | 00 00 01 00 [pg1] [pg2] 00 00 00 00 00 02 |
| 1366 | 00 01 01 00 [pg1] [pg2] 00 00 00 00 00 02 [ready for Y data] |
| 1367 | 00 03 01 00 [pg1] [pg2] 00 00 00 00 00 02 [transitions to this] |
| 1368 | 00 03 02 00 [pg1] [pg2] 00 00 00 00 00 02 [ready for M data] |
| 1369 | 00 05 02 00 [pg1] [pg2] 00 00 00 00 00 02 [transitions to this] |
| 1370 | 00 05 03 00 [pg1] [pg2] 00 00 00 00 00 02 [ready for C data] |
| 1371 | 00 0b ff 00 [pg1] [pg2] 00 00 00 00 00 02 [transitions to this] |
| 1372 | 00 0e ff 00 [pg1] [pg2] 00 00 00 00 00 02 [transitions to this] |
| 1373 | 00 00 10 00 [pg1] [pg2] 00 00 00 00 00 02 [ready for footer] |
| 1374 | |
| 1375 | [pg1] is: [pg2] is: |
| 1376 | |
| 1377 | 0x00 'P' ribbon 0x00 'P' paper |
| 1378 | 0x10 'L' ribbon 0x01 'L' paper |
| 1379 | 0x20 'C' ribbon 0x02 'C' paper |
| 1380 | 0x30 'W' ribbon 0x03 'W' paper |
| 1381 | 0xff NO RIBBON 0xff NO PAPER TRAY |
| 1382 | |
| 1383 | Other readbacks seen: |
| 1384 | |
| 1385 | 00 00 01 11 [pg1] [pg2] 00 00 00 00 00 02 [emptytray, ink match job ] |
| 1386 | 00 00 01 12 [pg1] [pg2] 00 00 00 00 00 02 [ notray, ink match job ] |
| 1387 | 00 00 01 13 [pg1] [pg2] 00 00 00 00 00 02 [ empty tray + mismatch ink ] |
| 1388 | 00 00 01 21 [pg1] [pg2] 00 00 00 00 00 02 [ depleted ribbon, match ink ] |
| 1389 | 00 00 01 22 [pg1] [pg2] 00 00 00 00 00 02 [ no paper tray ] |
| 1390 | 00 00 01 23 [pg1] [pg2] 00 00 00 00 00 02 [ empty tray, ink mismatch ] |
| 1391 | |
| 1392 | Note : These error conditions are confusing. |
| 1393 | |
| 1394 | *************************************************************************** |
| 1395 | Selphy CP-10: |
| 1396 | |
| 1397 | Init func: 40 00 00 00 00 00 00 00 00 00 00 00 |
| 1398 | Plane func: 40 01 00 [plane] [length, 32-bit LE] 00 00 00 00 |
| 1399 | |
| 1400 | plane codes are 0x00, 0x01, 0x02 for Y, M, and C, respectively. |
| 1401 | |
| 1402 | length is always '00 60 81 0a' which is 688480 bytes. |
| 1403 | |
| 1404 | Error clear: 40 10 00 00 00 00 00 00 00 00 00 00 |
| 1405 | |
| 1406 | Known readback values: |
| 1407 | |
| 1408 | 01 00 00 00 00 00 00 00 00 00 00 00 [idle, waiting for init] |
| 1409 | 02 00 00 00 00 00 00 00 00 00 00 00 [init sent, paper feeding] |
| 1410 | 02 00 00 00 00 00 00 00 00 00 00 00 [init sent, paper feeding] |
| 1411 | 02 00 00 00 00 00 00 00 00 00 00 00 [waiting for Y data] |
| 1412 | 04 00 00 00 00 00 00 00 00 00 00 00 [waiting for M data] |
| 1413 | 08 00 00 00 00 00 00 00 00 00 00 00 [waiting for C data] |
| 1414 | 10 00 00 00 00 00 00 00 00 00 00 00 [C done, waiting] |
| 1415 | 20 00 00 00 00 00 00 00 00 00 00 00 [All done] |
| 1416 | |
| 1417 | 02 00 80 00 00 00 00 00 00 00 00 00 [No ribbon] |
| 1418 | 02 00 80 00 00 00 00 00 00 00 00 00 [Ribbon depleted] |
| 1419 | 02 00 01 00 00 00 00 00 00 00 00 00 [No paper] |
| 1420 | |
| 1421 | There are no media type codes; the printer only supports one type. |
| 1422 | |
| 1423 | *************************************************************************** |
| 1424 | Selphy CP-series (except for CP790 & CP-10): |
| 1425 | |
| 1426 | This is known to apply to: |
| 1427 | CP-100, CP-200, CP-300, CP-330, CP400, CP500, CP510, CP710, |
| 1428 | CP720, CP730, CP740, CP750, CP760, CP770, CP780, CP800, CP900 |
| 1429 | |
| 1430 | Init func: 40 00 00 [pgcode] 00 00 00 00 00 00 00 00 |
| 1431 | Plane func: 40 01 00 [plane] [length, 32-bit LE] 00 00 00 00 |
| 1432 | End func: 00 00 00 00 # NOTE: Present (and necessary) on CP900 only. |
| 1433 | |
| 1434 | Error clear: 40 10 00 00 00 00 00 00 00 00 00 00 |
| 1435 | |
| 1436 | plane codes are 0x00, 0x01, 0x02 for Y, M, and C, respectively. |
| 1437 | |
| 1438 | 'P' papers pgcode 0x01 plane length 2227456 bytes. |
| 1439 | 'L' pgcode 0x02 plane length 1601600 bytes. |
| 1440 | 'C' pgcode 0x03 plane length 698880 bytes. |
| 1441 | 'W' pgcode 0x04 plane length 2976512 bytes. |
| 1442 | |
| 1443 | Known readback values: |
| 1444 | |
| 1445 | 01 00 00 00 [ss] 00 [pg] [zz] 00 00 00 [xx] [idle, waiting for init] |
| 1446 | 02 00 [rr] 00 00 00 [pg] [zz] 00 00 00 [xx] [init sent, paper feeding] |
| 1447 | 02 00 [rr] 00 10 00 [pg] [zz] 00 00 00 [xx] [init sent, paper feeding] |
| 1448 | 02 00 [rr] 00 70 00 [pg] [zz] 00 00 00 [xx] [waiting for Y data] |
| 1449 | 04 00 00 00 00 00 [pg] [zz] 00 00 00 [xx] [waiting for M data] |
| 1450 | 08 00 00 00 00 00 [pg] [zz] 00 00 00 [xx] [waiting for C data] |
| 1451 | 10 00 00 00 00 00 [pg] [zz] 00 00 00 [xx] [C done, waiting] |
| 1452 | 20 00 00 00 00 00 [pg] [zz] 00 00 00 [xx] [All done] |
| 1453 | |
| 1454 | [xx] is 0x01 on the CP780/CP800/CP900, 0x00 on all others. |
| 1455 | |
| 1456 | [rr] is error code: |
| 1457 | 0x00 no error |
| 1458 | 0x01 paper out |
| 1459 | 0x04 ribbon problem |
| 1460 | 0x08 ribbon depleted |
| 1461 | |
| 1462 | [ss] is either 0x00 or 0x70. Unsure as to its significance; perhaps it |
| 1463 | means paper or ribbon is already set to go? |
| 1464 | |
| 1465 | [pg] is as follows: |
| 1466 | |
| 1467 | 'P' paper 0x11 |
| 1468 | 'L' paper 0x22 |
| 1469 | 'C' paper 0x33 |
| 1470 | 'W' paper 0x44 |
| 1471 | |
| 1472 | First four bits are paper, second four bits are the ribbon. They aren't |
| 1473 | necessarily identical. So it's possible to have a code of, say, |
| 1474 | 0x41 if the 'Wide' paper tray is loaded with a 'P' ribbon. A '0' is used |
| 1475 | to signify nothing being loaded. |
| 1476 | |
| 1477 | [zz] is 0x01 when on battery power, 0x00 otherwise. |
| 1478 | |
| 1479 | */ |