APservice/win03_time.cpp

360 lines
11 KiB
C++
Raw Normal View History

2023-11-14 09:32:56 +01:00
#include "win03_time.h"
struct Trtc_DateTime localTime;
/*
{
uint8_t rtc_hour;
uint8_t rtc_min;
uint8_t rtc_sec;
uint8_t rtc_dayOfMonth;
uint8_t rtc_month;
uint8_t rtc_year;
uint8_t rtc_dayOfWeek;
};
*/
T_win03::T_win03(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
this->HWaccess = HWaccess;
myLayout = new QGridLayout;
QFont myTabFont;
myTabFont.setPixelSize(PIXELSIZE_LABEL);
lab1 =new QLabel(tr("Date / Time"));
lab1->setFont(myTabFont);
myLayout->addWidget(lab1,1,0);
myTabFont.setPixelSize(PIXELSIZE_DATA);
lab2 =new QLabel(tr(" "));
lab2->setFont(myTabFont);
myLayout->addWidget(lab2,2,0);
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab4 =new QLabel(tr("DeviceController"));
lab4->setFont(myTabFont);
myLayout->addWidget(lab4,4,0);
myTabFont.setPixelSize(PIXELSIZE_DATA);
labDate =new QLabel(tr("-"));
labDate->setFont(myTabFont);
myLayout->addWidget(labDate,4,1);
labTime =new QLabel(tr("-"));
labTime->setFont(myTabFont);
myLayout->addWidget(labTime,4,2);
myTabFont.setPixelSize(PIXELSIZE_BUTTONS);
butSetSysTime = new QPushButton("-->PTU");
butSetSysTime->setFont(myTabFont);
myLayout->addWidget(butSetSysTime,4,3);
connect(butSetSysTime, SIGNAL(clicked()), this, SLOT(ButtonTime2sysClicked()));
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab10 =new QLabel(" ");
myLayout->addWidget(lab10,5,0);
QLabel *lab6 =new QLabel(tr("PTU5 / System"));
lab6->setFont(myTabFont);
myLayout->addWidget(lab6,6,0);
myTabFont.setPixelSize(PIXELSIZE_DATA);
labSysDate =new QLabel(tr("-"));
labSysDate->setFont(myTabFont);
myLayout->addWidget(labSysDate,6,1);
labSysTime =new QLabel(tr("-"));
labSysTime->setFont(myTabFont);
myLayout->addWidget(labSysTime,6,2);
systTime = new QTime();
systDate = new QDate();
myTabFont.setPixelSize(PIXELSIZE_BUTTONS);
butSetDCTime = new QPushButton("-->DC");
butSetDCTime->setFont(myTabFont);
myLayout->addWidget(butSetDCTime,6,3);
connect(butSetDCTime, SIGNAL(clicked()), this, SLOT(ButtonTime2dcClicked()));
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab11 =new QLabel(" ");
myLayout->addWidget(lab11,7,0);
QLabel *lab14 =new QLabel("set date/time");
lab14->setFont(myTabFont);
myLayout->addWidget(lab14,8,0);
myTabFont.setPixelSize(22);
chgDate = new QDateEdit();
chgDate->setFont(myTabFont);
chgDate->setMinimumHeight(50);
myLayout->addWidget(chgDate,8,1);
chgTime = new QTimeEdit();
chgTime->setFont(myTabFont);
chgTime->setDisplayFormat("HH:mm:ss");
chgTime->setMinimumHeight(50);
myLayout->addWidget(chgTime,8,2);
myTabFont.setPixelSize(PIXELSIZE_BUTTONS);
butSetManual = new QPushButton("-->DC");
butSetManual->setFont(myTabFont);
myLayout->addWidget(butSetManual,8,3);
connect(butSetManual, SIGNAL(clicked()), this, SLOT(ButtonSetTimeClicked()));
QLabel *lab12 =new QLabel(" ");
myLayout->addWidget(lab12,9,0);
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab16 =new QLabel("DC HW Version:");
lab16->setFont(myTabFont);
myLayout->addWidget(lab16,12,0);
myTabFont.setPixelSize(PIXELSIZE_DATA);
hwVersion1 =new QLabel(" ");
hwVersion1->setFont(myTabFont);
myLayout->addWidget(hwVersion1,12,1);
hwVersion2 =new QLabel(" ");
hwVersion2->setFont(myTabFont);
myLayout->addWidget(hwVersion2,12,2);
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab17 =new QLabel("DC SW Version:");
lab17->setFont(myTabFont);
myLayout->addWidget(lab17,13,0);
myTabFont.setPixelSize(PIXELSIZE_DATA);
swVersion =new QLabel(" ");
swVersion->setFont(myTabFont);
myLayout->addWidget(swVersion,13,1);
myTabFont.setPixelSize(PIXELSIZE_LABEL);
QLabel *lab7 =new QLabel(tr("Battery:"));
lab7->setFont(myTabFont);
myLayout->addWidget(lab7,20,0);
myTabFont.setPixelSize(PIXELSIZE_DATA);
labVolt =new QLabel(tr("-"));
labVolt->setFont(myTabFont);
myLayout->addWidget(labVolt,20,1);
labCelsius =new QLabel(tr("-"));
labCelsius->setFont(myTabFont);
myLayout->addWidget(labCelsius,20,2);
setLayout(myLayout);
myNextStep=0;
myStep=0;
myTO = new QTimer();
myTO->setSingleShot(true);
myTO->start(2000);
}
T_win03::~T_win03()
{
close();
}
void T_win03::Nav_back(void)
{
myNextStep=WCS_WIN03BAK;
}
void T_win03::Nav_home(void)
{
myNextStep=WCS_WIN03MID;
}
void T_win03::Nav_next(void)
{
myNextStep=WCS_WIN03FWD;
// qDebug()<<"fenster1 nav next pressed "<< myNextStep;
}
void T_win03::ButtonTime2sysClicked(void)
{
HWaccess->rtc_getDateTime(&localTime);
if (tslib_plausiChkTime(localTime.rtc_hour, localTime.rtc_min, localTime.rtc_sec) &&
tslib_plausiChkDate(localTime.rtc_year, localTime.rtc_month, localTime.rtc_dayOfMonth))
{
QTime(localTime.rtc_hour, localTime.rtc_min, localTime.rtc_sec);
QDate(localTime.rtc_year, localTime.rtc_month, localTime.rtc_dayOfMonth);
//qDebug()<<"send date/time to PTU ";
//qDebug()<<"date: " << localTime.rtc_year << localTime.rtc_month << localTime.rtc_dayOfMonth << localTime.rtc_dayOfWeek ;
//qDebug()<<"time: " << localTime.rtc_hour << localTime.rtc_min << localTime.rtc_sec;
}
}
void T_win03::ButtonTime2dcClicked(void)
{
2024-07-08 10:34:47 +02:00
/*
2023-11-14 09:32:56 +01:00
localTime.rtc_hour = systTime->currentTime().hour();
localTime.rtc_min = systTime->currentTime().minute();
localTime.rtc_sec = systTime->currentTime().second();
2024-07-08 10:34:47 +02:00
//localTime.rtc_year = uint8_t(systDate->currentDate().year()%100);
localTime.rtc_year = systDate->currentDate().year();
2023-11-14 09:32:56 +01:00
localTime.rtc_month= systDate->currentDate().month();
localTime.rtc_dayOfMonth= systDate->currentDate().day();
//localTime.rtc_dayOfWeek = swl_weekday(systDate->currentDate().year(), systDate->currentDate().month(), systDate->currentDate().day());
localTime.rtc_dayOfWeek = systDate->currentDate().dayOfWeek(); // oder so
2024-07-08 10:34:47 +02:00
qDebug()<<"send date/time to DC ";
qDebug()<<"date: " << localTime.rtc_year << localTime.rtc_month << localTime.rtc_dayOfMonth << localTime.rtc_dayOfWeek ;
qDebug()<<"time: " << localTime.rtc_hour << localTime.rtc_min << localTime.rtc_sec;
HWaccess->rtc_setTimeDateDirect(&localTime);
*/
HWaccess->rtc_setDateTime();
2023-11-14 09:32:56 +01:00
}
void T_win03::ButtonSetTimeClicked(void)
{
QDate myDate;
QTime myTime;
myDate=chgDate->date();
myTime=chgTime->time();
//qDebug()<<"date: " <<myDate<<" myTime: "<<myTime;
localTime.rtc_hour = myTime.hour();
localTime.rtc_min = myTime.minute();
localTime.rtc_sec = myTime.second();
2024-07-08 10:34:47 +02:00
uint16_t val=myDate.year();
val%=100;
localTime.rtc_year = uint8_t(val);
2023-11-14 09:32:56 +01:00
localTime.rtc_month= myDate.month();
localTime.rtc_dayOfMonth= myDate.day();
localTime.rtc_dayOfWeek = myDate.dayOfWeek();
2024-07-08 10:34:47 +02:00
qDebug()<<"send manual date/time to DC ";
qDebug()<<"date: " << localTime.rtc_year << localTime.rtc_month << localTime.rtc_dayOfMonth << localTime.rtc_dayOfWeek ;
qDebug()<<"time: " << localTime.rtc_hour << localTime.rtc_min << localTime.rtc_sec;
2023-11-14 09:32:56 +01:00
HWaccess->rtc_setTimeDateDirect(&localTime);
}
bool T_win03::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_win03::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"
uint8_t nn; //, yl, yh;
char cbuf34[34];
uint8_t buf[64];
uint16_t uitmp;
QString myStr, tmpStr;
int ii, pp=0;
*nextScreen=0; // 0=no change
*useNavi=0;
HWaccess->rtc_getDateTime(&localTime);
if (tslib_plausiChkTime(localTime.rtc_hour, localTime.rtc_min, localTime.rtc_sec) &&
tslib_plausiChkDate(localTime.rtc_year, localTime.rtc_month, localTime.rtc_dayOfMonth))
{
for (nn=0; nn<20; nn++)
cbuf34[nn]=0;
GetTimeString(localTime.rtc_hour, localTime.rtc_min, localTime.rtc_sec, 0, 1, buf);
//void GetTimeString(uint8_t hours, uint8_t minutes, uint8_t seconds, uint8_t System12h, uint8_t ShowSec, uint8_t *buf);
for (nn=0; nn<12; nn++)
cbuf34[nn]=buf[nn];
labTime->setText(cbuf34);
for (nn=0; nn<20; nn++)
cbuf34[nn]=0;
GetDateString(localTime.rtc_dayOfMonth, localTime.rtc_month, 0x20, localTime.rtc_year,0, 0, buf);
// void GetDateString(uint8_t day, uint8_t month, uint8_t yearhigh, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf);
for (nn=0; nn<12; nn++)
cbuf34[nn]=buf[nn];
labDate->setText(cbuf34);
}
for (nn=0; nn<20; nn++)
cbuf34[nn]=0;
GetTimeString(systTime->currentTime().hour(), \
systTime->currentTime().minute(), \
systTime->currentTime().second(), 0, 1, buf);
for (nn=0; nn<12; nn++)
cbuf34[nn]=buf[nn];
labSysTime->setText(cbuf34);
for (nn=0; nn<20; nn++)
cbuf34[nn]=0;
uitmp= systDate->currentDate().year();
tmpStr.clear();
tmpStr.append(QString::number(uitmp));
GetDateString( systDate->currentDate().day(), \
systDate->currentDate().month(), 0, 0, 0, 0, buf);
for (nn=0; nn<12; nn++)
cbuf34[nn]=buf[nn];
cbuf34[6]=tmpStr.at(0).toLatin1();
cbuf34[7]=tmpStr.at(1).toLatin1();
cbuf34[8]=tmpStr.at(2).toLatin1();
cbuf34[9]=tmpStr.at(3).toLatin1();
labSysDate->setText(cbuf34);
// hwVersion1->setText(HWaccess->dc_getHWversion() );
// in 2 Teile zerlegen weil sonst 2.Spalte zu breit
tmpStr.clear();
tmpStr = HWaccess->dc_getHWversion();
for (ii=0; ii<tmpStr.length(); ii++) if (tmpStr.at(ii)==' ') {pp=ii; break; }
// tmpStr.truncate(pp); geht auch, dann muss man tmpStr aber nochmal neu laden
myStr=tmpStr.left(pp);
hwVersion1->setText(myStr);
myStr=tmpStr.right(pp+1);
hwVersion2->setText(myStr);
swVersion->setText(HWaccess->dc_getSWversion() );
labVolt->setText( HWaccess->dc_getVoltagStr());
labCelsius->setText( HWaccess->dc_getTemperaturStr());
if (myNextStep)
{
//qDebug()<<"fenster1 working: "<< myNextStep;
*nextScreen=myNextStep;
myNextStep=0;
}
return false;
}