[misc] Rework data structures.

This commit is contained in:
Solomon Peachy 2012-10-28 12:19:17 -04:00
parent d5d84d48fb
commit 793354f3df
3 changed files with 142 additions and 114 deletions

View file

@ -25,7 +25,7 @@
*
*/
#define VERSION "0.20"
#define VERSION "0.21"
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
#define cpu_to_le32(__x) __x
@ -41,7 +41,23 @@
})
#endif
/* Printer types */
#define READBACK_LEN 12
struct printer_data {
int type; /* P_??? */
char *model; /* "SELPHY ES1" */
int init_length;
int foot_length;
int16_t init_readback[READBACK_LEN];
int16_t ready_y_readback[READBACK_LEN];
int16_t ready_m_readback[READBACK_LEN];
int16_t ready_c_readback[READBACK_LEN];
int16_t done_c_readback[READBACK_LEN];
int16_t paper_codes[256];
int16_t paper_code_offset;
};
/* printer types */
enum {
P_ES1 = 0,
P_ES2_20,
@ -51,96 +67,108 @@ enum {
P_END
};
static char *models[P_END] = { "SELPHY ES1",
"SELPHY ES2/ES20",
"SELPHY ES3/ES30",
"SELPHY ES40/CP790",
"SELPHY CP Series (Except CP790)",
struct printer_data printers[P_END] = {
{ .type = P_ES1,
.model = "SELPHY ES1",
.init_length = 12,
.foot_length = 0,
.init_readback = { 0x02, 0x00, 0x00, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
.ready_y_readback = { 0x04, 0x00, 0x01, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
.ready_m_readback = { 0x04, 0x00, 0x03, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
.ready_c_readback = { 0x04, 0x00, 0x07, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
.done_c_readback = { 0x04, 0x00, 0x00, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
// .paper_codes
.paper_code_offset = 6,
},
{ .type = P_ES2_20,
.model = "SELPHY ES2/ES20",
.init_length = 16,
.foot_length = 0,
.init_readback = { 0x02, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
.ready_y_readback = { 0x03, 0x00, 0x01, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
.ready_m_readback = { 0x06, 0x00, 0x03, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
.ready_c_readback = { 0x09, 0x00, 0x07, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
.done_c_readback = { 0x09, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
// .paper_codes
.paper_code_offset = 4,
},
{ .type = P_ES3_30,
.model = "SELPHY ES3/ES30",
.init_length = 16,
.foot_length = 12,
.init_readback = { 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
.ready_y_readback = { 0x01, 0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
.ready_m_readback = { 0x03, 0xff, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
.ready_c_readback = { 0x05, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
.done_c_readback = { 0x00, 0xff, 0x10, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
// .paper_codes
.paper_code_offset = -1,
},
{ .type = P_ES40,
.model = "SELPHY ES40/CP790",
.init_length = 16,
.foot_length = 12,
// .init_readback =
// .ready_y_readback =
// .ready_m_readback =
// .ready_c_readback =
// .done_c_readback =
// .paper_codes
// .paper_code_offset = -1,
},
{ .type = P_CP_XXX,
.model = "SELPHY CP Series (Except CP790)",
.init_length = 12,
.foot_length = 0,
.init_readback = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
.ready_y_readback = { 0x02, 0x00, 0x00, 0x00, 0x70, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
.ready_m_readback = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
.ready_c_readback = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
.done_c_readback = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
// .paper_codes
.paper_code_offset = 6,
},
};
#define MAX_HEADER 28
static const int init_lengths[P_END] = { 12, 16, 16, 16, 12 };
static const int foot_lengths[P_END] = { 0, 0, 12, 12, 0 };
/* Does NOT include header length! */
#define RDBUF_LEN 12
#define BUF_LEN 4096
static const int es40_plane_lengths[4] = { 2227456, 1601600, 698880, 2976512 };
static const int16_t init_readbacks[P_END][RDBUF_LEN] = { { 0x02, 0x00, 0x00, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
{ 0x02, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
{ 0xde, 0xad, 0xba, 0xbe }, // XXX ES40/CP790
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
};
static const int16_t ready_y_readbacks[P_END][RDBUF_LEN] = { { 0x04, 0x00, 0x01, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
{ 0x03, 0x00, 0x01, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
{ 0x01, 0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
{ 0xde, 0xad, 0xba, 0xbe }, // XXX ES40/CP790
{ 0x02, 0x00, 0x00, 0x00, 0x70, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
};
static const int16_t ready_m_readbacks[P_END][RDBUF_LEN] = { { 0x04, 0x00, 0x03, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
{ 0x06, 0x00, 0x03, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
{ 0x03, 0xff, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
{ 0xde, 0xad, 0xba, 0xbe }, // XXX ES40/CP790
{ 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
};
static const int16_t ready_c_readbacks[P_END][RDBUF_LEN] = { { 0x04, 0x00, 0x07, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
{ 0x09, 0x00, 0x07, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
{ 0x05, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
{ 0xde, 0xad, 0xba, 0xbe }, // XXX ES40/CP790
{ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
};
static const int16_t done_c_readbacks[P_END][RDBUF_LEN] = { { 0x04, 0x00, 0x00, 0x00, 0x02, 0x01, -1, 0x01, 0x00, 0x00, 0x00, 0x00 },
{ 0x09, 0x00, 0x00, 0x00, -1, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0xff, 0x10, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
{ 0xde, 0xad, 0xba, 0xbe }, // XXX ES40/CP790
{ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 },
};
static int16_t paper_codes[P_END][256];
static const int16_t paper_code_offsets[P_END] = { 6, 4, -1, -1, 6 };
static void setup_paper_codes(void)
{
/* Default all to IGNORE */
int i, j;
for (i = 0; i < P_END ; i++)
for (j = 0 ; j < 256 ; j++)
paper_codes[i][j] = -1;
printers[i].paper_codes[j] = -1;
/* SELPHY ES1 paper codes */
paper_codes[P_ES1][0x11] = 0x01;
paper_codes[P_ES1][0x12] = 0x02; // ??
paper_codes[P_ES1][0x13] = 0x03;
printers[P_ES1].paper_codes[0x11] = 0x01;
printers[P_ES1].paper_codes[0x12] = 0x02; // ?
printers[P_ES1].paper_codes[0x13] = 0x03;
/* SELPHY ES2/20 paper codes */
paper_codes[P_ES2_20][0x01] = 0x01;
paper_codes[P_ES2_20][0x02] = 0x02; // ??
paper_codes[P_ES2_20][0x03] = 0x03;
printers[P_ES2_20].paper_codes[0x01] = 0x01;
printers[P_ES2_20].paper_codes[0x02] = 0x02; // ?
printers[P_ES2_20].paper_codes[0x03] = 0x03;
/* SELPHY ES3/30 paper codes */
// paper_codes[P_ES3_30][0x01] = -1;
// paper_codes[P_ES3_30][0x02] = -1;
// paper_codes[P_ES3_30][0x03] = -1;
// printers[P_ES3_30]paper_codes[0x01] = -1;
// printers[P_ES3_30]paper_codes[0x02] = -1;
// printers[P_ES3_30]paper_codes[0x03] = -1;
/* SELPHY ES40/CP790 paper codes */
// paper_codes[P_ES40][0x00] = -1;
// paper_codes[P_ES40][0x01] = -1;
// paper_codes[P_ES40][0x02] = -1;
// paper_codes[P_ES40][0x03] = -1;
// printers[P_ES40].paper_codes[0x00] = -1;
// printers[P_ES40].paper_codes[0x01] = -1;
// printers[P_ES40].paper_codes[0x02] = -1;
// printers[P_ES40].paper_codes[0x03] = -1;
/* SELPHY CP-760 paper codes */
paper_codes[P_CP_XXX][0x01] = 0x11;
paper_codes[P_CP_XXX][0x02] = 0x22;
// paper_codes[P_CP_XXX][0x03] = -1;
// paper_codes[P_CP_XXX][0x04] = -1;
printers[P_CP_XXX].paper_codes[0x01] = 0x11;
printers[P_CP_XXX].paper_codes[0x02] = 0x22;
// printers[P_CP_XXX].paper_codes[0x03] = -1;
// printers[P_CP_XXX].paper_codes[0x04] = -1;
}
#define INCORRECT_PAPER -999

View file

@ -133,7 +133,7 @@ int main (int argc, char **argv)
int ret = 0;
int claimed;
uint8_t rdbuf[RDBUF_LEN], rdbuf2[RDBUF_LEN];
uint8_t rdbuf[READBACK_LEN], rdbuf2[READBACK_LEN];
int last_state = -1, state = S_IDLE;
int plane_len = 0;
@ -175,12 +175,12 @@ int main (int argc, char **argv)
return(-1);
}
fprintf(stderr, "File intended for a '%s' printer %s\r\n", models[printer_type], bw_mode? "B/W" : "");
fprintf(stderr, "File intended for a '%s' printer %s\r\n", printers[printer_type].model, bw_mode? "B/W" : "");
plane_len += 12; /* Add in plane header */
paper_code_offset = paper_code_offsets[printer_type];
paper_code_offset = printers[printer_type].paper_code_offset;
if (paper_code_offset != -1)
paper_code = paper_codes[printer_type][paper_code_offset];
paper_code = printers[printer_type].paper_codes[paper_code_offset];
/* Libusb setup */
libusb_init(&ctx);
@ -249,7 +249,7 @@ int main (int argc, char **argv)
if (i == num) {
ret = 1;
fprintf(stderr, "No suitable printers found (looking for %s)\n", models[printer_type]);
fprintf(stderr, "No suitable printers found (looking for %s)\n", printers[printer_type].model);
goto done;
}
@ -262,7 +262,7 @@ found2:
#endif
fprintf(stderr, "Found a %s printer\r\n", models[printer_type]);
fprintf(stderr, "Found a %s printer\r\n", printers[printer_type].model);
ret = libusb_open(list[i], &dev);
if (ret) {
@ -289,7 +289,7 @@ top:
/* Read in the printer status */
ret = libusb_bulk_transfer(dev, ENDPOINT_UP,
rdbuf,
RDBUF_LEN,
READBACK_LEN,
&num,
2000);
if (ret < 0) {
@ -297,12 +297,12 @@ top:
goto done;
}
if (memcmp(rdbuf, rdbuf2, RDBUF_LEN)) {
if (memcmp(rdbuf, rdbuf2, READBACK_LEN)) {
fprintf(stderr, "readback: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
rdbuf[0], rdbuf[1], rdbuf[2], rdbuf[3],
rdbuf[4], rdbuf[5], rdbuf[6], rdbuf[7],
rdbuf[8], rdbuf[9], rdbuf[10], rdbuf[11]);
memcpy(rdbuf2, rdbuf, RDBUF_LEN);
memcpy(rdbuf2, rdbuf, READBACK_LEN);
} else {
sleep(1);
}
@ -314,17 +314,17 @@ top:
switch(state) {
case S_IDLE:
if (!fancy_memcmp(rdbuf, init_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].init_readback, READBACK_LEN, paper_code_offset, paper_code)) {
state = S_PRINTER_READY;
}
break;
case S_PRINTER_READY:
fprintf(stderr, "Sending init sequence (%d bytes)\n", init_lengths[printer_type]);
fprintf(stderr, "Sending init sequence (%d bytes)\n", printers[printer_type].init_length);
/* Send printer init */
ret = libusb_bulk_transfer(dev, ENDPOINT_DOWN,
buffer,
init_lengths[printer_type],
printers[printer_type].init_length,
&num,
2000);
if (ret < 0) {
@ -333,13 +333,13 @@ top:
}
/* Realign plane data to start of buffer.. */
memmove(buffer, buffer+init_lengths[printer_type],
MAX_HEADER-init_lengths[printer_type]);
memmove(buffer, buffer+printers[printer_type].init_length,
MAX_HEADER-printers[printer_type].init_length);
state = S_PRINTER_INIT_SENT;
break;
case S_PRINTER_INIT_SENT:
if (!fancy_memcmp(rdbuf, ready_y_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].ready_y_readback, READBACK_LEN, paper_code_offset, paper_code)) {
state = S_PRINTER_READY_Y;
}
break;
@ -348,11 +348,11 @@ top:
fprintf(stderr, "Sending BLACK plane\n");
else
fprintf(stderr, "Sending YELLOW plane\n");
dump_data(plane_len, MAX_HEADER-init_lengths[printer_type], data_fd, dev, buffer, BUF_LEN);
dump_data(plane_len, MAX_HEADER-printers[printer_type].init_length, data_fd, dev, buffer, BUF_LEN);
state = S_PRINTER_Y_SENT;
break;
case S_PRINTER_Y_SENT:
if (!fancy_memcmp(rdbuf, ready_m_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].ready_m_readback, READBACK_LEN, paper_code_offset, paper_code)) {
if (bw_mode)
state = S_PRINTER_DONE;
else
@ -365,7 +365,7 @@ top:
state = S_PRINTER_M_SENT;
break;
case S_PRINTER_M_SENT:
if (!fancy_memcmp(rdbuf, ready_c_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].ready_c_readback, READBACK_LEN, paper_code_offset, paper_code)) {
state = S_PRINTER_READY_C;
}
break;
@ -375,14 +375,14 @@ top:
state = S_PRINTER_C_SENT;
break;
case S_PRINTER_C_SENT:
if (!fancy_memcmp(rdbuf, done_c_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].done_c_readback, READBACK_LEN, paper_code_offset, paper_code)) {
state = S_PRINTER_DONE;
}
break;
case S_PRINTER_DONE:
if (foot_lengths[printer_type]) {
if (printers[printer_type].foot_length) {
fprintf(stderr, "Sending cleanup sequence\n");
dump_data(foot_lengths[printer_type], 0, data_fd, dev, buffer, BUF_LEN);
dump_data(printers[printer_type].foot_length, 0, data_fd, dev, buffer, BUF_LEN);
}
state = S_FINISHED;
break;

View file

@ -80,8 +80,8 @@ int main(int argc, char **argv)
int dev_fd, data_fd;
uint8_t buffer[BUF_LEN];
uint8_t rdbuf[RDBUF_LEN];
uint8_t rdbuf2[RDBUF_LEN];
uint8_t rdbuf[READBACK_LEN];
uint8_t rdbuf2[READBACK_LEN];
int last_state, state = S_IDLE;
int printer_type = P_END;
@ -121,9 +121,9 @@ int main(int argc, char **argv)
}
/* Figure out the printer type based on the readback */
read(dev_fd, rdbuf, RDBUF_LEN);
read(dev_fd, rdbuf, READBACK_LEN);
for (printer_type2 = 0; printer_type2 < P_END ; printer_type2++) {
if (!fancy_memcmp(rdbuf, init_readbacks[printer_type2], RDBUF_LEN, -1, -1))
if (!fancy_memcmp(rdbuf, printers[printer_type2].init_readback, READBACK_LEN, -1, -1))
break;
}
if (printer_type2 == P_END) {
@ -143,26 +143,26 @@ int main(int argc, char **argv)
}
if (printer_type != printer_type2) {
fprintf(stderr, "File intended for a %s printer, aborting!\n", models[printer_type]);
fprintf(stderr, "File intended for a %s printer, aborting!\n", printers[printer_type].model);
return (-1);
} else {
fprintf(stderr, "Printing a %s file\n", models[printer_type]);
fprintf(stderr, "Printing a %s file\n", printers[printer_type].model);
}
plane_len += 12; /* Add in plane header */
paper_code_offset = paper_code_offsets[printer_type];
paper_code_offset = printers[printer_type].paper_code_offset;
if (paper_code_offset != -1)
paper_code = paper_codes[printer_type][paper_code_offset];
paper_code = printers[printer_type].paper_codes[paper_code_offset];
top:
read(dev_fd, rdbuf, RDBUF_LEN); /* Read the status from printer */
if (memcmp(rdbuf, rdbuf2, RDBUF_LEN)) {
read(dev_fd, rdbuf, READBACK_LEN); /* Read the status from printer */
if (memcmp(rdbuf, rdbuf2, READBACK_LEN)) {
fprintf(stderr, "readback: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
rdbuf[0], rdbuf[1], rdbuf[2], rdbuf[3],
rdbuf[4], rdbuf[5], rdbuf[6], rdbuf[7],
rdbuf[8], rdbuf[9], rdbuf[10], rdbuf[11]);
memcpy(rdbuf2, rdbuf, RDBUF_LEN);
memcpy(rdbuf2, rdbuf, READBACK_LEN);
} else {
sleep(1);
}
@ -174,22 +174,22 @@ top:
switch(state) {
case S_IDLE:
if (!fancy_memcmp(rdbuf, init_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].init_readback, READBACK_LEN, paper_code_offset, paper_code)) {
state = S_PRINTER_READY;
break;
}
break;
case S_PRINTER_READY:
fprintf(stderr, "Sending init sequence (%d bytes)\n", init_lengths[printer_type]);
write(dev_fd, buffer, init_lengths[printer_type]); /* Send printer_init */
fprintf(stderr, "Sending init sequence (%d bytes)\n", printers[printer_type].init_length);
write(dev_fd, buffer, printers[printer_type].init_length); /* Send printer_init */
/* Realign plane data to start of buffer.. */
memmove(buffer, buffer+init_lengths[printer_type],
MAX_HEADER-init_lengths[printer_type]);
memmove(buffer, buffer+printers[printer_type].init_length,
MAX_HEADER-printers[printer_type].init_length);
state = S_PRINTER_INIT_SENT;
break;
case S_PRINTER_INIT_SENT:
if (!fancy_memcmp(rdbuf, ready_y_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].ready_y_readback, READBACK_LEN, paper_code_offset, paper_code)) {
state = S_PRINTER_READY_Y;
}
break;
@ -198,11 +198,11 @@ top:
fprintf(stderr, "Sending BLACK plane\n");
else
fprintf(stderr, "Sending YELLOW plane\n");
dump_data(plane_len, MAX_HEADER-init_lengths[printer_type], data_fd, dev_fd, buffer, BUF_LEN);
dump_data(plane_len, MAX_HEADER-printers[printer_type].init_length, data_fd, dev_fd, buffer, BUF_LEN);
state = S_PRINTER_Y_SENT;
break;
case S_PRINTER_Y_SENT:
if (!fancy_memcmp(rdbuf, ready_m_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].ready_m_readback, READBACK_LEN, paper_code_offset, paper_code)) {
if (bw_mode)
state = S_PRINTER_DONE;
else
@ -215,7 +215,7 @@ top:
state = S_PRINTER_M_SENT;
break;
case S_PRINTER_M_SENT:
if (!fancy_memcmp(rdbuf, ready_c_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].ready_c_readback, READBACK_LEN, paper_code_offset, paper_code)) {
state = S_PRINTER_READY_C;
}
break;
@ -225,14 +225,14 @@ top:
state = S_PRINTER_C_SENT;
break;
case S_PRINTER_C_SENT:
if (!fancy_memcmp(rdbuf, done_c_readbacks[printer_type], RDBUF_LEN, paper_code_offset, paper_code)) {
if (!fancy_memcmp(rdbuf, printers[printer_type].done_c_readback, READBACK_LEN, paper_code_offset, paper_code)) {
state = S_PRINTER_DONE;
}
break;
case S_PRINTER_DONE:
if (foot_lengths[printer_type]) {
if (printers[printer_type].foot_length) {
fprintf(stderr, "Sending cleanup sequence\n");
dump_data(foot_lengths[printer_type], 0, data_fd, dev_fd, buffer, BUF_LEN);
dump_data(printers[printer_type].foot_length, 0, data_fd, dev_fd, buffer, BUF_LEN);
}
state = S_FINISHED;
break;