Blame view

app/gui/oven_control/autocook.cpp 15.9 KB
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
1
  #include "autocook.h"
c6dd03260   김태훈   요리 시작/종료 관련 음향 효과...
2
  #include "soundplayer.h"
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
3
4
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
  
  AutoCook::AutoCook() : currentStepIndex(0), done_(false), doorOpened(false), checkingCoreTemp(false)
  {
  
  }
  
  AutoCook::AutoCook(Cook cook) : AutoCook()
  {
      this->cook = cook;
      for (int idx = 0; idx < this->cook.steps.size(); idx++)
          this->cook.steps[idx].time *= 1000;
  
  
      startStep();
  }
  
  void AutoCook::startStep()
  {
      Oven *oven = Oven::getInstance();
  
      CookStep &currentStep = cook.steps[currentStepIndex];
      switch (Define::classify(currentStep.type))
      {
      case Define::PreheatClass:
          startHumidity = oven->currentHumidity();
          startTemp = oven->currentTemp();
          isWaitingDoorOpened_ = false;
d0cfbd177   김태훈   GUI V0.1.10 (이 버전...
30
          oven->setMode(currentStep.mode);
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
31
32
33
34
35
36
37
38
39
40
41
42
          oven->setHumidity(currentStep.humidity);
          oven->setTemp(currentStep.temp);
          oven->setFan(currentStep.fan);
          oven->startPreheating();
          break;
      case Define::DoorClass:
          isWaitingDoorOpened_ = true;
          break;
      case Define::CookClass:
          startHumidity = oven->currentHumidity();
          startTemp = oven->currentTemp();
          isWaitingDoorOpened_ = false;
d0cfbd177   김태훈   GUI V0.1.10 (이 버전...
43
          oven->setMode(currentStep.mode);
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
44
45
46
47
          oven->setHumidity(currentStep.humidity);
          oven->setTemp(currentStep.temp);
          oven->setFan(currentStep.fan);
          oven->setTime(remainingTime() + 300);
c3af501ea   김태훈   GUI V0.2.0
48
          oven->setInterTempEnabled(false);
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
49
          if (cook.isCoreTempValid())
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
50
              oven->setInterTemp(cook.coreTemp());
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  
          if (currentStep.dehumidification)
          {
              if (currentStep.dehumidificationRepeatDelay)
                  oven->repeatDamper(currentStep.dehumidification, currentStep.dehumidificationRepeatDelay, currentStep.dehumidificationRepeatCount);
              else
                  oven->openDamper(currentStep.dehumidification);
          }
  
          if (currentStep.humidification)
          {
              if (currentStep.humidificationRepeatDelay)
                  oven->repeatHumidification(currentStep.humidification, currentStep.humidificationRepeatDelay, currentStep.humidificationRepeatCount);
              else
                  oven->startHumidification(currentStep.humidification);
          }
  
          stepStartTime.start();
          oven->startCooking();
      case Define::InvalidClass:
          break;
      }
  
      advance();
  }
  
  void AutoCook::nextStep()
  {
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
      Oven *oven = Oven::getInstance();
  
      CookStep &currentStep = cook.steps[currentStepIndex];
      CookStep &nextStep = cook.steps[currentStepIndex + 1];
  
      Define::StepClass currentClass = Define::classify(currentStep.type);
      Define::StepClass nextClass = Define::classify(nextStep.type);
  
      if (currentClass == Define::PreheatClass && nextClass == Define::DoorClass)
      {
          oven->stopPreheating();
          isWaitingDoorOpened_ = true;
      }
      else if (currentClass == Define::DoorClass && nextClass == Define::CookClass)
      {
          startHumidity = oven->currentHumidity();
          startTemp = oven->currentTemp();
e49f3cacd   김태훈   자동 요리 기능 변경
96
          oven->setMode(nextStep.mode);
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
97
98
99
100
101
102
          oven->setHumidity(nextStep.humidity);
          oven->setTemp(nextStep.temp);
          oven->setFan(nextStep.fan);
          oven->setTime(remainingTime() + 300);
  
          if (cook.isCoreTempValid())
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
103
              oven->setInterTemp(cook.coreTemp());
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  
          stepStartTime.start();
          oven->startCooking();
  
          if (nextStep.dehumidification)
          {
              if (nextStep.dehumidificationRepeatDelay)
                  oven->repeatDamper(nextStep.dehumidification, nextStep.dehumidificationRepeatDelay, nextStep.dehumidificationRepeatCount);
              else
                  oven->openDamper(nextStep.dehumidification);
          }
  
          if (nextStep.humidification)
          {
              if (nextStep.humidificationRepeatDelay)
                  oven->repeatHumidification(nextStep.humidification, nextStep.humidificationRepeatDelay, nextStep.humidificationRepeatCount);
              else
                  oven->startHumidification(nextStep.humidification);
          }
  
          if (checkingCoreTemp && currentStepIndex + 2 >= cook.steps.size())
          {
              lastCoreTempIncreasedTime.start();
          }
      }
      else if (currentClass == Define::CookClass && nextClass == Define::CookClass)
      {
          startHumidity = oven->currentHumidity();
          startTemp = oven->currentTemp();
e49f3cacd   김태훈   자동 요리 기능 변경
133
          oven->setMode(nextStep.mode);
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
          oven->setHumidity(nextStep.humidity);
          oven->setTemp(nextStep.temp);
          oven->setFan(nextStep.fan);
          stepStartTime.start();
  
          if (currentStep.dehumidification)
          {
              if (nextStep.dehumidification)
              {
                  if (currentStep.dehumidificationRepeatDelay)
                  {
                      if (nextStep.dehumidificationRepeatDelay)
                          oven->repeatDamper(nextStep.dehumidification, nextStep.dehumidificationRepeatDelay, nextStep.dehumidificationRepeatCount);
                      else
                      {
                          oven->stopRepeatDamper();
                          oven->openDamper(nextStep.dehumidification);
                      }
                  }
                  else
                  {
                      if (nextStep.dehumidificationRepeatDelay)
                          oven->repeatDamper(nextStep.dehumidification, nextStep.dehumidificationRepeatDelay, nextStep.dehumidificationRepeatCount);
                      else
                          oven->openDamper(nextStep.dehumidification);
                  }
              }
              else
              {
                  if (currentStep.dehumidificationRepeatDelay)
                      oven->stopRepeatDamper();
              }
          }
          else
          {
              if (nextStep.dehumidification)
              {
                  if (nextStep.dehumidificationRepeatDelay)
                      oven->repeatDamper(nextStep.dehumidification, nextStep.dehumidificationRepeatDelay, nextStep.dehumidificationRepeatCount);
                  else
                      oven->openDamper(nextStep.dehumidification);
              }
          }
  
          if (nextStep.humidification != currentStep.humidification
                  || nextStep.humidificationRepeatDelay != currentStep.humidificationRepeatDelay
                  || nextStep.humidificationRepeatCount != currentStep.humidificationRepeatCount)
          {
              if (nextStep.humidificationRepeatDelay)
              {
                  if (currentStep.humidificationRepeatDelay)
                      oven->repeatHumidification(nextStep.humidification, nextStep.humidificationRepeatDelay, nextStep.humidificationRepeatCount);
                  else
                  {
                      oven->stopHumidification();
                      oven->repeatHumidification(nextStep.humidification, nextStep.humidificationRepeatDelay, nextStep.humidificationRepeatCount);
                  }
              }
              else
              {
                  if (currentStep.humidificationRepeatDelay)
                  {
                      oven->stopRepeatHumidification();
                      oven->startHumidification(nextStep.humidification);
                  }
                  else
                      oven->startHumidification(nextStep.humidification);
              }
          }
  
          if (checkingCoreTemp && currentStepIndex + 2 >= cook.steps.size())
          {
              lastCoreTempIncreasedTime.start();
          }
      }
      else if (currentClass == Define::CookClass && nextClass == Define::DoorClass)
      {
          if (currentStep.dehumidification)
          {
              if (currentStep.dehumidificationRepeatDelay)
                  oven->stopRepeatDamper();
              else
                  oven->closeDamper();
          }
  
          if (currentStep.humidification)
          {
              if (currentStep.humidificationRepeatDelay)
                  oven->stopRepeatHumidification();
              else
                  oven->stopHumidification();
          }
c3af501ea   김태훈   GUI V0.2.0
226
          oven->setInterTempEnabled(false);
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
227
228
229
230
231
232
233
          oven->stopCooking();
          isWaitingDoorOpened_ = true;
      }
  
      currentStepIndex++;
  
      advance();
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
234
235
236
237
238
239
240
241
242
243
  }
  
  bool AutoCook::advance()
  {
      Oven *oven = Oven::getInstance();
  
      CookStep &currentStep = cook.steps[currentStepIndex];
      switch (Define::classify(currentStep.type))
      {
      case Define::PreheatClass:
1a93d524e   김태훈   예열 완료 조건 변경
244
          if (oven->currentTemp() >= currentStep.temp)
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
          {
              nextStep();
  
              return true;
          }
          break;
      case Define::DoorClass:
          if (isWaitingDoorOpened_)
          {
              if (oven->door())
              {
                  isWaitingDoorOpened_ = false;
  
                  return true;
              }
          }
          else
          {
              if (!oven->door())
              {
                  nextStep();
  
                  return true;
              }
          }
          break;
      case Define::CookClass:
      {
          if (oven->door())
          {
              if (!doorOpened)
              {
                  doorOpened = true;
  
                  if (checkingCoreTemp && currentStepIndex + 1 >= cook.steps.size())
                  {
                      currentStep.time -= lastCoreTempIncreasedTime.elapsed();
                  }
                  else
                  {
                      currentStep.time -= stepStartTime.elapsed();
                  }
              }
  
              return false;
          }
          else if (doorOpened)
          {
              doorOpened = false;
              stepStartTime.start();
              lastCoreTempIncreasedTime.start();
              lastCoreTempChangedTime.start();
          }
  
          int remainingCurrentStepTime = currentStep.time;
          if (checkingCoreTemp && currentStepIndex + 1 >= cook.steps.size())
              remainingCurrentStepTime -= lastCoreTempIncreasedTime.elapsed();
          else
              remainingCurrentStepTime -= stepStartTime.elapsed();
  
          if (remainingCurrentStepTime <= 0)
          {
              if (currentStepIndex + 1 < cook.steps.size())
              {
                  nextStep();
  
                  return true;
              }
              else
              {
                  done_ = true;
c6dd03260   김태훈   요리 시작/종료 관련 음향 효과...
316
                  SoundPlayer::playStop();
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
                  if (currentStep.dehumidification)
                  {
                      if (currentStep.dehumidificationRepeatDelay)
                          oven->stopRepeatDamper();
                      else
                          oven->closeDamper();
                  }
  
                  if (currentStep.humidification)
                  {
                      if (currentStep.humidificationRepeatDelay)
                          oven->stopRepeatHumidification();
                      else
                          oven->stopHumidification();
                  }
  
                  oven->stopCooking();
  
                  return true;
              }
          }
          else if (cook.isCoreTempValid() && oven->isInterTempValid())
          {
              if (!checkingCoreTemp)
              {
                  checkingCoreTemp = true;
                  lastCoreTemp = oven->currentInterTemp();
                  lastIncreasedCoreTemp = lastCoreTemp;
                  lastCoreTempChangedTime.start();
                  lastCoreTempIncreasedTime.start();
              }
c3af501ea   김태훈   GUI V0.2.0
348
349
350
351
352
              if (cook.coreTemp() != oven->interTemp())
                  oven->setInterTemp(cook.coreTemp());
  
              if (!oven->interTempEnabled())
                  oven->setInterTempEnabled(true);
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
353
354
355
356
357
  
              int currentCoreTemp = oven->currentInterTemp();
              if (currentCoreTemp >= cook.coreTemp())
              {
                  done_ = true;
c6dd03260   김태훈   요리 시작/종료 관련 음향 효과...
358
                  SoundPlayer::playStop();
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
                  if (currentStep.dehumidification)
                  {
                      if (currentStep.dehumidificationRepeatDelay)
                          oven->stopRepeatDamper();
                      else
                          oven->closeDamper();
                  }
  
                  if (currentStep.humidification)
                  {
                      if (currentStep.humidificationRepeatDelay)
                          oven->stopRepeatHumidification();
                      else
                          oven->stopHumidification();
                  }
  
                  oven->stopCooking();
  
                  currentStepIndex = cook.steps.size() - 1;
  
                  return true;
              }
              else if (currentCoreTemp != lastCoreTemp)
              {
                  if (currentCoreTemp > lastIncreasedCoreTemp)
                  {
                      if (currentStepIndex + 1 < cook.steps.size())
                      {
                          int otherStepsTime = 0;
                          for (int idx = currentStepIndex; idx + 1 < cook.steps.size(); idx++)
                              otherStepsTime += cook.steps[idx].time;
  
                          otherStepsTime -= stepStartTime.elapsed();
  
                          int expectedRemainingTime = (cook.coreTemp() - currentCoreTemp) * lastCoreTempChangedTime.elapsed() / (currentCoreTemp - lastCoreTemp);
                          int expectedLastStepRemainingTime = expectedRemainingTime - otherStepsTime;
  
                          CookStep &lastStep = cook.steps[cook.steps.size() - 1];
                          lastStep.time = qMax(expectedLastStepRemainingTime, 30000);
  
                          lastIncreasedCoreTemp = currentCoreTemp;
                          lastCoreTempIncreasedTime.start();
                      }
                      else
                      {
                          CookStep &lastStep = cook.steps[cook.steps.size() - 1];
  
                          int expectedRemainingTime = (cook.coreTemp() - currentCoreTemp) * lastCoreTempChangedTime.elapsed() / (currentCoreTemp - lastCoreTemp);
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
407
408
409
410
411
412
413
414
                          if (expectedRemainingTime > 30000)
                          {
                              lastStep.time = expectedRemainingTime;
                              lastCoreTempIncreasedTime.start();
                          }
                          else
                          {
                              int currentRemainingTime = lastStep.time - lastCoreTempIncreasedTime.elapsed();
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
                              if (currentRemainingTime > 30000)
                              {
                                  lastStep.time = 30000;
                                  lastCoreTempIncreasedTime.start();
                              }
                              else if (expectedRemainingTime > currentRemainingTime)
                              {
                                  lastStep.time = expectedRemainingTime;
                                  lastCoreTempIncreasedTime.start();
                              }
                          }
                      }
                  }
  
                  lastCoreTemp = currentCoreTemp;
                  lastCoreTempChangedTime.start();
              }
c3af501ea   김태훈   GUI V0.2.0
432
433
434
435
          }
          else if (oven->interTempEnabled())
          {
              oven->setInterTempEnabled(false);
6a81d38e4   김태훈   자동 요리 관련 로직 전면 재작성
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
          }
      }
      case Define::InvalidClass:
              break;
      }
  
      return false;
  }
  
  int AutoCook::remainingTime()
  {
      if (done_)
      {
          return 0;
      }
      else if (checkingCoreTemp && currentStepIndex + 1 >= cook.steps.size())
      {
          CookStep &step = cook.steps[cook.steps.size() - 1];
          int t = step.time;
          if (!doorOpened)
              t -= lastCoreTempIncreasedTime.elapsed();
  
          return t / 1000;
      }
      else
      {
          int t = 0;
          for (int i = currentStepIndex; i < cook.steps.size(); i++)
              t += cook.steps[i].time;
  
          if (!doorOpened && Define::classify(cook.steps[currentStepIndex].type) == Define::CookClass)
              t -= stepStartTime.elapsed();
  
          return t / 1000;
      }
  }
2bfd3a050   김태훈   환경 설정 대응
472
62e672364   김태훈   자동 요리 중 중심 온도 활성화...
473
474
475
476
  bool AutoCook::isCoreTempActivated()
  {
      return checkingCoreTemp;
  }
2bfd3a050   김태훈   환경 설정 대응
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
  int AutoCook::msecs()
  {
      if (done_)
      {
          return 0;
      }
      else if (checkingCoreTemp && currentStepIndex + 1 >= cook.steps.size())
      {
          CookStep &step = cook.steps[cook.steps.size() - 1];
          int t = step.time;
          if (!doorOpened)
              t -= lastCoreTempIncreasedTime.elapsed();
  
          return t;
      }
      else
      {
          int t = 0;
          for (int i = currentStepIndex; i < cook.steps.size(); i++)
              t += cook.steps[i].time;
  
          if (!doorOpened && Define::classify(cook.steps[currentStepIndex].type) == Define::CookClass)
              t -= stepStartTime.elapsed();
  
          return t;
      }
  }