adjustmentwindow.cpp 4.27 KB
#include <qdebug.h>
#include "adjustmentwindow.h"
#include "ui_adjustmentwindow.h"
#include "yesnopopupdlg.h"
#include "soundplayer.h"
#include "notipopupdlg.h"
#include "touchtestwindow.h"
#include "dirtylevel.h"

AdjustmentWindow::AdjustmentWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::AdjustmentWindow)
{
    ui->setupUi(this);

    ui->clockContainer->setParent(ui->upperStack);
    setAttribute(Qt::WA_DeleteOnClose);

    foreach (QPushButton *button, findChildren<QPushButton *>())
        connect(button, &QPushButton::pressed, SoundPlayer::playClick);
    m_nCurStep = 0;
    m_bAdjustStarted = false;
    m_tmrOneSec = new QTimer(this);
    connect(m_tmrOneSec, SIGNAL(timeout()), this, SLOT(testTimerFired()));
}

AdjustmentWindow::~AdjustmentWindow()
{
    delete ui;
}

void AdjustmentWindow::on_btnAdjust_clicked()
{
    YesNoPopupDlg* w = new YesNoPopupDlg(this,tr("모든 설정 값을 공장(출고)초기화\n값으로 변경 하시겠습니까?"));
    //w->raise();
    if(m_bAdjustStarted == false){
    UdpHandler* udp = UdpHandler::getInstance();
        int dlgrst = w->exec();
        dlgrst = w->result();
        if(dlgrst == QDialog::Accepted) {
            //Process Init Value;
            qDebug() << "Accepted";
            m_nCurStep = 0;
            m_bAdjustStarted = true;
            m_nSecCnt = 0;
            udp->turnOn(TG_MANUAL_BURNER1);
            udp->turnOn(TG_MANUAL_BURNER2);
            udp->turnOn(TG_MANUAL_BURNER3);
            udp->turnOn(TG_MANUAL_FAN1);
            udp->turnOn(TG_MANUAL_FAN2);
            udp->turnOn(TG_MANUAL_RELAY);
            udp->turnOn(m_arrTestItems[m_nCurStep]);
            m_tmrOneSec->start(1000);
        }
        else qDebug() <<"Rejected";
    }
    else{

    }
}

void AdjustmentWindow::on_backButton_clicked()
{
    UdpHandler* udp = UdpHandler::getInstance();
    if(m_bAdjustStarted){
        m_tmrOneSec->stop();
        udp->turnOff(TG_MANUAL_BURNER1);
        udp->turnOff(TG_MANUAL_BURNER2);
        udp->turnOff(TG_MANUAL_BURNER3);
        udp->turnOff(TG_MANUAL_FAN1);
        udp->turnOff(TG_MANUAL_FAN2);
        udp->turnOff(TG_MANUAL_RELAY);
        m_bAdjustStarted = false;
    }
    close();
}

void AdjustmentWindow::testTimerFired()
{
    int nRestTime = ADJUST_TIME_SEC * MAX_ADJUST_TEST_CNT;
    QString strTemp;
    m_nSecCnt++;
    if((m_nSecCnt%ADJUST_TIME_SEC)==0){
        UdpHandler* udp = UdpHandler::getInstance();
        udp->turnOff(m_arrTestItems[m_nCurStep]);
        m_nCurStep++;
        if(m_nCurStep < MAX_ADJUST_TEST_CNT){
            udp->turnOn(m_nCurStep);
        }
        else{
            //Test Finished
            m_tmrOneSec->stop();
            udp->turnOff(TG_MANUAL_BURNER1);
            udp->turnOff(TG_MANUAL_BURNER2);
            udp->turnOff(TG_MANUAL_BURNER3);
            udp->turnOff(TG_MANUAL_FAN1);
            udp->turnOff(TG_MANUAL_FAN2);
            udp->turnOff(TG_MANUAL_RELAY);
            m_bAdjustStarted = false;
            QDialog* dlg = new NotiPopupDlg(this,tr("테스트를 완료하였습니다."));
            dlg->exec();
        }
    }
    nRestTime = nRestTime - m_nSecCnt;
    strTemp = QString("%1/ %2:%3").arg(m_nCurStep).arg((nRestTime/60),2,10,QLatin1Char('0')).arg((nRestTime%60),2,10,QLatin1Char('0'));
    ui->btnAdjust->setText(strTemp);
}


void AdjustmentWindow::keyPressEvent(QKeyEvent *event){
    switch (event->key())
    {
    case 0x01000032:    // Turn left
        focusPreviousChild();
        break;
    case 0x01000030:    // Turn right
        focusNextChild();
        break;
    }
}

void AdjustmentWindow::keyReleaseEvent(QKeyEvent *event){
    switch (event->key())
    {
    case 0x01000032:    // Turn left
        focusPreviousChild();
        break;
    case 0x01000031:    // Push
    {
        QPushButton *btn = qobject_cast<QPushButton*>(focusWidget());
        if(btn != NULL){
            btn->click();
        }
        break;
    }
    case 0x01000030:    // Turn right
        focusNextChild();
        break;
    }
}

void AdjustmentWindow::on_btnAdjust_LCD_clicked()
{
    TouchTestWindow* wnd = new TouchTestWindow(this);
    wnd->setWindowModality(Qt::WindowModal);
    wnd->show();
    wnd->raise();
}

void AdjustmentWindow::on_btnClearWashData_clicked()
{
    DirtyLevel::setCookingTime(0);
    DirtyLevel::setCookingCount(0);
}