APservice/win06_prn.cpp

625 lines
19 KiB
C++
Raw Permalink Normal View History

2023-11-14 09:32:56 +01:00
#include "win06_prn.h"
T_win06::T_win06(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
int nn;
this->HWaccess = HWaccess;
myLayout = new QGridLayout;
QFont myTabFont;
myTabFont.setPixelSize(PIXELSIZE_LABEL);
lab1 =new QLabel(tr("Printer"));
lab1->setFont(myTabFont);
myLayout->addWidget(lab1,1,0);
myTabFont.setPixelSize(PIXELSIZE_BUTTONS);
butPrnPow = new QPushButton("Power");
myLayout->addWidget(butPrnPow,1,1);
butPrnPow->setFont(myTabFont);
butPrnPow->setStyleSheet("background-color: white");
butPrnPow->setCheckable(true); // true = toggle button
butPrnPow->setAutoDefault(false); // beim start aus
butPrnPow->setMinimumWidth(100);
butPrnPow->setMinimumHeight(40);
butPrnPow->setChecked(true);
connect(butPrnPow, SIGNAL(clicked()), this, SLOT(slot_powerButton()));
2024-07-08 10:34:47 +02:00
2023-11-14 09:32:56 +01:00
myTabFont.setPixelSize(14);
QLabel *lab14 =new QLabel(tr("external low paper sensor:"));
lab14->setFont(myTabFont);
lab14->setAlignment( Qt::AlignRight);
myLayout->addWidget(lab14,1,2);
lab15 =new QLabel(tr(" "));
lab15->setFont(myTabFont);
lab15->setStyleSheet("background-color: white");
lab15->setFrameStyle(3);
myLayout->addWidget(lab15,1,3);
2024-07-08 10:34:47 +02:00
QLabel *lab30 = new QLabel(" ");
myLayout->addWidget(lab30,2,0);
2023-11-14 09:32:56 +01:00
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab12 =new QLabel(tr("State:"));
lab12->setFont(myTabFont);
myLayout->addWidget(lab12,3,0);
myTabFont.setPixelSize(22);
showPrnState1 =new QLabel(tr(" "));
showPrnState1->setFont(myTabFont);
showPrnState1->setFrameStyle(1);
myLayout->addWidget(showPrnState1,3,1);
// selection box for Template-number to be printed
myTabFont.setPixelSize(20);
cb_templNr = new QComboBox();
myLayout->addWidget(cb_templNr,3,2);
for (nn=1; nn<=32; nn++)
cb_templNr->addItem(swl_int2str(nn));
cb_templNr->setFont(myTabFont);
cb_templNr->setCurrentIndex(0); // war 28 (=29)
cb_templNr->setMaxVisibleItems(5);
cb_templNr->setStyleSheet("QScrollBar:vertical { width: 30px; }");
//myTabFont.setPixelSize(14);
myTabFont.setPixelSize(PIXELSIZE_BUTTONS);
QPushButton *butPrint2 = new QPushButton(" print\ntemplate");
myLayout->addWidget(butPrint2,3,3);
connect(butPrint2, SIGNAL(clicked()), this, SLOT(slot_printVaris()));
2024-07-08 10:34:47 +02:00
QLabel *lab31 = new QLabel(" ");
myLayout->addWidget(lab31,4,0);
2023-11-14 09:32:56 +01:00
// myTabFont.setPixelSize(14);
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab13 =new QLabel(tr("Result:"));
lab13->setFont(myTabFont);
2024-07-08 10:34:47 +02:00
myLayout->addWidget(lab13,5,0);
2023-11-14 09:32:56 +01:00
myTabFont.setPixelSize(PIXELSIZE_BIGFONT);
showPrnResult =new QLabel(tr(" "));
showPrnResult->setFont(myTabFont);
showPrnResult->setFrameStyle(1);
2024-07-08 10:34:47 +02:00
myLayout->addWidget(showPrnResult,5,1);
// Anzeige: DC-connection
labState =new QLabel(tr("------------")); // datenverkehr läuft
labState->setFont(myTabFont);
labState->setFrameStyle(1);
myLayout->addWidget(labState,5,2);
QLabel *lab32 = new QLabel(" ");
myLayout->addWidget(lab32,6,0);
2023-11-14 09:32:56 +01:00
// myTabFont.setPixelSize(14);
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab16 =new QLabel(tr("Signals:"));
lab16->setFont(myTabFont);
2024-07-08 10:34:47 +02:00
myLayout->addWidget(lab16,7,0);
2023-11-14 09:32:56 +01:00
myTabFont.setPixelSize(PIXELSIZE_DATA);
labSignal =new QLabel(tr(" "));
labSignal->setFont(myTabFont);
labSignal->setFrameStyle(1);
2024-07-08 10:34:47 +02:00
myLayout->addWidget(labSignal,7,1);
2023-11-14 09:32:56 +01:00
2024-07-08 10:34:47 +02:00
cb_kombiNr = new QComboBox();
myLayout->addWidget(cb_kombiNr,7,2);
for (nn=1; nn<=8; nn++)
cb_kombiNr->addItem(swl_int2str(nn));
cb_kombiNr->setFont(myTabFont);
cb_kombiNr->setCurrentIndex(0);
cb_kombiNr->setMaxVisibleItems(5);
// cb_kombiNr->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
// cb_kombiNr->view()->setVerticalScrollBar(QScrollBar::setMinimumWidth(20));
//cb_kombiNr->view()->setVerticalScrollBar()->setMinimumWidth(20);
cb_kombiNr->setStyleSheet("QScrollBar::vertical { width: 30px; }"); // geht :))
// cb_kombiNr->setStyleSheet(QComboBox::downarrow {width: 30px; });
//cb_kombiNr->adjustSize();
2023-11-14 09:32:56 +01:00
2024-07-08 10:34:47 +02:00
QPushButton *butPrint6 = new QPushButton(" print\ncombi");
myLayout->addWidget(butPrint6,7,3);
connect(butPrint6, SIGNAL(clicked()), this, SLOT(slot_printCombi()));
2023-11-14 09:32:56 +01:00
2024-07-08 10:34:47 +02:00
QLabel *lab33 = new QLabel(" ");
myLayout->addWidget(lab33,8,0);
2023-11-14 09:32:56 +01:00
QPushButton *butPrint3 = new QPushButton("print \nLogo");
myLayout->addWidget(butPrint3,19,0);
connect(butPrint3, SIGNAL(clicked()), this, SLOT(slot_printLogo()));
QPushButton *butPrint4 = new QPushButton("print \nAcc.Bill");
myLayout->addWidget(butPrint4,19,1);
connect(butPrint4, SIGNAL(clicked()), this, SLOT(slot_printAcc()));
QPushButton *butPrintTicket = new QPushButton("print \nTicket");
myLayout->addWidget(butPrintTicket,19,2);
connect(butPrintTicket, SIGNAL(clicked()), this, SLOT(slot_printTicket()));
QPushButton *butPrint5 = new QPushButton(" CUT \n");
myLayout->addWidget(butPrint5,19,3);
connect(butPrint5, SIGNAL(clicked()), this, SLOT(slot_printCut()));
2024-07-08 10:34:47 +02:00
QLabel *lab34 = new QLabel(" ");
myLayout->addWidget(lab34,20,0);
2023-11-14 09:32:56 +01:00
2024-07-08 10:34:47 +02:00
QPushButton *butPrint20 = new QPushButton("Print QR\n");
myLayout->addWidget(butPrint20,22,0);
connect(butPrint20, SIGNAL(clicked()), this, SLOT(slot_printQr()));
QPushButton *butPrint30 = new QPushButton("Print Text\n");
myLayout->addWidget(butPrint30,22,1);
connect(butPrint30, SIGNAL(clicked()), this, SLOT(slot_sendText()));
2023-11-14 09:32:56 +01:00
QPushButton *butPrint12 = new QPushButton("Move \n Paper");
myLayout->addWidget(butPrint12,22,2);
connect(butPrint12, SIGNAL(clicked()), this, SLOT(slot_movPap()));
QPushButton *butPrint15 = new QPushButton("Paper \n back");
myLayout->addWidget(butPrint15,22,3);
connect(butPrint15, SIGNAL(clicked()), this, SLOT(slot_movBack()));
2024-07-08 10:34:47 +02:00
/*
2023-11-14 09:32:56 +01:00
QPushButton *butPrint13 = new QPushButton(" set \nFonts");
myLayout->addWidget(butPrint13,23,1);
connect(butPrint13, SIGNAL(clicked()), this, SLOT(slot_fonts()));
QPushButton *butPrint14 = new QPushButton(" set \nLetters");
myLayout->addWidget(butPrint14,23,2);
connect(butPrint14, SIGNAL(clicked()), this, SLOT(slot_letters()));
2024-07-08 10:34:47 +02:00
*/
2023-11-14 09:32:56 +01:00
setLayout(myLayout);
myNextStep=0;
myStep=0;
myTO = new QTimer();
myTO->setSingleShot(true);
myTO->start(1000);
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_templatePrintFinished_OK()), this, SLOT(signalPrnDone()));
connect( dynamic_cast<QObject*>(HWaccess), SIGNAL(hwapi_templatePrintFinished_Err()), this, SLOT(signalPrnErr()));
HWaccess->prn_switchPower(0);
dummyText.clear();
2024-07-08 10:34:47 +02:00
2023-11-14 09:32:56 +01:00
dummyText.append(" Quod equidem non reprehendo; Lorem ipsum dolor sit amet, consectetur adipiscing elit. ");
dummyText.append(" Quibus natura iure responderit non esse verum aliunde finem beate vivendi, ");
dummyText.append(" a se principia rei gerendae peti; Quae enim adhuc protulisti, popularia sunt, ");
dummyText.append(" ego autem a te elegantiora desidero. Duo Reges: constructio interrete. ");
dummyText.append("Tum Lucius: Mihi vero ista valde probata sunt, quod item fratri puto. ");
dummyText.append("Bestiarum vero nullum iudicium puto. Nihil enim iam habes, quod ad corpus referas; ");
dummyText.append("Deinde prima illa, quae in congressu solemus: Quid tu, inquit, huc? Et homini, qui ");
dummyText.append("ceteris animantibus plurimum praestat, praecipue a natura nihil datum esse dicemus? ");
dummyText.append("Iam id ipsum absurdum, maximum malum neglegi. Quod ea non occurrentia fingunt, vincunt Aristonem; ");
dummyText.append("Atqui perspicuum est hominem e corpore animoque constare, cum primae sint animi partes, ");
dummyText.append("secundae corporis. Fieri, inquam, Triari, nullo pacto potest, ut non dicas, quid non probes eius ");
dummyText.append(" a quo dissentias. Equidem e Cn. An dubium est, quin virtus ita maximam partem optineat ");
dummyText.append("in rebus humanis, ut reliquas obruat? ");
dummyText.append("Summus dolor plures dies manere non potest? Dicet pro me ipsa virtus nec dubitabit isti vestro ");
dummyText.append("beato M. Tubulum fuisse, qua illum, cuius is condemnatus est rogatione, P. Quod si ita sit, cur ");
dummyText.append("opera philosophiae sit danda nescio. valde probata sunt, quod item fratri puto");
dummyText.truncate(1278);
2024-07-08 10:34:47 +02:00
//dummyText.append("abcdefghijklmnopqrstuvwxyz0123ABCDEFGHIJKLMNOPQRSTUVWXYZ4567"); // 60byte
//dummyText.append("abcdefghijklmnopqrstuvwxyz0123ABCDEFGHIJKLMNOPQRSTUVWXYZ4567"); // 60byte
//dummyText.append("abcdefghijklmnopqrstuvwxyz0123ABCDEFGHIJKLMNOPQRSTUVWXYZ4567"); // 60byte
2023-11-14 09:32:56 +01:00
}
T_win06::~T_win06()
{
close();
}
void T_win06::Nav_back(void)
{
myNextStep=WCS_WIN06BAK;
}
void T_win06::Nav_home(void)
{
myNextStep=WCS_WIN06MID;
}
void T_win06::Nav_next(void)
{
myNextStep=WCS_WIN06FWD;
}
void T_win06::slot_sendDD1(void)
{
uint8_t buf[66];
// schicke V1_abcdef V2_ghijkl V3_mnopqr V4_stuvwx\nV5_ABCDEF V6_GHIJKL V7_MNOPQR V8_STUVWX als dyn.Drucker variablen
swl_text2ui8buf("V1_abcdef", &buf[0],8);
swl_text2ui8buf("V2_ghijkl", &buf[8],8);
swl_text2ui8buf("V3_mnopqr", &buf[16],8);
swl_text2ui8buf("V4_stuvwx", &buf[24],8);
swl_text2ui8buf("V5_ABCDEF", &buf[32],8);
swl_text2ui8buf("V6_GHIJKL", &buf[40],8);
swl_text2ui8buf("V7_MNOPQR", &buf[48],8);
swl_text2ui8buf("V8_STUVWX", &buf[56],8);
HWaccess->prn_sendDynamicPrnValues(buf);
}
void T_win06::slot_rdBackDD(void)
{
HWaccess->prn_requestCurrentDynData();
}
void T_win06::slot_printVaris(void)
{
int val=cb_templNr->currentIndex();
val++;
HWaccess->prn_printTemplate(val);
2024-07-08 10:34:47 +02:00
/* test
2023-11-14 09:32:56 +01:00
val++;
HWaccess->prn_printTemplate(val);
val++;
HWaccess->prn_printTemplate(val);
val++;
HWaccess->prn_printTemplate(val);
val++;
HWaccess->prn_printTemplate(val);
val++;
HWaccess->prn_printTemplate(val);
val++;
HWaccess->prn_printTemplate(val);
val++;
HWaccess->prn_printTemplate(val);
2024-07-08 10:34:47 +02:00
*/
2023-11-14 09:32:56 +01:00
}
void T_win06::slot_printCombi(void)
{
int val=cb_kombiNr->currentIndex();
val++;
HWaccess->prn_printKombiticket(val);
}
void T_win06::slot_printTicket(void)
{
// HWaccess->prn_printTemplate(1);
// HWaccess->prn_printTemplate(2);
// HWaccess->prn_printTemplate(3);
HWaccess->prn_printKombiticket(1);
}
void T_win06::slot_sendDD2(void)
{
uint8_t buf[66];
// send V1_000111 V2_000222 V3_000333 V4_000444\nV5_000555 V6_000666 V7_000777 V8_000888
swl_text2ui8buf("V1_000111", &buf[0],8);
swl_text2ui8buf("V2_000222", &buf[8],8);
swl_text2ui8buf("V3_000333", &buf[16],8);
swl_text2ui8buf("V4_000444", &buf[24],8);
swl_text2ui8buf("V5_000555", &buf[32],8);
swl_text2ui8buf("V6_000666", &buf[40],8);
swl_text2ui8buf("V7_000777", &buf[48],8);
swl_text2ui8buf("V8_000888", &buf[56],8);
HWaccess->prn_sendDynamicPrnValues(buf);
}
void T_win06::signalPrnDone(void)
{
labSignal->setText("signal printing finished");
myTO->start(2000);
}
void T_win06::signalPrnErr(void)
{
labSignal->setText("signal printing ERROR");
myTO->start(2000);
}
void T_win06::slot_powerButton(void)
{
if (butPrnPow->isChecked())
{
HWaccess->prn_switchPower(1);
} else
{
HWaccess->prn_switchPower(0);
}
}
void T_win06::slot_printLogo(void)
{
HWaccess->prn_switchPower(1);
HWaccess->prn_printLogo(1,0);
}
void T_win06::slot_printAcc(void)
{
HWaccess->prn_switchPower(1);
HWaccess->prn_printAccountReceipt();
}
void T_win06::slot_printCut(void)
{
HWaccess->prn_switchPower(1);
HWaccess->prn_cut(1);
}
void T_win06::slot_sendText(void)
{
HWaccess->prn_switchPower(1);
2024-07-08 10:34:47 +02:00
uint8_t wayInMm=30;
uint8_t direction=1;
HWaccess->prn_switchPower(1);
HWaccess->prn_movePaper(wayInMm, direction);
//direction: 1=forward 2=backward
//void prn_newLine(uint8_t nrOfLines) const override;
2023-11-14 09:32:56 +01:00
HWaccess->prn_sendText(&dummyText);
// up to 1280 bytes
2024-07-08 10:34:47 +02:00
HWaccess->prn_movePaper(wayInMm, direction);
HWaccess->prn_cut(1);
2023-11-14 09:32:56 +01:00
}
void T_win06::slot_setup(void)
{
uint16_t paperSpeed=240;
uint8_t density=25;
uint8_t alignment='c';
uint8_t orientation=0;
HWaccess->prn_switchPower(1);
HWaccess->prn_sendPrnSetup(paperSpeed, density, alignment, orientation);
// send 5 byte: byte 0,1: speed 5...250 mm/s
// byte2: density 0....(25)....50
// byte3: alignment 'l', 'c', 'r' = left, center, right
// byte4: orientation 0, 90, 180 = 0°, 90°, 180° rotation (by now not supported!)
// not batched! don't use twice within 100ms
}
void T_win06::slot_movPap(void)
{
uint8_t wayInMm=30;
uint8_t direction=1;
HWaccess->prn_switchPower(1);
HWaccess->prn_movePaper(wayInMm, direction);
//direction: 1=forward 2=backward
//void prn_newLine(uint8_t nrOfLines) const override;
}
void T_win06::slot_movBack(void)
{
uint8_t wayInMm=30;
uint8_t direction=2;
HWaccess->prn_switchPower(1);
HWaccess->prn_movePaper(wayInMm, direction);
//direction: 1=forward 2=backward
//void prn_newLine(uint8_t nrOfLines) const override;
}
void T_win06::slot_fonts(void)
{
uint8_t font=10;
uint8_t size=5;
uint8_t width=1;
uint8_t height=2;
HWaccess->prn_switchPower(1);
HWaccess->prn_setFonts(font, size, width, height);
// font = kind of font 5...11 (0..22)
// size = seem to be dots/mm 1..10=nice >15=ugly
// [size = 6...20, 9..9: too tiny 10: small ...12 = normal size ...20=huge] (for some fonts)
// width: 0...4 0=1x 1=2x 2=4x (huge!) 3=8x 4=16x (3,4 make no sense)
// heigth: 0...7 = 1x...8x only 0,1,2,(3) make sense
}
void T_win06::slot_printQr(void)
{
HWaccess->prn_printQRcode();
}
void T_win06::slot_letters(void)
{
uint8_t bold=1;
uint8_t invers=0;
uint8_t underlined=0;
HWaccess->prn_switchPower(1);
HWaccess->prn_setLetters(bold, invers, underlined);
// bold: 0/1
// invers: 0/1
// underlined: 0/1
}
/*
void T_win06::slot_(void)
{
HWaccess->prn_
}
void T_win06::slot_(void)
{
HWaccess->prn_
}
void T_win06::slot_(void)
{
HWaccess->prn_
}
*/
bool T_win06::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;
}
bool T_win06::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"
*nextScreen=0; // 0=no change
*useNavi=0;
QString myStr;
2024-07-08 10:34:47 +02:00
//uint8_t buf[66];
//char ctmp;
2023-11-14 09:32:56 +01:00
uint8_t uctmp;
2024-07-08 10:34:47 +02:00
//bool btmp;
2023-11-14 09:32:56 +01:00
// clear signals after 2s:
if (!myTO->isActive())
labSignal->setText(" ");
uctmp=HWaccess->prn_getCurrentPrinterState();
// 0: printer OK
// bit0: near paper end bit1: no paper
// bit2: temperature error bit3: error head open
// bit4: paper jam in cutter
// bit6: no response bit7: serial rec. error
// bit5: printer not ready
myStr.clear();
myStr.append(QString::number(uctmp));
myStr.append(" ");
if (uctmp&0x80) myStr.append("serial rec.error"); else
if (uctmp&0x40) myStr.append("no response"); else
if (uctmp&0x20) myStr.append("Prn not Ready"); else
if (uctmp&0x10) myStr.append("Paper jam"); else
if (uctmp&0x08) myStr.append("head open"); else
if (uctmp&0x04) myStr.append("too hot"); else
if (uctmp&0x02) myStr.append("no paper"); else
if (uctmp&0x01) myStr.append("near paper end");
showPrnState1->setText(myStr);
//btmp=HWaccess->prn_isUpAndReady(); geht nicht richtig
//if (btmp) // up and ready
if (uctmp<2)
showPrnState1->setStyleSheet("background-color: rgb(150,230,150)"); // hell grün
else
showPrnState1->setStyleSheet("background-color: rgb(250,150,150)"); // hell rot
uctmp=HWaccess->prn_getPrintResult();
// return: 0: unknown
// 1: OK - last template was printed succesful
// 2: error - last template was not printed
myStr.clear();
myStr.append(QString::number(uctmp));
myStr.append(" ");
if (uctmp==1) myStr.append("- OK"); else
if (uctmp==2) myStr.append("- error"); else
if (uctmp==3) myStr.append("- 3"); else
myStr.append("- unknown");
showPrnResult->setText(myStr);
uctmp=HWaccess->cash_getLowPaperSensor();
// 0: Sensor sees paper 1: no paper 99: off
if (uctmp==0)
lab15->setStyleSheet("background-color: rgb(150,230,150)"); // hell grün
else if (uctmp==1)
lab15->setStyleSheet("background-color: yellow");
else
lab15->setStyleSheet("background-color: white");
if (HWaccess->prn_isPrinterPowerOn())
{
if (HWaccess->prn_PrnFuseIsOk()==0)
{
// fuse is blown
butPrnPow->setStyleSheet("background-color: rgb(250,150,150)"); // hell rot
butPrnPow->setText("FUSE blown");
} else
{
// on
butPrnPow->setStyleSheet("background-color: rgb(150,230,150)"); // hell grün
butPrnPow->setText(" O N ");
}
} else
{
butPrnPow->setStyleSheet("background-color: white");
butPrnPow->setText("Power");
}
2024-07-08 10:34:47 +02:00
// update values:
if (HWaccess->sys_areDCdataValid())
{
labState->setText(" DC2 connected "); // datenverkehr läuft
labState->setStyleSheet(COLORGREEN);
} else
{
labState->setText(" no connection\n to DC ");
labState->setStyleSheet(COLORYELLOW);
//qDebug()<<"lost connection to DC";
}
2023-11-14 09:32:56 +01:00
if (myNextStep)
{
*nextScreen=myNextStep;
myNextStep=0;
}
return false;
}