washwindow.cpp 2.28 KB
#include "washwindow.h"
#include "ui_washwindow.h"

#include <QSignalMapper>

WashWindow::WashWindow(QWidget *parent, UdpHandler *udp) :
    QMainWindow(parent),
    ui(new Ui::WashWindow),
    udp(udp),
    started(false)
{
    ui->setupUi(this);

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

    udp->turnOff(TG_SYSTEM);
    connect(udp, SIGNAL(changed()), SLOT(onChanged()));

    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");

    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()));

}

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

void WashWindow::start(int type)
{
    if (started)
        return;

    if (type < 1 || type > 5)
        return;

    started = true;

    udp->set(TG_OVEN_MODE, 2);
    udp->set(TG_CLEAN_TYPE, type);
    udp->turnOn(TG_SYSTEM);
    udp->turnOn(TG_CLEANING);

    ui->upperStack->setCurrentIndex(1);
    ui->animation->start(300);
}

void WashWindow::stop()
{
    udp->turnOff(TG_CLEANING);
}

void WashWindow::onChanged()
{
    if (!started)
        return;

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

    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));
    ui->washStepTypeLabel->setText("세척 공정 진행");
}

void WashWindow::on_backButton_clicked()
{
    stop();
    close();
}