APservice/win10_pay.cpp

610 lines
19 KiB
C++
Executable File

#include "win10_pay.h"
#define TIME_DISPLAY_SIGNALS_MS 2000
static uint8_t win10_paymentStarted;
static uint32_t win10_value;
T_win10::T_win10(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
this->HWaccess = HWaccess;
myLayout = new QGridLayout;
QFont myTabFont;
myTabFont.setPixelSize(PIXELSIZE_LABEL);
lab1 =new QLabel(tr("Testing Payment"));
lab1->setFont(myTabFont);
myLayout->addWidget(lab1,1,0);
QLabel *labs2 =new QLabel(tr(" "));
labs2->setFont(myTabFont);
myLayout->addWidget(labs2,1,1);
// QLabel *labs3 =new QLabel(tr(" "));
// labs3->setFont(myTabFont);
// myLayout->addWidget(labs3,1,2);
QLabel *labs4 =new QLabel(tr(" "));
labs4->setFont(myTabFont);
myLayout->addWidget(labs4,1,3);
QLabel *labs5 =new QLabel(tr(" "));
labs5->setFont(myTabFont);
myLayout->addWidget(labs5,1,4);
// lab2 =new QLabel(tr(" "));
// lab2->setFont(myTabFont);
// myLayout->addWidget(lab2,2,0);
lab3 =new QLabel(tr("Amount in cent:"));
lab3->setFont(myTabFont);
myLayout->addWidget(lab3,3,0);
myTabFont.setPixelSize(PIXELSIZE_DATA);
insertedCoin = new QLineEdit();
insertedCoin->setMaxLength(10);
insertedCoin->setFrame(true);
insertedCoin->setText("-");
insertedCoin->setReadOnly(true);
insertedCoin->setFont(myTabFont);
insertedCoin->setMaxLength(100);
insertedCoin->setStyleSheet("background-color: white");
myLayout->addWidget(insertedCoin,3,1);
myTabFont.setPixelSize(PIXELSIZE_LABEL);
lab4 =new QLabel(tr("inserted total: "));
lab4->setFont(myTabFont);
myLayout->addWidget(lab4,4,0);
myTabFont.setPixelSize(PIXELSIZE_DATA);
insertedTotal = new QLineEdit();
insertedTotal->setMaxLength(10);
insertedTotal->setFrame(true);
insertedTotal->setText("-");
insertedTotal->setReadOnly(true);
insertedTotal->setFont(myTabFont);
insertedTotal->setMaxLength(100);
insertedTotal->setStyleSheet("background-color: white");
myLayout->addWidget(insertedTotal,4,1);
myTabFont.setPixelSize(PIXELSIZE_LABEL);
lab8 =new QLabel(tr("inserted: "));
lab8->setFont(myTabFont);
myLayout->addWidget(lab8,5,0);
// display ALL inserted coins:
myTabFont.setPixelSize(PIXELSIZE_DATA);
allCoins = new QListWidget;
allCoins->setFont(myTabFont);
allCoins->setMinimumHeight(100);
myLayout->addWidget(allCoins,5,1);
myTabFont.setPixelSize(PIXELSIZE_LABEL);
lab5 =new QLabel(tr("Amount to pay:"));
lab5->setFont(myTabFont);
myLayout->addWidget(lab5,6,0);
myKeypad = new T_keypad();
myLayout->addWidget(myKeypad,5,1);
connect(myKeypad, SIGNAL(keyEntryFinished()), this, SLOT(valueIsSet()));
myTabFont.setPixelSize(PIXELSIZE_BUTTONS);
pb_enterPrice = new QPushButton("click to select");
pb_enterPrice->setFont(myTabFont);
myLayout->addWidget(pb_enterPrice,6,1);
//pb_enterPrice->setText("0");
connect(pb_enterPrice, SIGNAL(clicked()), this, SLOT(Button_enterPriceClicked()));
pb_statPay = new QPushButton("START\n");
pb_statPay->setFont(myTabFont);
myLayout->addWidget(pb_statPay,6,2);
connect(pb_statPay, SIGNAL(clicked()), this, SLOT(ButtonStartClicked()));
pb_stopPay = new QPushButton("STOP\n Pay");
pb_stopPay->setFont(myTabFont);
myLayout->addWidget(pb_stopPay,8,0);
connect(pb_stopPay, SIGNAL(clicked()), this, SLOT(ButtonStopClicked()));
pb_cancelPay = new QPushButton("CANCEL\n Pay");
pb_cancelPay->setFont(myTabFont);
myLayout->addWidget(pb_cancelPay,8,1);
connect(pb_cancelPay, SIGNAL(clicked()), this, SLOT(ButtonCancelClicked()));
pb_vendSucc = new QPushButton(" VEND\nsuccess");
pb_vendSucc->setFont(myTabFont);
myLayout->addWidget(pb_vendSucc,8,2);
connect(pb_vendSucc, SIGNAL(clicked()), this, SLOT(ButtonSuccClicked()));
pb_vendFail = new QPushButton(" VEND\nfailed");
pb_vendFail->setFont(myTabFont);
myLayout->addWidget(pb_vendFail,8,3);
connect(pb_vendFail, SIGNAL(clicked()), this, SLOT(ButtonFailClicked()));
myTabFont.setPixelSize(PIXELSIZE_LABEL);
lab7 =new QLabel(tr(" "));
lab7->setFont(myTabFont);
myLayout->addWidget(lab7,9,0);
// rechts oben, zeige Bezahlstatus:
QLabel *lab8 =new QLabel(tr("pay state:"));
lab8->setFont(myTabFont);
myLayout->addWidget(lab8,3,2);
myTabFont.setPixelSize(PIXELSIZE_DATA);
coinPayState = new QLineEdit();
coinPayState->setFrame(true);
coinPayState->setText(" ");
coinPayState->setReadOnly(true);
coinPayState->setFont(myTabFont);
//coinPayState->setMaxLength(100);
myLayout->addWidget(coinPayState,3,3);
coinPayState->setStyleSheet("background-color: white");
// "background-color: white" "background-color: yellow"
// "background-color: rgb(150,230,150)"); // hell grün
// "background-color: rgb(250,150,150)"); // hell rot
// darunter Signale anzeigen:
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab9 =new QLabel(tr("last Signal:"));
lab9->setFont(myTabFont);
myLayout->addWidget(lab9,4,2);
myTabFont.setPixelSize(PIXELSIZE_DATA);
coinPaySignals = new QLineEdit();
coinPaySignals->setFrame(true);
coinPaySignals->setText(" ");
coinPaySignals->setReadOnly(true);
coinPaySignals->setFont(myTabFont);
coinPaySignals->setStyleSheet("background-color: white");
myLayout->addWidget(coinPaySignals,4,3);
empState = new QListWidget;
empState->setFont(myTabFont);
myLayout->addWidget(empState,5,3);
setLayout(myLayout);
myNextStep=0;
myStep=99;
myTO = new QTimer();
myTO->setSingleShot(true);
myTO->start(2000);
timerClrDisp = new QTimer();
timerClrDisp->setSingleShot(true);
//timerClrDisp->start(1000);
connect(timerClrDisp, SIGNAL(timeout()), this, SLOT(win10_slotClrSig()));
// Eingangssignal auf QObject casten, weil hwinf kein QObject ist
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_gotNewCoin()), this, SLOT(signalGotNewCoin()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_coinCollectionJustStarted()), this, SLOT(signalJustStarted()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_coinCollectionAborted()), this, SLOT(signalCollectAbort()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_payStopByMax()), this, SLOT(signalStopByMax()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_payStopByPushbutton()), this, SLOT(signalStopByUser()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_payStopByEscrow()), this, SLOT(signalStopByEscrow()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_payStopByError()), this, SLOT(signalStopByError()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_payStopByTimeout()), this, SLOT(signalStopTO()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_payCancelled()), this, SLOT(signalCancelled()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_coinProcessJustStopped()), this, SLOT(signalProcessStop()));
win10_paymentStarted=0;
win10_value=0;
}
void T_win10::addDigit2Val(uint8_t digi)
{
QString myStr;
win10_value*=10;
win10_value+=digi;
myStr.clear();
myStr.append(QString::number(win10_value));
startAmount->setText(myStr);
}
T_win10::~T_win10()
{
close();
}
void T_win10::Nav_back(void)
{
myNextStep=WCS_WIN10BAK;
}
void T_win10::Nav_home(void)
{
myNextStep=WCS_WIN10MID;
}
void T_win10::Nav_next(void)
{
myNextStep=WCS_WIN10FWD;
}
void T_win10::Button_enterPriceClicked(void)
{
myKeypad->show();
}
void T_win10::ButtonStartClicked()
{
QString myStr, tmpStr;
uint32_t val;
myStr.clear();
tmpStr.clear();
insertedCoin->clear();
insertedTotal->clear();
allCoins->clear();
//myStr=startAmount->text();
myStr=pb_enterPrice->text();
val=myStr.toULong();
//tmpStr.append(QString::number(uitmp));
//qDebug()<<"from box: " << myStr << " dec: " << val;
HWaccess->cash_startPayment(val);
coinPayState->setStyleSheet("background-color: white");
coinPayState->setText("starting...");
win10_paymentStarted=1;
}
void T_win10::ButtonStopClicked()
{
HWaccess->cash_stopPayment();
coinPayState->setStyleSheet("background-color: yellow");
coinPayState->setText(" ");
}
void T_win10::ButtonCancelClicked()
{
HWaccess->cash_cancelPayment();
coinPayState->setStyleSheet("background-color: white");
coinPayState->setText(" ");
}
void T_win10::ButtonSuccClicked()
{
HWaccess->vend_success();
coinPayState->setStyleSheet("background-color: white");
coinPayState->setText(" ");
}
void T_win10::ButtonFailClicked()
{
HWaccess->vend_failed();
coinPayState->setStyleSheet("background-color: white");
coinPayState->setText(" ");
}
void T_win10::signalGotNewCoin()
{
uint32_t ultmp;
QString myStr;
uint16_t types[66], values[66];
int nn;
//qDebug()<<"signal got new coin";
myStr.clear();
ultmp=HWaccess->getLastInsertedCoin();
//if (ultmp>0 && ultmp<1000)
{
myStr.append(QString::number(ultmp));
insertedCoin->setText(myStr);
}
//qDebug()<<myStr;
myStr.clear();
ultmp=HWaccess->getInsertedAmount();
//if (ultmp>0 && ultmp<65000)
{
myStr.append(QString::number(ultmp));
insertedTotal->setText(myStr);
}
//qDebug()<<myStr;
HWaccess->getAllInsertedCoins(types, values);
// all inserted coins (max 64) since "cash_startPayment"
allCoins->clear();
nn=0;
do
{
myStr.clear();
if (types[nn]>0 && values[nn]>0)
{
myStr.append("Index: ");
myStr.append(QString::number(nn));
myStr.append(" Type: ");
myStr.append(QString::number(types[nn]));
myStr.append(" Val: ");
myStr.append(QString::number(values[nn]));
allCoins->addItem(myStr);
}
} while (++nn<64);
coinPaySignals->setText("got new coin ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
}
void T_win10::signalJustStarted()
{
coinPaySignals->setText("just started ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
coinPayState->setStyleSheet("background-color: green");
coinPayState->setText("insert coins....");
}
void T_win10::signalCollectAbort()
{
coinPaySignals->setText("collect aborted ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
coinPayState->setStyleSheet("background-color: white");
coinPayState->setText(" ");
}
void T_win10::signalStopByMax()
{
coinPaySignals->setText("stopped by max ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
coinPayState->setStyleSheet("background-color: yellow");
coinPayState->setText(" ");
}
void T_win10::signalStopByUser()
{
coinPaySignals->setText("stopped by user ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
coinPayState->setStyleSheet("background-color: yellow");
coinPayState->setText(" ");
}
void T_win10::signalStopByEscrow()
{
coinPaySignals->setText("STOPPED BY ESCROW ");
timerClrDisp->start(1000); // wieder loeschen
coinPayState->setStyleSheet("background-color: yellow");
coinPayState->setText(" ");
}
void T_win10::signalStopByError()
{
coinPaySignals->setText("stopped by error ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
coinPayState->setStyleSheet("background-color: white");
coinPayState->setText(" ");
}
void T_win10::signalStopTO()
{
coinPaySignals->setText("stopped by TO ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
coinPayState->setStyleSheet("background-color: white");
coinPayState->setText(" ");
}
void T_win10::signalCancelled()
{
coinPaySignals->setText("canncelled ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
coinPayState->setStyleSheet("background-color: white");
coinPayState->setText(" ");
}
void T_win10::signalProcessStop()
{
coinPaySignals->setText("processing stopped ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
coinPayState->setStyleSheet("background-color: white");
coinPayState->setText(" ");
}
void T_win10::win10_slotClrSig()
{
coinPaySignals->setText(" ");
timerClrDisp->start(TIME_DISPLAY_SIGNALS_MS); // wieder loeschen
}
void T_win10::valueIsSet(void)
{
pb_enterPrice->setText( myKeypad->getValueString() );
}
void T_win10::pay_slotClrSig(void)
{
coinPaySignals->clear();
}
bool T_win10::work_ini(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called ONE time after selecting this state (initialization)
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
*nextScreen=0; // needed 0=no change
*useNavi=SWITCH_BACK_ON | SWITCH_HOME_ON | SWITCH_NEXT_ON;
myNextStep=0;
return false;
}
#define SENDINGGRID_MS 300
//itmp=globVar_GetCoinChecker();
bool T_win10::working(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called cyclic until this state changes intentionally to another state
// display informations for human operator, react on operators inputs or wait for payment media
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
QString myStr;
struct T_emp empStat;
struct T_dynamicCondition myDynMachCond;
//uint8_t prbuf[66];
myStr.clear();
*nextScreen=0; // 0=no change
*useNavi=0;
//myStr=startAmount->text();
HWaccess->emp_getAllParameters(&empStat);
/*
struct T_emp
{
// Fixdata from EMP:
uint8_t shaft; // = changer level
uint16_t countryCode;
uint8_t scale;
uint8_t decimals;
uint8_t coinValues[16];
uint16_t routing;
// Master specs:
uint8_t gotSetup; // 1: got specifications from master 0: no specs
uint16_t coinAccept; // bit 0 = coin1 bit H=accept
uint8_t tokenChannel;
uint16_t denomination[16];
// dynamic:
uint8_t state; // step counter of EMP (electronic coin checker) FSM (finite state machine):
// 0=Emp & Bus power off, 1=powered, poll off 2=polling on
// 3=device responded, requesting status
// 4=waiting for status 5=have status,
// 6: IDLE, have paramters from master, polling running, ready for payment
// Master can stop/start polling and acceptance
// 7: end of transaction, polling on, accept off, reporting coins, (wait for last coin)
// 8: transaction running, polling on, acceptance on, reporting coins,
uint8_t pollingRunning;
uint8_t paymentRunning;
};
*/
empState->clear();
myStr.clear();
myStr.append("EMP State: ");
myStr.append(QString::number(empStat.state));
empState->addItem(myStr);
myStr.clear();
myStr.append("polling: ");
myStr.append(QString::number(empStat.pollingRunning));
empState->addItem(myStr);
myStr.clear();
myStr.append("pay active: ");
myStr.append(QString::number(empStat.paymentRunning));
empState->addItem(myStr);
HWaccess->sys_getDynMachineConditions(&myDynMachCond);
myStr.clear();
myStr.append("paym. in progress: ");
myStr.append(QString::number(myDynMachCond.paymentInProgress));
empState->addItem(myStr);
uint8_t curStat;
curStat = HWaccess->cash_paymentProcessing();
// return value:
// 0: stopped 1: starting up 2: coin collection
// 3: finished by User (Push button) 4: finished, Max-Value collected
// 5: finished by escrow
// 6: money encashed
// 7: cancelled
// 10,11: error cannot start
// 12: timeout while payment, coins returned
// 13: stopped by unexpected error
myStr.clear();
myStr.append("paym.Processing: ");
myStr.append(QString::number(curStat));
empState->addItem(myStr);
myStr.clear();
myStr.append("paym.Started: ");
myStr.append(QString::number(win10_paymentStarted));
empState->addItem(myStr);
if (win10_paymentStarted==1)
{
/*
if (curStat<2 || curStat==6 || curStat==7)
coinPayState->setStyleSheet("background-color: white");
else
if (curStat==2)
coinPayState->setStyleSheet("background-color: rgb(150,230,150)"); // hell grün
// "background-color: white" "background-color: yellow"
// "background-color: rgb(150,230,150)"); // hell grün
// "background-color: rgb(250,150,150)"); // hell rot
else
if (curStat>=3 && curStat<=5)
coinPayState->setStyleSheet("background-color: yellow");
else
if (curStat>=10)
coinPayState->setStyleSheet("background-color: rgb(250,150,150)"); // hell rot
switch (curStat)
{
case 1: //coinPayState->setText("starting..."); break;
//coinPayState->clear();
break;
case 2: coinPayState->setText("wait for coins"); break;
case 3: coinPayState->setText("finished by user"); break;
case 4: coinPayState->setText("got full amount"); break;
case 5: coinPayState->setText("escrow full"); break;
case 7: coinPayState->setText("cancelled"); break;
case 10: coinPayState->setText("Hardware error"); break;
case 11: coinPayState->setText("cannot start"); break;
case 12: coinPayState->setText("timeout"); break;
case 13: coinPayState->setText("unknown error"); break;
}
*/
if (curStat==0)
win10_paymentStarted++; // nur 1x anzeigen
}
if (myNextStep)
{
*nextScreen=myNextStep;
myNextStep=0;
}
return false;
}