diff --git a/include/tabby/printer.h b/include/tabby/printer.h index 4a75f56..6400b75 100644 --- a/include/tabby/printer.h +++ b/include/tabby/printer.h @@ -26,6 +26,9 @@ typedef enum { TABBY_PRINTER_OK = 0 } tabby_printer_status; +#define TABBY_PRINTER_WAIT 0x0e +#define TABBY_PRINTER_ERROR 0xf0 + typedef enum { TABBY_PRINTER_PACKET_INIT = 0x01, TABBY_PRINTER_PACKET_JOB = 0x02, diff --git a/src/printer.c b/src/printer.c index 47a87f3..3c85a59 100644 --- a/src/printer.c +++ b/src/printer.c @@ -197,16 +197,25 @@ int tabby_printer_job_cancel(tabby_printer *printer) { } int tabby_printer_wait(tabby_printer *printer) { - do { + while (1) { sleep(1); if (tabby_printer_inquiry_send(printer) < 0) { goto error_inquiry_send; } - } while (printer->status); + + if (printer->status & (TABBY_PRINTER_WAIT | TABBY_PRINTER_SUM)) { + continue; + } else if (printer->status & TABBY_PRINTER_ERROR) { + goto error_printer; + } else { + break; + } + } return 0; +error_printer: error_inquiry_send: return -1; }