configsteamwashdlg.cpp 4.63 KB
#include "configsteamwashdlg.h"
#include "ui_configsteamwashdlg.h"

#include "udphandler.h"

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

    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_NoSystemBackground);
    setAttribute(Qt::WA_TranslucentBackground);
    setAttribute(Qt::WA_DeleteOnClose);
    setFocus();

    qApp->setActiveWindow(this);

    UdpHandler *udp = UdpHandler::getInstance();
    connect(udp, SIGNAL(changed()), SLOT(onChanged()));

    updateView();
}

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

void ConfigSteamWashDlg::updateView()
{
    switch (phase) {
    case Idle:
        ui->ctrLbBody->setText(tr("시작하시겠습니까?"));
        ui->ctrLbBody->show();
        ui->ctrGauge->hide();
        ui->ctrBtnOk->setGeometry(300, 350, 150, 100);
        ui->ctrBtnOk->show();
        ui->ctrBtnCancel->show();
        break;
    case Starting:
        ui->ctrLbBody->hide();
        ui->ctrGauge->hide();
        ui->ctrBtnOk->hide();
        ui->ctrBtnCancel->hide();
        break;
    case Started:
    {
        UdpHandler *udp = UdpHandler::getInstance();

        oven_control_t control;
        udp->fillControl(control);

        switch (control.clean_step_type)
        {
        case 1:
            ui->ctrLbBody->setText(tr("내부 헹굼 진행 중입니다."));
            break;
        case 2:
            ui->ctrLbBody->setText(tr("스팀 급수 진행 중입니다."));
            break;
        case 3:
            ui->ctrLbBody->setText(tr("내부 팬 세척 진행 중입니다."));
            break;
        case 4:
            ui->ctrLbBody->setText(tr("내부 스팀 불림 진행 중입니다."));
            break;
        case 5:
            ui->ctrLbBody->setText(tr("내부 강 세척 진행 중입니다."));
            break;
        case 6:
            ui->ctrLbBody->setText(tr("내부 상부 세척 진행 중입니다."));
            break;
        case 7:
            ui->ctrLbBody->setText(tr("내부 스팀 세척 진행 중입니다."));
            break;
        case 8:
            ui->ctrLbBody->setText(tr("세척 종료 진행 중입니다."));
            break;
        case 9:
            ui->ctrLbBody->setText(tr("세제 세척수 만들기 진행 중입니다."));
            break;
        case 10:
            ui->ctrLbBody->setText(tr("세제 세척수 헹굼 진행 중입니다."));
            break;
        case 11:
            ui->ctrLbBody->setText(tr("하부 탱크 세척수 만들기 진행 중입니다."));
            break;
        }
        ui->ctrLbBody->show();

        ui->ctrGauge->setMaximum(control.clean_total);
        ui->ctrGauge->setValue(control.clean_step);
        ui->ctrGauge->show();

        ui->ctrBtnOk->hide();
        ui->ctrBtnCancel->hide();
        break;
    }
    case Finished:
        ui->ctrLbBody->setText(tr("세척이 종료되었습니다"));
        ui->ctrLbBody->show();
        ui->ctrGauge->setMaximum(1);
        ui->ctrGauge->setValue(1);
        ui->ctrGauge->show();
        ui->ctrBtnOk->setGeometry(300, 350, 300, 100);
        ui->ctrBtnOk->show();
        ui->ctrBtnCancel->hide();
    }
}

void ConfigSteamWashDlg::onChanged()
{
    switch (phase) {
    case Idle:
        return;
    case Starting:
        if (isStarted())
            phase = Started;
        break;
    case Started:
        if (isFinished())
            phase = Finished;
        break;
    case Finished:
        return;
    }

    updateView();
}

void ConfigSteamWashDlg::start()
{
    UdpHandler *udp = UdpHandler::getInstance();
    udp->set(TG_OVEN_MODE, 2);
    udp->set(TG_CLEAN_TYPE, 6);
    udp->turnOn(TG_CLEANING);

    phase = Starting;

    updateView();
}

bool ConfigSteamWashDlg::isStarted()
{
    UdpHandler *udp = UdpHandler::getInstance();

    oven_control_t control;
    oven_state_t state;
    udp->fillControl(control);
    udp->fillData(state);

    return state.cleaning_sate != 0
            && control.clean_total != 0
            && control.clean_step != 0
            && control.clean_step_type != 0;
}

bool ConfigSteamWashDlg::isFinished()
{
    UdpHandler *udp = UdpHandler::getInstance();

    oven_state_t state;
    udp->fillData(state);

    return state.cleaning_sate == 0;
}

void ConfigSteamWashDlg::on_ctrBtnOk_clicked()
{
    switch (phase) {
    case Idle:
        start();
        break;
    case Finished:
        close();
        break;
    default:
        return;
    }
}

void ConfigSteamWashDlg::on_ctrBtnCancel_clicked()
{
    switch (phase) {
    case Idle:
        close();
        break;
    default:
        return;
    }
}