From d66d7f5b443cd02409863597861746bad5822987 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 27 Mar 2017 20:09:27 +0900 Subject: [PATCH] =?UTF-8?q?GUI=20=EB=B2=84=EC=A0=84=200.1.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/gui/oven_control/autocookselectionwindow.cpp | 14 ++++++- app/gui/oven_control/autocookselectionwindow.h | 2 + app/gui/oven_control/autocookwindow.cpp | 49 ++++++++++++++++++------ app/gui/oven_control/cook.cpp | 2 +- app/gui/oven_control/mainwindow.ui | 2 +- app/gui/oven_control/ovencontroller.cpp | 15 +++++++- app/gui/oven_control/udphandler.cpp | 4 +- 7 files changed, 70 insertions(+), 18 deletions(-) diff --git a/app/gui/oven_control/autocookselectionwindow.cpp b/app/gui/oven_control/autocookselectionwindow.cpp index 872d74d..f44e88e 100644 --- a/app/gui/oven_control/autocookselectionwindow.cpp +++ b/app/gui/oven_control/autocookselectionwindow.cpp @@ -8,7 +8,7 @@ AutoCookSelectionWindow::AutoCookSelectionWindow(QWidget *parent, Oven *oven, Cook::CookType type) : QMainWindow(parent), ui(new Ui::AutoCookSelectionWindow), - oven(oven), type(type) + oven(oven), type(type), autoCookWindowOpened(false) { ui->setupUi(this); @@ -47,7 +47,6 @@ AutoCookSelectionWindow::AutoCookSelectionWindow(QWidget *parent, Oven *oven, Co for (int idx = 0; idx < cookList.size(); idx++) { - // TODO: make pushbuttons, map buttons to index, int x = 12 + (idx % 3) * 294; int y = 615 + (idx / 3) * 80; @@ -72,8 +71,19 @@ AutoCookSelectionWindow::~AutoCookSelectionWindow() void AutoCookSelectionWindow::onCookSelected(int idx) { + if (autoCookWindowOpened) + return; + + autoCookWindowOpened = true; + AutoCookWindow *w = new AutoCookWindow(this, oven, cookList.at(idx)); w->showFullScreen(); + connect(w, SIGNAL(destroyed(QObject*)), SLOT(onAutoCookWindowDestroyed())); +} + +void AutoCookSelectionWindow::onAutoCookWindowDestroyed() +{ + autoCookWindowOpened = false; } void AutoCookSelectionWindow::on_backButton_clicked() diff --git a/app/gui/oven_control/autocookselectionwindow.h b/app/gui/oven_control/autocookselectionwindow.h index 086a063..93190cc 100644 --- a/app/gui/oven_control/autocookselectionwindow.h +++ b/app/gui/oven_control/autocookselectionwindow.h @@ -20,6 +20,7 @@ public: private slots: void onCookSelected(int idx); + void onAutoCookWindowDestroyed(); void on_backButton_clicked(); @@ -28,6 +29,7 @@ private: Oven *oven; Cook::CookType type; QList cookList; + bool autoCookWindowOpened; }; #endif // AUTOCOOKSELECTIONWINDOW_H diff --git a/app/gui/oven_control/autocookwindow.cpp b/app/gui/oven_control/autocookwindow.cpp index 40438aa..bc94925 100644 --- a/app/gui/oven_control/autocookwindow.cpp +++ b/app/gui/oven_control/autocookwindow.cpp @@ -32,8 +32,6 @@ AutoCookWindow::AutoCookWindow(QWidget *parent, Oven *oven, AbstractCook *cook) cookStartTimer->setInterval(3000); connect(cookStartTimer, SIGNAL(timeout()), SLOT(start())); - cookStartTimer->start(); - connect(ui->configButton_1, SIGNAL(pressed()), SIGNAL(stopCookStartTimer())); connect(ui->configButton_2, SIGNAL(pressed()), SIGNAL(stopCookStartTimer())); connect(ui->configButton_3, SIGNAL(pressed()), SIGNAL(stopCookStartTimer())); @@ -97,6 +95,8 @@ AutoCookWindow::AutoCookWindow(QWidget *parent, Oven *oven, AbstractCook *cook) connect(&showCurrentTempTimer, SIGNAL(timeout()), SLOT(showCurrentTemp())); setupUi(); + + cookStartTimer->start(); } AutoCookWindow::~AutoCookWindow() @@ -248,6 +248,7 @@ void AutoCookWindow::setupUi() void AutoCookWindow::updateView() { + qDebug() << "updateView"; if (started) { ui->stackedWidget->setCurrentIndex(1); @@ -345,6 +346,7 @@ void AutoCookWindow::updateView() void AutoCookWindow::viewStep(Cook::Step step) { + qDebug() << "viewStep" << step.type; switch (Cook::classify(step.type)) { case Cook::PreheatClass: @@ -403,6 +405,7 @@ void AutoCookWindow::viewPreheatStep(Cook::Step step) void AutoCookWindow::viewDoorStep(Cook::Step step) { + qDebug() << "viewDoorStep"; ui->cookStepLabel->hide(); ui->cookStepIcon->hide(); ui->doorStepLabel->show(); @@ -521,11 +524,9 @@ void AutoCookWindow::doCookStep(Cook::Step step) static bool checkReached(int target, int last, int current) { - if (target == current) - return true; - - return ((target > last) && (target <= current)) - || ((target < last) && (target >= current)); + qDebug() << "checkReached" << target << last << current; + return ((target >= last) && (target <= current)) + || ((target <= last) && (target >= current)); } void AutoCookWindow::checkPreheatStep(Cook::Step step) @@ -533,6 +534,9 @@ void AutoCookWindow::checkPreheatStep(Cook::Step step) if (/*checkReached(step.humidity, lastHumidity, oven->currentHumidity()) && */checkReached(step.temp, lastTemp, oven->currentTemp())) { + if (selectedStepIndex == cook->currentStepIndex()) + selectedStepIndex = cook->currentStepIndex() + 1; + cook->setCurrentStepIndex(cook->currentStepIndex() + 1); doStep(); } @@ -540,13 +544,23 @@ void AutoCookWindow::checkPreheatStep(Cook::Step step) void AutoCookWindow::checkDoorStep(Cook::Step /*step*/) { - if (opened && !oven->door()) + qDebug() << "checkDoorStep" << opened << oven->door(); + if (opened) { - cook->setCurrentStepIndex(cook->currentStepIndex() + 1); - doStep(); + if (!oven->door()) + { + if (selectedStepIndex == cook->currentStepIndex()) + selectedStepIndex = cook->currentStepIndex() + 1; + + cook->setCurrentStepIndex(cook->currentStepIndex() + 1); + doStep(); + } + } + else + { + if (oven->door()) + opened = true; } - else if (!opened && oven->door()) - opened = true; } void AutoCookWindow::checkCookStep(Cook::Step step) @@ -556,6 +570,9 @@ void AutoCookWindow::checkCookStep(Cook::Step step) if (/*checkReached(step.humidity, lastHumidity, oven->currentHumidity()) && */checkReached(step.temp, lastTemp, oven->currentTemp())) { + if (selectedStepIndex == cook->currentStepIndex()) + selectedStepIndex = cook->currentStepIndex() + 1; + cook->setCurrentStepIndex(cook->currentStepIndex() + 1); doStep(); } @@ -563,6 +580,9 @@ void AutoCookWindow::checkCookStep(Cook::Step step) { if (cook->interTemp() == oven->currentInterTemp()) { + if (selectedStepIndex == cook->currentStepIndex()) + selectedStepIndex = cook->stepCount() - 1; + cook->setCurrentStepIndex(cook->stepCount() - 1); doStep(); } @@ -572,6 +592,8 @@ void AutoCookWindow::checkCookStep(Cook::Step step) void AutoCookWindow::start() { + qDebug() << "start"; + started = true; oven->setTime(cook->time()); oven->setInterTempEnabled(interTempEnabled); @@ -585,6 +607,7 @@ void AutoCookWindow::start() void AutoCookWindow::stop() { + qDebug() << "stop"; oven->stop(); checkCookTimer.stop(); @@ -593,6 +616,7 @@ void AutoCookWindow::stop() void AutoCookWindow::doStep() { + qDebug() << "doStep"; Cook::Step step = cook->currentStep(); switch (Cook::classify(step.type)) { @@ -612,6 +636,7 @@ void AutoCookWindow::doStep() void AutoCookWindow::checkCook() { + qDebug() << "checkCook"; Cook::Step step = cook->currentStep(); switch (Cook::classify(step.type)) { diff --git a/app/gui/oven_control/cook.cpp b/app/gui/oven_control/cook.cpp index 9619111..b0b0c48 100644 --- a/app/gui/oven_control/cook.cpp +++ b/app/gui/oven_control/cook.cpp @@ -62,7 +62,7 @@ int AbstractCook::currentStepIndex() void AbstractCook::setCurrentStepIndex(int index) { - if (index < stepCount_) + if (index < stepCount_ && index >= 0) currentStep_ = index; } diff --git a/app/gui/oven_control/mainwindow.ui b/app/gui/oven_control/mainwindow.ui index 8250add..3c1ce5e 100644 --- a/app/gui/oven_control/mainwindow.ui +++ b/app/gui/oven_control/mainwindow.ui @@ -1647,7 +1647,7 @@ QPushButton#primeButton:pressed { - V0.1.1 + V0.1.2 Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing diff --git a/app/gui/oven_control/ovencontroller.cpp b/app/gui/oven_control/ovencontroller.cpp index bb6ca73..bc54740 100644 --- a/app/gui/oven_control/ovencontroller.cpp +++ b/app/gui/oven_control/ovencontroller.cpp @@ -12,8 +12,21 @@ void OvenController::setUdpHandler(UdpHandler *udp) void OvenController::onDataChanged() { + bool opened = state.door_state != 0; + udp->fillControl(control); udp->fillData(state); + + if (opened) + { + if (state.door_state == 0) + emit doorClosed(); + } + else + { + if (state.door_state != 0) + emit doorOpened(); + } } int OvenController::currentTemp() @@ -34,7 +47,7 @@ int OvenController::currentInterTemp() bool OvenController::door() { - return state.door_state; + return state.door_state != 0; } void OvenController::setHumidity(int percentage) diff --git a/app/gui/oven_control/udphandler.cpp b/app/gui/oven_control/udphandler.cpp index f58f4c8..a466d00 100644 --- a/app/gui/oven_control/udphandler.cpp +++ b/app/gui/oven_control/udphandler.cpp @@ -43,18 +43,20 @@ void UdpHandler::readPendingDatagrams() void UdpHandler::processDatagram(QByteArray &datagram) { - qDebug() << "Received"; sock->writeDatagram(datagram, QHostAddress("192.168.4.191"), 4000); packet_t *packet = (packet_t *) datagram.data(); switch (packet->header) { case HDR_OVEN_CONTROL: + qDebug() << "Received Control"; processControl((oven_control_t *) packet->body); break; case HDR_OVEN_STATE: + qDebug() << "Received State"; processState((oven_state_t *) packet->body); break; case HDR_ERROR_CODE: + qDebug() << "Received Error"; break; } } -- 2.1.4