diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index c552178..1f72e23 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -537,6 +537,56 @@ void ATBDeviceControllerPlugin::requestPrintReceipt(const QHashprn_switchPower(true); + hw->prn_sendText(&ba); + QTimer::singleShot(4000, this, SLOT(onPrinterWaitForPrintingReceipt())); + + //QTimer::singleShot(2000, this, [this](){ hw->prn_cut(3); } ); +} + +void ATBDeviceControllerPlugin::onPrinterWaitForPrintingReceipt() +{ + quint8 printerResult = this->hw->prn_getPrintResult(); + + switch (printerResult) { + case 0: // still printing + qCritical() << "--> printer: WaitForPrintingReceipt"; + QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingReceipt())); + break; + case 1: // printing finished, Ok + qCritical() << "DC Finished printing receipt"; + emit this->printReceiptFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS, + // TODO: TicketNumber + "", + ""); + hw->prn_switchPower(true); + hw->prn_cut(3); + break; + case 2: // printing finished, Error + qCritical() << "DC Error: wait for printing receipt"; + this->errorCode = "PRINTER"; // TODO: get more detailed error code from low level API + this->errorDescription = "Printer error"; // TODO: get more detailed error description from low level API + + emit this->printReceiptFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND, + this->errorCode, + this->errorDescription); + break; + default: + qCritical() << "DC Error: wait for printing receipt"; + this->errorCode = "PRINTER"; // TODO: get more detailed error code from low level API + this->errorDescription = "Printer error"; // TODO: get more detailed error description from low level API + + emit this->printReceiptFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND, + this->errorCode, + this->errorDescription); + break; + } + +} + void ATBDeviceControllerPlugin::requestPrintTicket(const QHash & printingData) { @@ -662,21 +712,21 @@ void ATBDeviceControllerPlugin::onPrinterDataPrepared() // note: calling prn_getPrintResult() immediately may result in wrong answer! // We have to wait "about some seconds" until calling this function! - QTimer::singleShot(4000, this, SLOT(onPrinterWaitForPrinting())); + QTimer::singleShot(4000, this, SLOT(onPrinterWaitForPrintingTicket())); // old: use printer templates: // this->currentTemplate = 1; // this->onPrinterPrintNextTemplate(); } -void ATBDeviceControllerPlugin::onPrinterWaitForPrinting() +void ATBDeviceControllerPlugin::onPrinterWaitForPrintingTicket() { quint8 printerResult = this->hw->prn_getPrintResult(); switch (printerResult) { case 0: // still printing - qCritical() << "--> printer: WaitForPrinting"; - QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrinting())); + qCritical() << "--> printer: WaitForPrintingTicket"; + QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingTicket())); break; case 1: // printing finished, Ok this->onPrintFinishedOK(); diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index a3c0ead..654613d 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -52,6 +52,7 @@ public: void requestPrintTicket(const QHash & printingData); void requestPrintTicket(nsDeviceControllerInterface::TICKET_VARIANT ticketVariant, const QHash & printingData); void requestPrintReceipt(const QHash & printingData); + void requestPrintReceipt(const QString & printingString); // TASKS: Account ------------------------------------------------------------- void requestAccount(); @@ -125,7 +126,8 @@ private slots: void onPrinterDataPrepared(); void onPrinterDataPreparedForTemplates(); void onPrinterPrintNextTemplate(); - void onPrinterWaitForPrinting(); + void onPrinterWaitForPrintingTicket(); + void onPrinterWaitForPrintingReceipt(); void onPrintFinishedOK(); void onPrintFinishedERR();