Blame view

app/gui/oven_control/multicookcontroller.cpp 4.12 KB
2f6b55128   김태훈   다중 요리 구현
1
2
3
  #include "multicookcontroller.h"
  
  #include "oven.h"
af27778be   김태훈   HACCP 구현
4
  #include "haccp.h"
2f6b55128   김태훈   다중 요리 구현
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  
  MultiCookController::MultiCookController(QObject *parent) : QObject(parent)
  {
      state = Idle;
  
      connect(&checkTimer, SIGNAL(timeout()), SLOT(check()));
  }
  
  void MultiCookController::setContainer(MultiCookContainer *container)
  {
      this->container = container;
      checkTimer.start(100);
  }
  
  bool MultiCookController::requireOpen()
  {
      if (state == OpenDoor || state == Finished)
          return true;
  
      if (state != Running)
          return false;
  
      for (int i = 0; i < 10; i++)
      {
          MultiCook *cook = container->at(i);
          if (cook != Q_NULLPTR && cook->remainingTime() <= 0)
              return true;
      }
  
      return false;
  }
  
  bool MultiCookController::requireClose()
  {
      if (state == Idle || state == OpenDoor)
          return false;
  
      return true;
  }
  
  void MultiCookController::check()
  {
      switch (state)
      {
      case Idle:
          if (!container->isEmpty())
af27778be   김태훈   HACCP 구현
51
          {
2f6b55128   김태훈   다중 요리 구현
52
              state = Preheating;
af27778be   김태훈   HACCP 구현
53
54
55
  
              HACCP::multiStart();
          }
2f6b55128   김태훈   다중 요리 구현
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
          break;
      case Preheating:
          checkPreheating();
          break;
      case OpenDoor:
          if (Oven::getInstance()->door())
              state = CloseDoor;
          break;
      case CloseDoor:
          if (!Oven::getInstance()->door())
          {
              state = Running;
              container->start();
          }
          break;
      case Running:
          checkRunning();
          break;
      case Paused:
          checkPaused();
          break;
      case Finished:
          checkFinished();
          break;
      }
  }
  
  void MultiCookController::checkPreheating()
  {
      Oven *oven = Oven::getInstance();
      if (container->isEmpty())
      {
          state = Idle;
af27778be   김태훈   HACCP 구현
89
          HACCP::done();
2f6b55128   김태훈   다중 요리 구현
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
          oven->stop();
          return;
      }
  
      int temp = container->temperature();
      if (temp <= oven->currentTemp())
      {
          state = OpenDoor;
          oven->stop();
          return;
      }
  
      if (temp != oven->temp())
          oven->setTemp(temp);
  
      int hum = container->humidity();
      if (hum != oven->humidity())
          oven->setHumidity(hum);
  
      if (!oven->preheating())
          oven->startPreheating();
  }
  
  void MultiCookController::checkRunning()
  {
      Oven *oven = Oven::getInstance();
      if (container->isEmpty())
      {
          state = Idle;
af27778be   김태훈   HACCP 구현
119
          HACCP::done();
2f6b55128   김태훈   다중 요리 구현
120
121
122
123
124
125
126
          oven->stop();
          return;
      }
  
      if (container->isFinished())
      {
          state = Finished;
af27778be   김태훈   HACCP 구현
127
          HACCP::done();
2f6b55128   김태훈   다중 요리 구현
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
          oven->stop();
          container->stop();
          return;
      }
  
      if (oven->door())
      {
          state = Paused;
          oven->stopCooking();
          container->pause();
          return;
      }
  
  //    Define::Mode mode = container->mode();
  //    switch (mode)
  //    {
  //    case Define::Invalid:
  //        // Do nothing
  //        break;
  //    case Define::SteamMode:
  //    case Define::CombiMode:
  //    case Define::DryMode:
  //        oven->setMode(mode);
  //        break;
  //    }
  
  //    int temp = container->temperature();
  //    if (temp != oven->temp())
  //        oven->setTemp(temp);
  
  //    int hum = container->humidity();
  //    if (hum != oven->humidity())
  //        oven->setHumidity(hum);
  
      oven->setMode(container->mode());
      oven->setTemp(container->temperature());
      oven->setHumidity(container->humidity());
  
      if (!oven->cooking())
      {
          oven->setTime(12 * 60 * 60);
          oven->startCooking();
      }
  }
  
  void MultiCookController::checkPaused()
  {
      Oven *oven = Oven::getInstance();
      if (oven->door())
          return;
  
      for (int i = 0; i < 10; i++)
      {
          MultiCook *cook = container->at(i);
          if (cook != Q_NULLPTR && cook->remainingTime() <= 0)
          {
              container->remove(i);
              cook->deleteLater();
          }
      }
  
      state = Running;
      container->resume();
  }
  
  void MultiCookController::checkFinished()
  {
      Oven *oven = Oven::getInstance();
      if (oven->door())
      {
          state = Idle;
af27778be   김태훈   HACCP 구현
199
          HACCP::done();
2f6b55128   김태훈   다중 요리 구현
200
201
202
203
204
205
206
207
208
209
210
211
  
          for (int i = 0; i < 10; i++)
          {
              MultiCook *cook = container->at(i);
              if (cook != Q_NULLPTR)
              {
                  container->remove(i);
                  cook->deleteLater();
              }
          }
      }
  }