diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 892b4b8..e657ee5 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -311,6 +311,73 @@ void ATBDeviceControllerPlugin::cashCollect() } } + +void ATBDeviceControllerPlugin::cashCollect(const QString & amount) +{ + if (this->coinProcessor() != nsDeviceControllerInterface::COIN_PROCESSOR::CHANGER) { + this->cashCollect(); + return; + } + + // check if we must change coins: + + // inserted amount + uint32_t amountInsertedInt = this->hw->getInsertedAmount(); + + bool ok; + uint32_t amountToPayInt = amount.toInt(&ok); + + // check if we must change coins: + if (amountInsertedInt > amountToPayInt) { + + uint32_t amountToChangeInt = amountInsertedInt - amountToPayInt; + + qCritical() << "cashCollect(" << amount << ")"; + qCritical() << " amount to change: " << QString::number(amountToChangeInt); + + + // trigger changer: + emit this->cashPaymentChanging(nsDeviceControllerInterface::RESULT_STATE::SUCCESS, + QString::number(amountToChangeInt), + "", // ErrorCode + ""); // ErrorDescription + + // change + hw->changer_returnCoins(amountToChangeInt); + + QTimer::singleShot(1000, this, &ATBDeviceControllerPlugin::onCashChangerState); + + } + else { + // nothing to change: + + qCritical() << "cashCollect(" << amount << ")"; + qCritical() << " nothing to change. "; + + + hw->vend_success(); + + QString amountString = QString::number(amountInsertedInt); + + // inserted coins + uint32_t amountCoinsInt = CashUtils::getAmountOfInsertedCoins(this->hw); + QString amountCoinsString = QString::number(amountCoinsInt); + + // inserted notes + uint32_t amountNotesInt = CashUtils::getAmountOfInsertedNotes(this->hw); + QString amountNotesString = QString::number(amountNotesInt); + + emit this->cashPaymentFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS, + amountString, + amountCoinsString, // coins + amountNotesString, // notes + 0, // proposed change + "", + ""); + this->currentCashState = CASH_STATE::CACHE_EMPTY; + } +} + void ATBDeviceControllerPlugin::cashAbort() { hw->vend_failed(); @@ -1444,6 +1511,10 @@ void ATBDeviceControllerPlugin::onCashChangerState() ""); changerStateRequestCounter = 0; lastChangerResult = 0; + + // finalize vending: + hw->vend_success(); + return; } else @@ -1498,6 +1569,10 @@ void ATBDeviceControllerPlugin::onCashChangerState() errorDescription); changerStateRequestCounter = 0; lastChangerResult = 0; + + // finalize vending: + hw->vend_success(); + return; } diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index 6a1ce44..53f562b 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -50,6 +50,7 @@ public: void requestStartCashInput(const QString & amount); void requestStopCashInput(); void cashCollect(); + void cashCollect(const QString & amount); void cashAbort(); // read coin/cash processing variants -----------------------------------------