#include #include #include #include #include #include #include #include #include #include static void usage(int argc, char **argv, char *message, ...) { if (message) { va_list args; va_start(args, message); vfprintf(stderr, message, args); fprintf(stderr, "\n"); va_end(args); } fprintf(stderr, "usage: %s print device sheet.tile\n", argv[0]); exit(1); } int tabby_command_print(int argc, char **argv) { int fd; ssize_t readlen; size_t offset = 0; tabby_printer *printer; uint8_t band[TABBY_PRINTER_BAND_SIZE]; if (argc != 4) { usage(argc, argv, "Must specify device and tile"); } if ((fd = open(argv[3], O_RDONLY)) < 0) { fprintf(stderr, "%s: %s: %s: %s\n", argv[0], "open()", argv[3], strerror(errno)); goto error_open_tile; } if ((printer = tabby_printer_open(argv[2])) == NULL) { fprintf(stderr, "%s: %s: %s: %s\n", argv[0], "tabby_printer_open()", argv[2], strerror(errno)); goto error_printer_open; } do { sleep(1); tabby_printer_init(printer); } while (printer->device != TABBY_PRINTER_DEVICE_ID); while ((readlen = read(fd, band, sizeof(band))) > 0) { offset += readlen; tabby_printer_band_send(printer, band); if (offset % TABBY_PRINTER_SHEET_SIZE == 0) { tabby_printer_band_finish(printer); tabby_printer_wait(printer); tabby_printer_job_start(printer, 1, 0x00, 0x00, 0x40); tabby_printer_wait(printer); } } if (offset % TABBY_PRINTER_SHEET_SIZE) { tabby_printer_band_finish(printer); tabby_printer_wait(printer); tabby_printer_job_start(printer, 1, 0x00, 0x00, 0x40); tabby_printer_wait(printer); } tabby_printer_close(printer); return 0; error_printer_open: close(fd); error_open_tile: return 1; }