#include "componenttestwindow.h" #include "ui_componenttestwindow.h" #include #include "soundplayer.h" ComponentTestWindow::ComponentTestWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::ComponentTestWindow) { ui->setupUi(this); ui->clockContainer->setParent(ui->upperStack); setAttribute(Qt::WA_DeleteOnClose); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); udp = UdpHandler::getInstance(); connect(udp, SIGNAL(changed()), this, SLOT(onDataChanged())); damperTimer.setInterval(10 * 1000); connect(&damperTimer, SIGNAL(timeout()), this, SLOT(damperOff())); udp->set(TG_OVEN_MODE, 4); udp->turnOn(TG_MANUAL_RELAY); onDataChanged(); } ComponentTestWindow::~ComponentTestWindow() { delete ui; } void ComponentTestWindow::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case 0x01000030: // Turn left onEncoderLeft(); break; case 0x01000031: // Push pushed = focusWidget(); break; case 0x01000032: // Turn right onEncoderRight(); break; } } void ComponentTestWindow::keyReleaseEvent(QKeyEvent *event) { switch (event->key()) { case 0x01000030: // Turn left onEncoderLeft(); break; case 0x01000031: // Push if (focusWidget() == pushed) onEncoderClicked(pushed); pushed = NULL; break; case 0x01000032: // Turn right onEncoderRight(); break; } } void ComponentTestWindow::onDataChanged() { if (udp->hl()) ui->lampButton->setText("OFF"); else ui->lampButton->setText("ON"); if (udp->hdm()) ui->damperButton->setText("STOP"); else ui->damperButton->setText("START"); } void ComponentTestWindow::on_speakerButton_clicked() { } void ComponentTestWindow::on_lampButton_clicked() { if (udp->hl()) lampOff(); else lampOn(); } void ComponentTestWindow::on_damperButton_clicked() { if (udp->hdm()) { damperTimer.stop(); damperOff(); } else { damperTimer.start(); damperOn(); } } void ComponentTestWindow::on_backButton_clicked() { damperTimer.stop(); udp->turnOff(TG_HL); udp->turnOff(TG_HDM); udp->turnOff(TG_MANUAL_RELAY); close(); } void ComponentTestWindow::onEncoderLeft() { focusPreviousChild(); } void ComponentTestWindow::onEncoderRight() { focusNextChild(); } void ComponentTestWindow::onEncoderClicked(QWidget *clicked) { QPushButton *b = qobject_cast(clicked); if (b) b->click(); } void ComponentTestWindow::lampOn() { udp->turnOn(TG_HL); } void ComponentTestWindow::lampOff() { udp->turnOff(TG_HL); } void ComponentTestWindow::damperOn() { udp->turnOn(TG_HDM); } void ComponentTestWindow::damperOff() { udp->turnOff(TG_HDM); }