#include "washwindow.h" #include "ui_washwindow.h" #include #include #include "soundplayer.h" #include "dirtylevel.h" #include "configwindow.h" #include "mainwindow.h" #include "ovenstatics.h" #include "cooldownpopup.h" #include "manualviewerdlg.h" #include "haccp.h" WashWindow::WashWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::WashWindow), selected(false), opened(false), started(false), run(false), canceled(false), type(0) { ui->setupUi(this); ui->clockContainer->setParent(ui->upperStack); ui->progressContainer->setParent(ui->upperStack); setAttribute(Qt::WA_DeleteOnClose); udp = UdpHandler::getInstance(); connect(udp, SIGNAL(changed()), SLOT(onChanged())); ui->animation->load(":/images/animation/wash_04.png"); ui->closeDoorArrow->hide(); QSignalMapper *sm = new QSignalMapper(this); connect(sm, SIGNAL(mapped(int)), SLOT(start(int))); sm->setMapping(ui->washButton_1, 1); sm->setMapping(ui->washButton_2, 2); sm->setMapping(ui->washButton_3, 3); sm->setMapping(ui->washButton_4, 4); sm->setMapping(ui->washButton_5, 5); connect(ui->washButton_1, SIGNAL(clicked()), sm, SLOT(map())); connect(ui->washButton_2, SIGNAL(clicked()), sm, SLOT(map())); connect(ui->washButton_3, SIGNAL(clicked()), sm, SLOT(map())); connect(ui->washButton_4, SIGNAL(clicked()), sm, SLOT(map())); connect(ui->washButton_5, SIGNAL(clicked()), sm, SLOT(map())); returnToClockTimer.setSingleShot(true); returnToClockTimer.setInterval(10 * 1000); connect(&returnToClockTimer, SIGNAL(timeout()), SLOT(returnToClock())); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); updateGauge(); setFocus(); OvenStatistics *os = OvenStatistics::getInstance(); #if ENABLE_WASH_RESUMING if (os->loadWashState()) { // Start Cleaning Steam Generator state = RequestClean; udp->set(TG_OVEN_MODE, 2); udp->set(TG_CLEAN_TYPE, 6); udp->turnOn(TG_CLEANING); ui->animation->clear(); ui->animation->load(":/images/animation/wash_01.png"); ui->animation->load(":/images/animation/wash_02.png"); ui->animation->load(":/images/animation/wash_03.png"); ui->animation->load(":/images/animation/wash_04.png"); ui->animation->show(); ui->animation->start(300); ui->washStepGauge->setValue(0); ui->titleLabel->setText(tr("제품 스팀통을 세척 중입니다")); ui->descLabel->setText(tr("완료될 때까지 문을 열지 마세요\n제품의 스팀통 자동 세척 기능을 실행 중입니다")); ui->washStepTypeLabel->setText(""); ui->washStepCountLabel->setText(""); ui->upperStack->setCurrentIndex(1); } #endif connect(os, SIGNAL(stopClean()), SLOT(stop())); } WashWindow::~WashWindow() { udp->turnOff(TG_CLEANING); delete ui; } void WashWindow::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case 0x01000032: // Turn left onEncoderLeft(); break; case 0x01000031: // Push pushed = focusWidget(); break; case 0x01000030: // Turn right onEncoderRight(); break; } } void WashWindow::keyReleaseEvent(QKeyEvent *event) { switch (event->key()) { case 0x01000032: // Turn left onEncoderLeft(); break; case 0x01000031: // Push if (focusWidget() == pushed) onEncoderClicked(pushed); pushed = NULL; break; case 0x01000030: // Turn right onEncoderRight(); break; } } void WashWindow::start(int type) { if (state != Idle) return; if (type < 1 || type > 5) return; this->type = type; if (udp->getData().sensor1 > 60) { state = CoolDown; lastFocus = focusWidget(); CooldownPopup *p = new CooldownPopup(this, 60); p->setWindowModality(Qt::WindowModal); p->showFullScreen(); connect(p, SIGNAL(destroyed(QObject*)), SLOT(resume())); } else { state = OpenDoor; returnToClockTimer.stop(); showOpenDoor(); } } void WashWindow::resume() { if (lastFocus) { lastFocus->setFocus(); lastFocus = NULL; } if (udp->getData().door_state) { state = CloseDoor; showCloseDoor(); } else { state = Request; request(); } } void WashWindow::stop() { if (state != Request && state != Running) return; state = Stopping; udp->turnOff(TG_CLEANING); } void WashWindow::returnToClock() { ui->upperStack->setCurrentIndex(0); } void WashWindow::updateGauge() { ui->dirtySlider->setValue(DirtyLevel::dirty()); ui->stateSlider->setValue(DirtyLevel::state()); } void WashWindow::updateView() { const oven_control_t &control = udp->getControl(); if (control.clean_total != 0 && control.clean_step != 0 && control.clean_step_type != 0) { ui->washStepGauge->setMaximum(control.clean_total); ui->washStepGauge->setValue(control.clean_step); ui->washStepCountLabel->setText(QString().sprintf("%d/%d", control.clean_step, control.clean_total)); #if MODEL_GRADE != 2 switch (control.clean_step_type) { case 1: ui->washStepTypeLabel->setText(tr("내부 헹굼 진행 중입니다.")); break; case 2: ui->washStepTypeLabel->setText(tr("스팀 급수 진행 중입니다.")); break; case 3: ui->washStepTypeLabel->setText(tr("내부 팬 세척 진행 중입니다.")); break; case 4: ui->washStepTypeLabel->setText(tr("내부 스팀 불림 진행 중입니다.")); break; case 5: ui->washStepTypeLabel->setText(tr("내부 강 세척 진행 중입니다.")); break; case 6: ui->washStepTypeLabel->setText(tr("내부 상부 세척 진행 중입니다.")); break; case 7: ui->washStepTypeLabel->setText(tr("내부 스팀 세척 진행 중입니다.")); break; case 8: ui->washStepTypeLabel->setText(tr("세척 종료 진행 중입니다.")); break; case 9: ui->washStepTypeLabel->setText(tr("세제 세척수 만들기 진행 중입니다.")); break; case 10: ui->washStepTypeLabel->setText(tr("세제 세척수 헹굼 진행 중입니다.")); break; case 11: ui->washStepTypeLabel->setText(tr("하부 탱크 세척수 만들기 진행 중입니다.")); break; } #else switch (control.clean_step_type) { case 1: ui->washStepTypeLabel->setText(tr("내부 헹굼 진행 중입니다.")); break; case 2: ui->washStepTypeLabel->setText(tr("내부 팬 세척 진행 중입니다.")); break; case 3: ui->washStepTypeLabel->setText(tr("내부 스팀 불림 진행 중입니다.")); break; case 4: ui->washStepTypeLabel->setText(tr("내부 강 세척 진행 중입니다.")); break; case 5: ui->washStepTypeLabel->setText(tr("내부 상부 세척 진행 중입니다.")); break; case 6: ui->washStepTypeLabel->setText(tr("세제 세척 헹굼 중입니다.")); break; case 7: ui->washStepTypeLabel->setText(tr("세척 헹굼수 만드는 중입니다.")); break; case 8: ui->washStepTypeLabel->setText(tr("세척 건조 진행 중입니다.")); break; case 9: ui->washStepTypeLabel->setText(tr("세제 투입 진행 중입니다.")); break; case 10: ui->washStepTypeLabel->setText(tr("세척 진행 중입니다.")); break; case 11: ui->washStepTypeLabel->setText(tr("세척 진행 중입니다.")); break; } #endif } switch (state) { case Idle: case CoolDown: showIdle(); break; case OpenDoor: if (udp->getData().door_state == 0) showOpenDoor(); break; case CloseDoor: case Request: case Running: case Stopping: case RequestClean: case RunningClean: if (udp->getData().door_state != 0) showCloseDoor(); else showWash(); break; } } void WashWindow::showIdle() { if (animationState == Stopped) return; animationState = Stopped; ui->animation->stop(); ui->animation->clear(); ui->animation->load(":/images/animation/wash_04.png"); } void WashWindow::showOpenDoor() { if (animationState == ShowingOpenDoor) return; animationState = ShowingOpenDoor; ui->animation->clear(); ui->animation->load(":/images/animation/pull_01.png"); ui->animation->load(":/images/animation/pull_02.png"); ui->animation->load(":/images/animation/pull_03.png"); ui->animation->load(":/images/animation/pull_04.png"); ui->animation->show(); ui->animation->start(300); ui->closeDoorArrow->hide(); } void WashWindow::showCloseDoor() { if (animationState == ShowingCloseDoor) return; animationState = ShowingCloseDoor; ui->animation->clear(); ui->animation->load(":/images/animation/door_big_09.png"); ui->animation->load(":/images/animation/door_big_08.png"); ui->animation->load(":/images/animation/door_big_07.png"); ui->animation->load(":/images/animation/door_big_06.png"); ui->animation->load(":/images/animation/door_big_05.png"); ui->animation->load(":/images/animation/door_big_04.png"); ui->animation->load(":/images/animation/door_big_03.png"); ui->animation->load(":/images/animation/door_big_02.png"); ui->animation->load(":/images/animation/door_big_01.png"); ui->animation->show(); ui->animation->start(300); ui->closeDoorArrow->show(); } void WashWindow::showWash() { if (animationState == ShowingWash) return; animationState = ShowingWash; ui->animation->clear(); ui->animation->load(":/images/animation/wash_01.png"); ui->animation->load(":/images/animation/wash_02.png"); ui->animation->load(":/images/animation/wash_03.png"); ui->animation->load(":/images/animation/wash_04.png"); ui->animation->show(); ui->animation->start(300); ui->closeDoorArrow->hide(); } void WashWindow::request() { udp->set(TG_OVEN_MODE, 2); udp->set(TG_CLEAN_TYPE, type); udp->turnOn(TG_CLEANING); OvenStatistics::getInstance()->setWashState(true); SoundPlayer::playStart(); showWash(); ui->washStepGauge->setValue(0); ui->titleLabel->setText(tr("기기의 내부를 세척 중입니다")); ui->descLabel->setText(tr("완료될 때까지 문을 열지 마세요.\n제품 내부의 자동 세척 기능을 실행 중입니다.")); ui->washStepTypeLabel->setText(""); ui->washStepCountLabel->setText(""); ui->upperStack->setCurrentIndex(1); } void WashWindow::onChanged() { if (state == Idle) return; switch (state) { case Idle: case CoolDown: return; case OpenDoor: if (udp->getData().door_state) { state = CloseDoor; showCloseDoor(); } break; case CloseDoor: if (!udp->getData().door_state) { state = Request; request(); } break; case Request: if (udp->getData().cleaning_sate) { state = Running; HACCP::washStart(type); updateView(); } else updateView(); break; case Running: if (udp->getData().cleaning_sate) { updateView(); } else { state = Idle; HACCP::done(); SoundPlayer::playStop(); DirtyLevel::wash(type); OvenStatistics::getInstance()->setWashState(false); ui->titleLabel->setText(tr("세척이 종료되었습니다")); ui->descLabel->setText(""); ui->washStepTypeLabel->setText(""); ui->washStepCountLabel->setText(""); ui->animation->stop(); ui->animation->clear(); ui->animation->load(":/images/animation/wash_04.png"); returnToClockTimer.start(); updateGauge(); } break; case Stopping: if (!udp->getData().cleaning_sate) { HACCP::done(); SoundPlayer::playStop(); OvenStatistics::getInstance()->setWashState(false); close(); } else updateView(); break; case RequestClean: if (udp->getData().cleaning_sate) { state = RunningClean; HACCP::washStart(6); updateView(); } else updateView(); break; case RunningClean: if (udp->getData().cleaning_sate) { updateView(); } else { state = Idle; HACCP::done(); SoundPlayer::playStop(); OvenStatistics::getInstance()->setWashState(false); ui->titleLabel->setText(tr("세척이 종료되었습니다")); ui->descLabel->setText(""); ui->washStepTypeLabel->setText(""); ui->washStepCountLabel->setText(""); ui->animation->stop(); ui->animation->clear(); ui->animation->load(":/images/animation/wash_04.png"); returnToClockTimer.start(); } } } void WashWindow::on_backButton_clicked() { switch (state) { case Idle: case OpenDoor: case CloseDoor: close(); break; case Request: case Running: stop(); break; case CoolDown: case Stopping: case RequestClean: case RunningClean: return; } } void WashWindow::on_configButton_clicked() { switch (state) { case Idle: case OpenDoor: case CloseDoor: { ConfigWindow *w = new ConfigWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); MainWindow::jump(w); break; } case Request: case Running: stop(); break; case CoolDown: case Stopping: case RequestClean: case RunningClean: return; } } void WashWindow::on_helpButton_clicked() { ManualViewerDlg* dlg = new ManualViewerDlg(this); dlg->showFullScreen(); dlg->raise(); } void WashWindow::onEncoderLeft() { focusPreviousChild(); } void WashWindow::onEncoderRight() { focusNextChild(); } void WashWindow::onEncoderClicked(QWidget *clicked) { QPushButton *b = qobject_cast(clicked); if (b) b->click(); }