From dcaf33ce01fc7ef5b297909827fddc28e326543c Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Fri, 10 Jun 2016 22:12:22 +0000 Subject: [PATCH] I *really* care about reliability and error detection! --- include/tabby/printer.h | 3 +++ src/printer.c | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) 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; }