2023-11-30 18:15:07 +01:00
|
|
|
#include "CashUtils.h"
|
|
|
|
|
2023-12-08 12:33:46 +01:00
|
|
|
#include <QDebug>
|
2023-11-30 18:15:07 +01:00
|
|
|
|
|
|
|
#define MAX_COINS 64
|
|
|
|
#define MAX_NOTES 16
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Get current inserted coins
|
|
|
|
*
|
|
|
|
* getAllInsertedCoins(uint16_t *types, uint16_t *values)
|
|
|
|
* all inserted coins of this past transaction are stored, max 64
|
|
|
|
*/
|
2023-12-08 12:33:46 +01:00
|
|
|
uint32_t CashUtils::getAmountOfInsertedCoins(hwinf* hw)
|
2023-11-30 18:15:07 +01:00
|
|
|
{
|
|
|
|
uint32_t result = 0;
|
|
|
|
|
|
|
|
uint16_t types[MAX_COINS];
|
|
|
|
uint16_t values[MAX_COINS];
|
|
|
|
hw->getAllInsertedCoins(types, values);
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_COINS; i++) {
|
2023-12-08 12:33:46 +01:00
|
|
|
result += values[i];
|
2023-11-30 18:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Get current inserted notes
|
|
|
|
*
|
|
|
|
* virtual uint8_t bna_getCurrentNotes(uint16_t latestBill, uint16_t *currentNotes) const =0;
|
|
|
|
* returns number of collected bank notes since start-command (current transaction)
|
2023-12-08 12:33:46 +01:00
|
|
|
* latestBill: last accepted bank note, value in cent
|
|
|
|
* currentNotes an array with up to 16 (further) notes collected
|
2023-11-30 18:15:07 +01:00
|
|
|
*
|
|
|
|
*/
|
2023-12-08 12:33:46 +01:00
|
|
|
uint32_t CashUtils::getAmountOfInsertedNotes(hwinf* hw)
|
2023-11-30 18:15:07 +01:00
|
|
|
{
|
|
|
|
uint32_t result = 0;
|
2023-12-14 15:48:37 +01:00
|
|
|
uint8_t numberOfInsertedNotes;
|
2023-11-30 18:15:07 +01:00
|
|
|
|
2023-12-14 15:48:37 +01:00
|
|
|
uint16_t beforeArray = 0;
|
|
|
|
uint16_t currentNotes[4];
|
|
|
|
uint16_t afterArray = 0;
|
|
|
|
numberOfInsertedNotes = hw->bna_getCurrentNotes(0, currentNotes);
|
2023-11-30 18:15:07 +01:00
|
|
|
|
2023-12-14 15:48:37 +01:00
|
|
|
if ( (beforeArray != 0) || (afterArray != 0) ) {
|
|
|
|
qCritical() << "CashUtils::getAmountOfInsertedNotes() ERROR: Array";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numberOfInsertedNotes == 99) {
|
|
|
|
// Error
|
|
|
|
qCritical() << "CashUtils::getAmountOfInsertedNotes() ERROR: ";
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
qCritical() << " currentNotes[" << i << "] = " << currentNotes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// no error
|
|
|
|
result = currentNotes[3];
|
|
|
|
result = ( result << 16 ) | currentNotes[2];
|
2023-12-08 12:33:46 +01:00
|
|
|
}
|
2023-11-30 18:15:07 +01:00
|
|
|
|
2023-12-14 15:48:37 +01:00
|
|
|
// DEBUG
|
|
|
|
qCritical() << "--------------------------------------------------";
|
|
|
|
qCritical() << "CashUtils::getAmountOfInsertedNotes()";
|
|
|
|
qCritical() << " numberOfInsertedNotes = " << numberOfInsertedNotes;
|
|
|
|
qCritical() << " result = " << result;
|
|
|
|
qCritical() << "--------------------------------------------------";
|
|
|
|
|
2023-11-30 18:15:07 +01:00
|
|
|
return result;
|
|
|
|
}
|