functiontestwindow.cpp 6.26 KB
#include "functiontestwindow.h"
#include "ui_functiontestwindow.h"

#include <QKeyEvent>

#include "burnertestwindow.h"
#include "componenttestwindow.h"
#include "valvetestwindow.h"
#include "washtestwindow.h"
#include "fantestwindow.h"
#include "gastestwindow.h"
#include "soundplayer.h"
#include "config.h"
#include "yesnopopupdlg.h"
#include "notipopupdlg.h"
#include "usbcheckpopupdlg.h"
#include "fileprocessor.h"

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

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

    foreach (QPushButton *button, findChildren<QPushButton *>())
        connect(button, &QPushButton::pressed, SoundPlayer::playClick);

    connect(ui->backButton, SIGNAL(clicked(bool)), SLOT(close()));
}

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

void FunctionTestWindow::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 FunctionTestWindow::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 FunctionTestWindow::on_burnerTestButton_clicked()
{
    BurnerTestWindow *w = new BurnerTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_componentTestButton_clicked()
{
    ComponentTestWindow *w = new ComponentTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_valveTestButton_clicked()
{
    ValveTestWindow *w = new ValveTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_washTestButton_clicked()
{
    WashTestWindow *w = new WashTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_fanTestButton_clicked()
{
    FanTestWindow *w = new FanTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_gasTestButton_clicked()
{
//    GasTestWindow *w = new GasTestWindow(this, udp);
    //    w->showFullScreen();
}

void FunctionTestWindow::onEncoderLeft()
{
    focusPreviousChild();
}

void FunctionTestWindow::onEncoderRight()
{
    focusNextChild();
}

void FunctionTestWindow::onEncoderClicked(QWidget *clicked)
{
    QPushButton *b = qobject_cast<QPushButton *>(clicked);
    if (b)
        b->click();
}

bool FunctionTestWindow::readFromRpmFilea(QMap<QString, uint32_t> &rpm_map, const QString &filename){
    QFile file(filename);
    QString label;
    uint32_t value;

    if(file.open(QIODevice::ReadOnly | QIODevice::Text)){
        while(!file.atEnd()){
            QString line = QString::fromUtf8(file.readLine());
            rpm_map[line.section(',',0,0)] = line.section(',',1,1).toUInt();
        }
        qDebug() << file.fileName() << "read OK!";
        qDebug() << "final size " << rpm_map.size();
        return true;
    }
    else {
        qDebug() << file.fileName() + " file not found";
    }
    return false;

}

void FunctionTestWindow::on_adjustBlowerFan_clicked()
{
    QString strUsbPath;
    Config* cfg = Config::getInstance();
    Define::config_item item;

    YesNoPopupDlg* yesDlg = new YesNoPopupDlg(this,tr("RPM 설정을 바꾸시겠습니까?"));
    yesDlg->exec();
    if(yesDlg->result()!=QDialog::Accepted){
        return;
    }


    QMap<QString, uint32_t> rpm_infos;
    rpm_infos["config_burner1_pwr1_normal_rpm"] = 4000;
    rpm_infos["config_burner1_pwr2_normal_rpm"] = 6000;
    rpm_infos["config_burner23_pwr1_normal_rpm"] = 2300;
    rpm_infos["config_burner23_pwr2_normal_rpm"] = 6500;
    rpm_infos["config_burner1_pwr1_half_rpm"] = 4000;
    rpm_infos["config_burner1_pwr2_half_rpm"] = 4500;
    rpm_infos["config_burner23_pwr1_half_rpm"] = 2300;
    rpm_infos["config_burner23_pwr2_half_rpm"] = 4500;

    if(!FileProcessor::detectUSB(strUsbPath)){
        UsbCheckPopupDlg* usbDlg = new UsbCheckPopupDlg(this);
        usbDlg->exec();
        if(usbDlg->result() != QDialog::Accepted){
            NotiPopupDlg* notidlg= new NotiPopupDlg(this,tr("USB 메모리가 인식되지 않았습니다."));
            notidlg->exec();
            return;
        }
    }

    FileProcessor::detectUSB(strUsbPath);



    strUsbPath = QString("%1%2").arg(strUsbPath).arg(QString(RPM_INFO_FILE_NAME));

    if(readFromRpmFilea(rpm_infos,strUsbPath)){

        YesNoPopupDlg* dlg = new YesNoPopupDlg(this, tr("송풍기 교정을 하시겠습니까?"));

        item.d32 = rpm_infos["config_burner1_pwr1_normal_rpm"];
        cfg->setConfigValue(Define::config_burner1_pwr1_normal_rpm, item);

        item.d32 = rpm_infos["config_burner1_pwr2_normal_rpm"];
        cfg->setConfigValue(Define::config_burner1_pwr2_normal_rpm, item);

        item.d32 = rpm_infos["config_burner23_pwr1_normal_rpm"];
        cfg->setConfigValue(Define::config_burner23_pwr1_normal_rpm,item);

        item.d32 = rpm_infos["config_burner23_pwr2_normal_rpm"];
        cfg->setConfigValue(Define::config_burner23_pwr2_normal_rpm,  item);

        item.d32 = rpm_infos["config_burner1_pwr1_half_rpm"];
        cfg->setConfigValue(Define::config_burner1_pwr1_half_rpm,item);

        item.d32 = rpm_infos["config_burner1_pwr2_half_rpm"];
        cfg->setConfigValue(Define::config_burner1_pwr2_half_rpm, item);

        item.d32 = rpm_infos["config_burner23_pwr1_half_rpm"];
        cfg->setConfigValue(Define::config_burner23_pwr1_half_rpm,item);

        item.d32 = rpm_infos["config_burner23_pwr2_half_rpm"];
        cfg->setConfigValue(Define::config_burner23_pwr2_half_rpm,item);

        cfg->saveConfig();
        cfg->applyConfig();

        item = cfg->getConfigValue(Define::config_burner23_pwr2_half_rpm);
        qDebug() << item.d32;

        NotiPopupDlg* notidlg = new NotiPopupDlg(this,tr("적용 되었습니다."));
        notidlg->exec();
    }
    else{
        NotiPopupDlg* notidlg = new NotiPopupDlg(this,tr("설정 파일이 없습니다."));
        notidlg->exec();
    }

}