diff --git a/app/gui/oven_control/mainwindow.cpp b/app/gui/oven_control/mainwindow.cpp index cd049dc..e6801bd 100644 --- a/app/gui/oven_control/mainwindow.cpp +++ b/app/gui/oven_control/mainwindow.cpp @@ -20,7 +20,7 @@ MainWindow::MainWindow(QWidget *parent) : oven = new Oven(this); - OvenController *interface = new OvenController; + OvenController *interface = new OvenController(this, oven); oven->setInterface(interface); udp = new UdpHandler(this); diff --git a/app/gui/oven_control/oven.cpp b/app/gui/oven_control/oven.cpp index 8103cd7..3b936fe 100644 --- a/app/gui/oven_control/oven.cpp +++ b/app/gui/oven_control/oven.cpp @@ -7,6 +7,10 @@ Oven::Oven(QObject *parent) : QObject(parent) { interface = NULL; + currentHumidity_ = 0; + currentTemp_ = 0; + currentInterTemp_ = 0; + cookingTimer.setSingleShot(true); connect(&cookingTimer, SIGNAL(timeout()), this, SLOT(stopCooking())); @@ -83,7 +87,6 @@ void Oven::setDefault(Mode mode) cooldown_ = false; damper_ = false; humidification_ = false; - washing_ = false; door_ = interface->door(); paused_ = false; @@ -285,26 +288,30 @@ void Oven::stop() if (humidification()) stopHumidification(); - - if (washing()) - stopWashing(); } void Oven::startCooking() { - paused_ = false; - if (!cooking()) { - if (preheating()) - stopPreheating(); + if (door()) + { + paused_ = true; + } + else + { + paused_ = false; + + if (preheating()) + stopPreheating(); - if (cooldown()) - stopCooldown(); + if (cooldown()) + stopCooldown(); - cooking_ = true; - cookingTimer.start(); - interface->startCooking(); + cooking_ = true; + cookingTimer.start(); + interface->startCooking(); + } emit changed(this); } @@ -334,6 +341,9 @@ void Oven::startPreheating() { if (preheatingStartable()) { + if (cooking()) + stopCooking(); + preheating_ = true; interface->startPreheating(); @@ -349,6 +359,9 @@ void Oven::stopPreheating() interface->stopPreheating(); emit changed(this); + + if (paused()) + startCooking(); } } @@ -406,26 +419,17 @@ void Oven::stopHumidification() } } -void Oven::startWashing() -{ - -} - -void Oven::stopWashing() -{ - -} - -void Oven::openDamper() +void Oven::openDamper(int secs) { if (!damper()) { damper_ = true; - damperTimer.start(5 * 60 * 1000); interface->openDamper(); emit changed(this); } + + damperTimer.start(secs * 1000); } void Oven::closeDamper() @@ -442,6 +446,33 @@ void Oven::closeDamper() } } +void Oven::setCurrentHumidity(int percentage) +{ + if (currentHumidity() != percentage) + { + currentHumidity_ = percentage; + emit changed(this); + } +} + +void Oven::setCurrentTemp(int celsius) +{ + if (currentTemp() != celsius) + { + currentTemp_ = celsius; + emit changed(this); + } +} + +void Oven::setCurrentInterTemp(int celsius) +{ + if (currentInterTemp() != celsius) + { + currentInterTemp_ = celsius; + emit changed(this); + } +} + @@ -523,7 +554,10 @@ void Oven::onDoorOpened() emit changed(this); if (cooking()) + { stopCooking(); + openDamper(7); + } } void Oven::onDoorClosed() @@ -532,6 +566,9 @@ void Oven::onDoorClosed() emit changed(this); - if (paused()) + if (!cooldown() && paused()) startCooking(); + + if (damper()) + closeDamper(); } diff --git a/app/gui/oven_control/oven.h b/app/gui/oven_control/oven.h index f74cb7c..ce1c10f 100644 --- a/app/gui/oven_control/oven.h +++ b/app/gui/oven_control/oven.h @@ -66,7 +66,10 @@ private: bool damper_ = false; // true: open, false: close bool humidification_ = false; bool door_ = false; // true: open, false: close - bool washing_ = false; + + int currentHumidity_; + int currentTemp_; + int currentInterTemp_; bool paused_; @@ -95,12 +98,11 @@ public: bool damper() { return damper_; } bool humidification() { return humidification_; } bool door() { return door_; } - bool washing() { return washing_; } bool paused() { return paused_; } - int currentTemp() { return interface->currentTemp(); } - int currentHumidity() { return interface->currentHumidity(); } - int currentInterTemp() { return interface->currentInterTemp(); } + int currentTemp() { return currentTemp_; } + int currentHumidity() { return currentHumidity_; } + int currentInterTemp() { return currentInterTemp_; } bool cookingStartable(); bool preheatingStartable(); @@ -139,12 +141,13 @@ public slots: void stopCooldown(); void startHumidification(); void stopHumidification(); - void startWashing(); - void stopWashing(); - void openDamper(); + void openDamper(int secs = 300); void closeDamper(); + void setCurrentHumidity(int percentage); + void setCurrentTemp(int celsius); + void setCurrentInterTemp(int celsius); void setInterface(OvenInterface *interface); diff --git a/app/gui/oven_control/ovencontroller.cpp b/app/gui/oven_control/ovencontroller.cpp index 97e7e09..ebf55b1 100644 --- a/app/gui/oven_control/ovencontroller.cpp +++ b/app/gui/oven_control/ovencontroller.cpp @@ -1,6 +1,7 @@ #include "ovencontroller.h" -OvenController::OvenController(QObject *parent) : OvenInterface(parent) +OvenController::OvenController(QObject *parent, Oven *oven) : OvenInterface(parent), + oven(oven) { bzero(&control, sizeof(control)); bzero(&state, sizeof(state)); @@ -29,6 +30,10 @@ void OvenController::onDataChanged() if (state.door_state != 0) emit doorOpened(); } + + oven->setCurrentHumidity(currentHumidity()); + oven->setCurrentTemp(currentTemp()); + oven->setCurrentInterTemp(currentInterTemp()); } int OvenController::currentTemp() @@ -92,7 +97,7 @@ void OvenController::stopCooking() void OvenController::startPreheating() { - udp->set(TG_OVEN_MODE, 0); + udp->set(TG_OVEN_MODE, 1); udp->set(TG_TIME, 1440); udp->turnOn(TG_SYSTEM); udp->turnOn(TG_PREHEAT); @@ -135,10 +140,10 @@ void OvenController::stopWashing() void OvenController::openDamper() { - + udp->turnOn(TG_OUTHUMIDITY); } void OvenController::closeDamper() { - + udp->turnOff(TG_OUTHUMIDITY); } diff --git a/app/gui/oven_control/ovencontroller.h b/app/gui/oven_control/ovencontroller.h index 6904a4c..d3a2e60 100644 --- a/app/gui/oven_control/ovencontroller.h +++ b/app/gui/oven_control/ovencontroller.h @@ -9,12 +9,13 @@ class OvenController : public OvenInterface { Q_OBJECT + Oven *oven; UdpHandler *udp; oven_control_t control; oven_state_t state; public: - OvenController(QObject *parent = 0); + OvenController(QObject *parent = 0, Oven *oven = 0); void setUdpHandler(UdpHandler *udp); int currentTemp(); diff --git a/app/gui/oven_control/preheatpopup.cpp b/app/gui/oven_control/preheatpopup.cpp index c9a83f1..8d0e278 100644 --- a/app/gui/oven_control/preheatpopup.cpp +++ b/app/gui/oven_control/preheatpopup.cpp @@ -12,7 +12,7 @@ PreheatPopup::PreheatPopup(QWidget *parent, Oven *oven) : setAttribute(Qt::WA_DeleteOnClose); - connect(oven, SIGNAL(changed(Oven*)), SLOT(updateView())); + connect(oven, SIGNAL(changed(Oven*)), SLOT(onOvenChanged())); showCurrentHumidityTimer.setSingleShot(true); showCurrentHumidityTimer.setInterval(3000); @@ -22,6 +22,10 @@ PreheatPopup::PreheatPopup(QWidget *parent, Oven *oven) : showCurrentTempTimer.setInterval(3000); connect(&showCurrentTempTimer, SIGNAL(timeout()), SLOT(showCurrentTemp())); + ui->preheatGauge->setMaximum(oven->temp()); + ui->preheatGauge->setMinimum(oven->currentTemp()); + ui->preheatGauge->setValue(oven->currentTemp()); + start(); } @@ -63,6 +67,8 @@ void PreheatPopup::updateView() ui->humidityLabel->setText(QString().sprintf("%d%%", humidity)); ui->heatLabel->setText(QString().sprintf("%d℃", temp)); + + ui->preheatGauge->setValue(oven->currentTemp()); } void PreheatPopup::start() @@ -89,6 +95,17 @@ void PreheatPopup::showCurrentTemp() updateView(); } +void PreheatPopup::onOvenChanged() +{ + if (oven->currentHumidity() >= oven->humidity() && oven->currentTemp() >= oven->temp()) + { + stop(); + close(); + } + else + updateView(); +} + void PreheatPopup::on_closeButton_clicked() { stop(); diff --git a/app/gui/oven_control/preheatpopup.h b/app/gui/oven_control/preheatpopup.h index 7b54346..6ef43c8 100644 --- a/app/gui/oven_control/preheatpopup.h +++ b/app/gui/oven_control/preheatpopup.h @@ -26,15 +26,14 @@ private slots: void showCurrentHumidity(); void showCurrentTemp(); + void onOvenChanged(); + void on_closeButton_clicked(); void on_closeButton_2_clicked(); void on_humidityGaugeButton_pressed(); - void on_humidityGaugeButton_released(); - void on_heatGaugeButton_pressed(); - void on_heatGaugeButton_released(); private: