Commit fd8461350e18ba5f13cbffe10c2112d8c25de065

Authored by 김태훈
1 parent aa40dc8071
Exists in master and in 2 other branches fhd, fhd-demo

오븐 기능 추가 및 수정

- 댐퍼 / 가습 기능 반복 가능하게 추가
 - 중심 온도 유효성 검사 기능 추가
   - 중심 온도가 현재 온도와 20도 이상 3초 이상 차이날 때 유효
 - 싱글톤 오브젝트로 변경
app/gui/oven_control/mainwindow.cpp
@@ -21,7 +21,7 @@ MainWindow::MainWindow(QWidget *parent) : @@ -21,7 +21,7 @@ MainWindow::MainWindow(QWidget *parent) :
21 //for singletone event debug 21 //for singletone event debug
22 pcombiButton = ui->helpButton; 22 pcombiButton = ui->helpButton;
23 23
24 - oven = new Oven(this); 24 + oven = Oven::getInstance();
25 25
26 OvenController *interface = new OvenController(this, oven); 26 OvenController *interface = new OvenController(this, oven);
27 oven->setInterface(interface); 27 oven->setInterface(interface);
@@ -73,27 +73,31 @@ void MainWindow::on_configButton_clicked() @@ -73,27 +73,31 @@ void MainWindow::on_configButton_clicked()
73 FunctionTestWindow *w = new FunctionTestWindow(this, udp); 73 FunctionTestWindow *w = new FunctionTestWindow(this, udp);
74 w->setWindowModality(Qt::WindowModal); 74 w->setWindowModality(Qt::WindowModal);
75 w->showFullScreen(); 75 w->showFullScreen();
  76 + w->raise();
76 } 77 }
77 78
78 void MainWindow::on_poultryButton_clicked() 79 void MainWindow::on_poultryButton_clicked()
79 { 80 {
80 - AutoCookSelectionWindow *w = new AutoCookSelectionWindow(this, oven, Cook::Poultry); 81 + AutoCookSelectionWindow *w = new AutoCookSelectionWindow(this, oven, Define::Poultry);
81 w->setWindowModality(Qt::WindowModal); 82 w->setWindowModality(Qt::WindowModal);
82 w->showFullScreen(); 83 w->showFullScreen();
  84 + w->raise();
83 } 85 }
84 86
85 void MainWindow::on_meatButton_clicked() 87 void MainWindow::on_meatButton_clicked()
86 { 88 {
87 - AutoCookSelectionWindow *w = new AutoCookSelectionWindow(this, oven, Cook::Meat); 89 + AutoCookSelectionWindow *w = new AutoCookSelectionWindow(this, oven, Define::Meat);
88 w->setWindowModality(Qt::WindowModal); 90 w->setWindowModality(Qt::WindowModal);
89 w->showFullScreen(); 91 w->showFullScreen();
  92 + w->raise();
90 } 93 }
91 94
92 void MainWindow::on_breadButton_clicked() 95 void MainWindow::on_breadButton_clicked()
93 { 96 {
94 - AutoCookSelectionWindow *w = new AutoCookSelectionWindow(this, oven, Cook::Bread); 97 + AutoCookSelectionWindow *w = new AutoCookSelectionWindow(this, oven, Define::Bread);
95 w->setWindowModality(Qt::WindowModal); 98 w->setWindowModality(Qt::WindowModal);
96 w->showFullScreen(); 99 w->showFullScreen();
  100 + w->raise();
97 } 101 }
98 102
99 void MainWindow::on_washButton_clicked() 103 void MainWindow::on_washButton_clicked()
@@ -101,4 +105,5 @@ void MainWindow::on_washButton_clicked() @@ -101,4 +105,5 @@ void MainWindow::on_washButton_clicked()
101 WashWindow *w = new WashWindow(this, udp); 105 WashWindow *w = new WashWindow(this, udp);
102 w->setWindowModality(Qt::WindowModal); 106 w->setWindowModality(Qt::WindowModal);
103 w->showFullScreen(); 107 w->showFullScreen();
  108 + w->raise();
104 } 109 }
app/gui/oven_control/oven.cpp
1 #include "oven.h" 1 #include "oven.h"
2 2
3 #include <QtDebug> 3 #include <QtDebug>
  4 +#include <QTime>
4 #include <cmath> 5 #include <cmath>
5 6
  7 +Oven *Oven::instance = 0;
  8 +
6 Oven::Oven(QObject *parent) : QObject(parent) 9 Oven::Oven(QObject *parent) : QObject(parent)
7 { 10 {
8 interface = NULL; 11 interface = NULL;
@@ -12,13 +15,30 @@ Oven::Oven(QObject *parent) : QObject(parent) @@ -12,13 +15,30 @@ Oven::Oven(QObject *parent) : QObject(parent)
12 currentInterTemp_ = 0; 15 currentInterTemp_ = 0;
13 16
14 cookingTimer.setSingleShot(true); 17 cookingTimer.setSingleShot(true);
15 - connect(&cookingTimer, SIGNAL(timeout()), this, SLOT(stopCooking())); 18 + connect(&cookingTimer, SIGNAL(timeout()), SLOT(stopCooking()));
16 19
17 damperTimer.setSingleShot(true); 20 damperTimer.setSingleShot(true);
18 - connect(&damperTimer, SIGNAL(timeout()), this, SLOT(closeDamper())); 21 + connect(&damperTimer, SIGNAL(timeout()), SLOT(closeDamper()));
19 22
20 humidificationTimer.setSingleShot(true); 23 humidificationTimer.setSingleShot(true);
21 - connect(&humidificationTimer, SIGNAL(timeout()), this, SLOT(stopHumidification())); 24 + connect(&humidificationTimer, SIGNAL(timeout()), SLOT(stopHumidification()));
  25 +
  26 + damperRepeatRuntimeTimer.setSingleShot(true);
  27 + connect(&damperRepeatRuntimeTimer, SIGNAL(timeout()), SLOT(idleRepeatDamper()));
  28 +
  29 + damperRepeatDelayTimer.setSingleShot(true);
  30 + connect(&damperRepeatDelayTimer, SIGNAL(timeout()), SLOT(runRepeatDamper()));
  31 +
  32 + humidificationRepeatRuntimeTimer.setSingleShot(true);
  33 + connect(&humidificationRepeatRuntimeTimer, SIGNAL(timeout()), SLOT(idleRepeatHumidification()));
  34 +
  35 + humidificationRepeatDelayTimer.setSingleShot(true);
  36 + connect(&humidificationRepeatDelayTimer, SIGNAL(timeout()), SLOT(runRepeatHumidification()));
  37 +
  38 + isInterTempValid_ = false;
  39 +
  40 + humidificationRepeat = false;
  41 + damperRepeat = false;
22 } 42 }
23 43
24 void Oven::setInterface(OvenInterface *interface) 44 void Oven::setInterface(OvenInterface *interface)
@@ -241,6 +261,11 @@ bool Oven::setFan_(int speed) @@ -241,6 +261,11 @@ bool Oven::setFan_(int speed)
241 return true; 261 return true;
242 } 262 }
243 263
  264 +bool Oven::isInterTempValid()
  265 +{
  266 + return isInterTempValid_ && interTempValidTime.elapsed() > 3000;
  267 +}
  268 +
244 bool Oven::cookingStartable() 269 bool Oven::cookingStartable()
245 { 270 {
246 if (/*door() || */cooking() || time() <= 0) 271 if (/*door() || */cooking() || time() <= 0)
@@ -393,15 +418,22 @@ void Oven::stopCooldown() @@ -393,15 +418,22 @@ void Oven::stopCooldown()
393 } 418 }
394 } 419 }
395 420
396 -void Oven::startHumidification() 421 +void Oven::startHumidification(int secs)
397 { 422 {
398 if (humidificationStartable()) 423 if (humidificationStartable())
399 { 424 {
400 - humidification_ = true;  
401 - humidificationTimer.start(10 * 60 * 1000);  
402 - interface->startHumidification(); 425 + if (humidificationRepeat)
  426 + {
403 427
404 - emit changed(this); 428 + }
  429 + else
  430 + {
  431 + humidification_ = true;
  432 + humidificationTimer.start(secs * 1000);
  433 + interface->startHumidification();
  434 +
  435 + emit changed(this);
  436 + }
405 } 437 }
406 } 438 }
407 439
@@ -419,6 +451,123 @@ void Oven::stopHumidification() @@ -419,6 +451,123 @@ void Oven::stopHumidification()
419 } 451 }
420 } 452 }
421 453
  454 +void Oven::repeatHumidification(int runtime, int delay, int count)
  455 +{
  456 + humidificationRepeatInfinitely = count == 0;
  457 + humidificationRepeatRuntime = runtime * 1000;
  458 + humidificationRepeatDelay = delay * 1000;
  459 + humidificationRepeatCount = count;
  460 +
  461 + if (humidificationRepeat)
  462 + {
  463 + if (humidificationRepeatPaused)
  464 + {
  465 + if (humidificationRepeatPausedOnRuntime)
  466 + humidificationRepeatRemainingTime = humidificationRepeatRuntime;
  467 + else
  468 + humidificationRepeatRemainingTime = humidificationRepeatDelay;
  469 + }
  470 + else
  471 + {
  472 + runRepeatHumidification();
  473 + }
  474 + }
  475 + else
  476 + {
  477 + humidificationRepeat = true;
  478 +
  479 + if (humidification())
  480 + {
  481 + humidificationRepeatPaused = true;
  482 + humidificationRepeatPausedOnRuntime = false;
  483 + humidificationRepeatRemainingTime = humidificationRepeatDelay;
  484 + }
  485 + else
  486 + {
  487 + humidificationRepeatPaused = false;
  488 + humidificationRepeatRemainingTime = 0;
  489 + runRepeatHumidification();
  490 + }
  491 + }
  492 +}
  493 +
  494 +void Oven::stopRepeatHumidification()
  495 +{
  496 + if (!humidificationRepeat)
  497 + return;
  498 +
  499 + humidificationRepeat = false;
  500 +
  501 + humidificationRepeatRuntimeTimer.stop();
  502 + humidificationRepeatDelayTimer.stop();
  503 +
  504 + if (humidification())
  505 + stopHumidification();
  506 +}
  507 +
  508 +void Oven::pauseRepeatHumidification()
  509 +{
  510 + if (!humidificationRepeat)
  511 + return;
  512 +
  513 + humidificationRepeatPaused = true;
  514 +
  515 + if (humidificationRepeatRuntimeTimer.isActive())
  516 + {
  517 + humidificationRepeatPausedOnRuntime = true;
  518 + humidificationRepeatRemainingTime = humidificationRepeatRuntimeTimer.remainingTime();
  519 + humidificationRepeatRuntimeTimer.stop();
  520 + }
  521 + else
  522 + {
  523 + humidificationRepeatPausedOnRuntime = false;
  524 + humidificationRepeatRemainingTime = humidificationRepeatDelayTimer.remainingTime();
  525 + humidificationRepeatDelayTimer.stop();
  526 + }
  527 +}
  528 +
  529 +void Oven::resumeRepeatHumidification()
  530 +{
  531 + if (!humidificationRepeat || !humidificationRepeatPaused)
  532 + return;
  533 +
  534 + humidificationRepeatPaused = false;
  535 +
  536 + if (humidificationRepeatPausedOnRuntime)
  537 + {
  538 + humidificationRepeatRuntimeTimer.start(humidificationRepeatRemainingTime);
  539 +
  540 + humidification_ = true;
  541 + interface->startHumidification();
  542 + emit changed(this);
  543 + }
  544 + else
  545 + {
  546 + humidificationRepeatDelayTimer.start(humidificationRepeatRemainingTime);
  547 + }
  548 +}
  549 +
  550 +void Oven::runRepeatHumidification()
  551 +{
  552 + if (humidificationRepeatInfinitely || humidificationRepeatCount-- > 0)
  553 + {
  554 + humidificationRepeatRuntimeTimer.start(humidificationRepeatRuntime);
  555 +
  556 + humidification_ = true;
  557 + interface->startHumidification();
  558 + emit changed(this);
  559 + }
  560 +}
  561 +
  562 +void Oven::idleRepeatHumidification()
  563 +{
  564 + humidificationRepeatDelayTimer.start(humidificationRepeatDelay);
  565 +
  566 + humidification_ = false;
  567 + interface->stopHumidification();
  568 + emit changed(this);
  569 +}
  570 +
422 void Oven::openDamper(int secs) 571 void Oven::openDamper(int secs)
423 { 572 {
424 if (!damper()) 573 if (!damper())
@@ -446,6 +595,123 @@ void Oven::closeDamper() @@ -446,6 +595,123 @@ void Oven::closeDamper()
446 } 595 }
447 } 596 }
448 597
  598 +void Oven::repeatDamper(int runtime, int delay, int count)
  599 +{
  600 + damperRepeatInfinitely = count == 0;
  601 + damperRepeatRuntime = runtime * 1000;
  602 + damperRepeatDelay = delay * 1000;
  603 + damperRepeatCount = count;
  604 +
  605 + if (damperRepeat)
  606 + {
  607 + if (damperRepeatPaused)
  608 + {
  609 + if (damperRepeatPausedOnRuntime)
  610 + damperRepeatRemainingTime = damperRepeatRuntime;
  611 + else
  612 + damperRepeatRemainingTime = damperRepeatDelay;
  613 + }
  614 + else
  615 + {
  616 + runRepeatDamper();
  617 + }
  618 + }
  619 + else
  620 + {
  621 + damperRepeat = true;
  622 +
  623 + if (damper())
  624 + {
  625 + damperRepeatPaused = true;
  626 + damperRepeatPausedOnRuntime = false;
  627 + damperRepeatRemainingTime = damperRepeatDelay;
  628 + }
  629 + else
  630 + {
  631 + damperRepeatPaused = false;
  632 + damperRepeatRemainingTime = 0;
  633 + runRepeatDamper();
  634 + }
  635 + }
  636 +}
  637 +
  638 +void Oven::stopRepeatDamper()
  639 +{
  640 + if (!damperRepeat)
  641 + return;
  642 +
  643 + damperRepeat = false;
  644 +
  645 + damperRepeatRuntimeTimer.stop();
  646 + damperRepeatDelayTimer.stop();
  647 +
  648 + if (damper())
  649 + closeDamper();
  650 +}
  651 +
  652 +void Oven::pauseRepeatDamper()
  653 +{
  654 + if (!damperRepeat)
  655 + return;
  656 +
  657 + damperRepeatPaused = true;
  658 +
  659 + if (damperRepeatRuntimeTimer.isActive())
  660 + {
  661 + damperRepeatPausedOnRuntime = true;
  662 + damperRepeatRemainingTime = damperRepeatRuntimeTimer.remainingTime();
  663 + damperRepeatRuntimeTimer.stop();
  664 + }
  665 + else
  666 + {
  667 + damperRepeatPausedOnRuntime = false;
  668 + damperRepeatRemainingTime = damperRepeatDelayTimer.remainingTime();
  669 + damperRepeatDelayTimer.stop();
  670 + }
  671 +}
  672 +
  673 +void Oven::resumeRepeatDamper()
  674 +{
  675 + if (!damperRepeat || !damperRepeatPaused)
  676 + return;
  677 +
  678 + damperRepeatPaused = false;
  679 +
  680 + if (damperRepeatPausedOnRuntime)
  681 + {
  682 + damperRepeatRuntimeTimer.start(damperRepeatRemainingTime);
  683 +
  684 + damper_ = true;
  685 + interface->closeDamper();
  686 + emit changed(this);
  687 + }
  688 + else
  689 + {
  690 + damperRepeatDelayTimer.start(damperRepeatRemainingTime);
  691 + }
  692 +}
  693 +
  694 +void Oven::runRepeatDamper()
  695 +{
  696 + if (damperRepeatInfinitely || damperRepeatCount-- > 0)
  697 + {
  698 + damperRepeatRuntimeTimer.start(damperRepeatRuntime);
  699 +
  700 + damper_ = true;
  701 + interface->openDamper();
  702 + emit changed(this);
  703 + }
  704 +}
  705 +
  706 +void Oven::idleRepeatDamper()
  707 +{
  708 + damperRepeatDelayTimer.start(damperRepeatDelay);
  709 +
  710 + damper_ = false;
  711 + interface->closeDamper();
  712 + emit changed(this);
  713 +}
  714 +
449 void Oven::setCurrentHumidity(int percentage) 715 void Oven::setCurrentHumidity(int percentage)
450 { 716 {
451 if (currentHumidity() != percentage) 717 if (currentHumidity() != percentage)
@@ -469,6 +735,21 @@ void Oven::setCurrentInterTemp(int celsius) @@ -469,6 +735,21 @@ void Oven::setCurrentInterTemp(int celsius)
469 if (currentInterTemp() != celsius) 735 if (currentInterTemp() != celsius)
470 { 736 {
471 currentInterTemp_ = celsius; 737 currentInterTemp_ = celsius;
  738 +
  739 + if (isInterTempValid_)
  740 + {
  741 + if (currentInterTemp_ == currentTemp_)
  742 + isInterTempValid_ = false;
  743 + }
  744 + else
  745 + {
  746 + if (currentInterTemp_ + 20 < currentTemp_)
  747 + {
  748 + isInterTempValid_ = true;
  749 + interTempValidTime = QTime::currentTime();
  750 + }
  751 + }
  752 +
472 emit changed(this); 753 emit changed(this);
473 } 754 }
474 } 755 }
@@ -556,6 +837,10 @@ void Oven::onDoorOpened() @@ -556,6 +837,10 @@ void Oven::onDoorOpened()
556 if (cooking()) 837 if (cooking())
557 { 838 {
558 stopCooking(); 839 stopCooking();
  840 +
  841 + if (damperRepeat)
  842 + pauseRepeatDamper();
  843 +
559 openDamper(7); 844 openDamper(7);
560 } 845 }
561 } 846 }
@@ -571,4 +856,7 @@ void Oven::onDoorClosed() @@ -571,4 +856,7 @@ void Oven::onDoorClosed()
571 856
572 if (damper()) 857 if (damper())
573 closeDamper(); 858 closeDamper();
  859 +
  860 + if (damperRepeat)
  861 + resumeRepeatDamper();
574 } 862 }
app/gui/oven_control/oven.h
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 3
4 #include <QObject> 4 #include <QObject>
5 #include <QTimer> 5 #include <QTimer>
  6 +#include <QTime>
6 7
7 class OvenInterface : public QObject 8 class OvenInterface : public QObject
8 { 9 {
@@ -71,6 +72,30 @@ private: @@ -71,6 +72,30 @@ private:
71 int currentTemp_; 72 int currentTemp_;
72 int currentInterTemp_; 73 int currentInterTemp_;
73 74
  75 + bool isInterTempValid_;
  76 + QTime interTempValidTime;
  77 +
  78 + bool damperRepeat;
  79 + bool damperRepeatInfinitely;
  80 + int damperRepeatRuntime;
  81 + int damperRepeatDelay;
  82 + int damperRepeatCount;
  83 + QTimer damperRepeatRuntimeTimer;
  84 + QTimer damperRepeatDelayTimer;
  85 + bool damperRepeatPaused;
  86 + bool damperRepeatPausedOnRuntime;
  87 + int damperRepeatRemainingTime;
  88 +
  89 + bool humidificationRepeat;
  90 + bool humidificationRepeatInfinitely;
  91 + int humidificationRepeatRuntime;
  92 + int humidificationRepeatDelay;
  93 + int humidificationRepeatCount;
  94 + QTimer humidificationRepeatRuntimeTimer;
  95 + QTimer humidificationRepeatDelayTimer;
  96 + bool humidificationRepeatPaused;
  97 + bool humidificationRepeatPausedOnRuntime;
  98 + int humidificationRepeatRemainingTime;
74 99
75 bool paused_; 100 bool paused_;
76 101
@@ -81,9 +106,17 @@ private: @@ -81,9 +106,17 @@ private:
81 106
82 OvenInterface *interface; 107 OvenInterface *interface;
83 108
  109 + static Oven *instance;
  110 +
84 public: 111 public:
85 explicit Oven(QObject *parent = 0); 112 explicit Oven(QObject *parent = 0);
86 113
  114 + static Oven *getInstance() {
  115 + if (instance == 0)
  116 + instance = new Oven();
  117 +
  118 + return instance;
  119 + }
87 120
88 Mode mode() { return mode_; } 121 Mode mode() { return mode_; }
89 int humidity() { return humidity_; } 122 int humidity() { return humidity_; }
@@ -104,6 +137,8 @@ public: @@ -104,6 +137,8 @@ public:
104 int currentHumidity() { return currentHumidity_; } 137 int currentHumidity() { return currentHumidity_; }
105 int currentInterTemp() { return currentInterTemp_; } 138 int currentInterTemp() { return currentInterTemp_; }
106 139
  140 + bool isInterTempValid();
  141 +
107 bool cookingStartable(); 142 bool cookingStartable();
108 bool preheatingStartable(); 143 bool preheatingStartable();
109 bool cooldownStartable(); 144 bool cooldownStartable();
@@ -139,12 +174,22 @@ public slots: @@ -139,12 +174,22 @@ public slots:
139 void stopPreheating(); 174 void stopPreheating();
140 void startCooldown(); 175 void startCooldown();
141 void stopCooldown(); 176 void stopCooldown();
142 - void startHumidification(); 177 + void startHumidification(int secs = 600);
143 void stopHumidification(); 178 void stopHumidification();
144 179
145 void openDamper(int secs = 300); 180 void openDamper(int secs = 300);
146 void closeDamper(); 181 void closeDamper();
147 182
  183 + void repeatHumidification(int runtime, int delay, int count = 0);
  184 + void stopRepeatHumidification();
  185 + void pauseRepeatHumidification();
  186 + void resumeRepeatHumidification();
  187 +
  188 + void repeatDamper(int runtime, int delay, int count = 0);
  189 + void stopRepeatDamper();
  190 + void pauseRepeatDamper();
  191 + void resumeRepeatDamper();
  192 +
148 void setCurrentHumidity(int percentage); 193 void setCurrentHumidity(int percentage);
149 void setCurrentTemp(int celsius); 194 void setCurrentTemp(int celsius);
150 void setCurrentInterTemp(int celsius); 195 void setCurrentInterTemp(int celsius);
@@ -159,12 +204,14 @@ private slots: @@ -159,12 +204,14 @@ private slots:
159 bool setInterTemp_(int celsius); 204 bool setInterTemp_(int celsius);
160 bool setFan_(int speed); 205 bool setFan_(int speed);
161 206
  207 + void runRepeatHumidification();
  208 + void idleRepeatHumidification();
162 209
  210 + void runRepeatDamper();
  211 + void idleRepeatDamper();
163 212
164 void onDoorOpened(); 213 void onDoorOpened();
165 void onDoorClosed(); 214 void onDoorClosed();
166 }; 215 };
167 216
168 -  
169 -  
170 #endif // OVEN_H 217 #endif // OVEN_H