Commit b53c48f6a7f6e5c3a2ad0816e6e8f9d6294ff7f3

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

세척 관련 관리 자료를 저장하지 않던 문제 수정

Showing 1 changed file with 66 additions and 30 deletions   Show diff stats
app/gui/oven_control/dirtylevel.cpp
... ... @@ -2,11 +2,41 @@
2 2  
3 3 #include <QDateTime>
4 4  
  5 +#include "ovenstatics.h"
  6 +
5 7 namespace {
6 8 QDateTime cookStartTime;
7 9 bool cookStarted = false;
8   -qint64 cookingTime;
9   -int cookingCount;
  10 +
  11 +void setCookingTime(qint64 t)
  12 +{
  13 + OvenStatistics::getInstance()->setTotalCookingTime(t, false);
  14 +}
  15 +
  16 +void addCookingTime(qint64 t)
  17 +{
  18 + OvenStatistics::getInstance()->addTotalCookingTime(t, false);
  19 +}
  20 +
  21 +qint64 getCookingTime()
  22 +{
  23 + return OvenStatistics::getInstance()->loadTotalCookingTime();
  24 +}
  25 +
  26 +void setCookingCount(int c)
  27 +{
  28 + OvenStatistics::getInstance()->setTotalCookingCount(c, false);
  29 +}
  30 +
  31 +void addCookingCount(int c)
  32 +{
  33 + OvenStatistics::getInstance()->addTotalCookingCount(c, false);
  34 +}
  35 +
  36 +int getCookingCount()
  37 +{
  38 + return OvenStatistics::getInstance()->loadTotalCookingCount();
  39 +}
10 40  
11 41 void decountState(int level)
12 42 {
... ... @@ -15,22 +45,22 @@ void decountState(int level)
15 45 switch (target)
16 46 {
17 47 case 0:
18   - cookingCount = 0;
  48 + setCookingCount(0);
19 49 break;
20 50 case 1:
21   - cookingCount = 1;
  51 + setCookingCount(1);
22 52 break;
23 53 case 2:
24   - cookingCount = 6;
  54 + setCookingCount(6);
25 55 break;
26 56 case 3:
27   - cookingCount = 11;
  57 + setCookingCount(11);
28 58 break;
29 59 case 4:
30   - cookingCount = 16;
  60 + setCookingCount(16);
31 61 break;
32 62 case 5:
33   - cookingCount = 21;
  63 + setCookingCount(21);
34 64 break;
35 65 }
36 66 }
... ... @@ -41,91 +71,97 @@ void DirtyLevel::cookStart()
41 71 {
42 72 cookStarted = true;
43 73 cookStartTime = QDateTime::currentDateTime();
44   - ::cookingCount++;
  74 + ::addCookingCount(1);
45 75 }
46 76  
47 77 void DirtyLevel::cookEnd()
48 78 {
49 79 if (cookStarted)
50 80 {
51   - cookStarted = true;
52   - ::cookingTime += cookStartTime.secsTo(QDateTime::currentDateTime());
  81 + cookStarted = false;
  82 +
  83 + ::addCookingTime(cookStartTime.secsTo(QDateTime::currentDateTime()));
53 84 }
54 85 }
55 86  
56 87 void DirtyLevel::wash(int type)
57 88 {
  89 + qint64 cookingTime = ::getCookingTime();
58 90 switch (type)
59 91 {
60 92 case 1:
61   - ::cookingTime = qMax(::cookingTime - 2 * 3600, (qint64) 0);
  93 + cookingTime = qMax(cookingTime - 2 * 3600, (qint64) 0);
62 94 decountState(1);
63 95 break;
64 96 case 2:
65   - ::cookingTime = qMax(::cookingTime - 3 * 3600, (qint64) 0);
  97 + cookingTime = qMax(cookingTime - 3 * 3600, (qint64) 0);
66 98 decountState(1);
67 99 break;
68 100 case 3:
69   - ::cookingTime = qMax(::cookingTime - 4 * 3600, (qint64) 0);
  101 + cookingTime = qMax(cookingTime - 4 * 3600, (qint64) 0);
70 102 decountState(2);
71 103 break;
72 104 case 4:
73   - ::cookingTime = qMax(::cookingTime - 10 * 3600, (qint64) 0);
  105 + cookingTime = qMax(cookingTime - 10 * 3600, (qint64) 0);
74 106 decountState(2);
75 107 break;
76 108 case 5:
77   - ::cookingTime = qMax(::cookingTime - 2 * 3600, (qint64) 0);
  109 + cookingTime = qMax(cookingTime - 2 * 3600, (qint64) 0);
78 110 decountState(1);
79 111 break;
80 112 }
  113 + ::setCookingTime(cookingTime);
81 114 }
82 115  
83 116 int DirtyLevel::dirty()
84 117 {
85   - if (::cookingCount < 1)
  118 + if (::getCookingCount() < 1)
86 119 return 0;
87   - if (::cookingTime < 1 * 3600)
  120 +
  121 + qint64 cookingTime = ::getCookingTime();
  122 + if (cookingTime < 1 * 3600)
88 123 return 1;
89   - if (::cookingTime < 3 * 3600)
  124 + if (cookingTime < 3 * 3600)
90 125 return 2;
91   - if (::cookingTime < 5 * 3600)
  126 + if (cookingTime < 5 * 3600)
92 127 return 3;
93   - if (::cookingTime < 7 * 3600)
  128 + if (cookingTime < 7 * 3600)
94 129 return 4;
95 130 return 5;
96 131 }
97 132  
98 133 int DirtyLevel::state()
99 134 {
100   - if (::cookingCount < 1)
  135 + int cookingCount = ::getCookingCount();
  136 + if (cookingCount < 1)
101 137 return 0;
102   - if (::cookingCount <= 5)
  138 + if (cookingCount <= 5)
103 139 return 1;
104   - if (::cookingCount <= 10)
  140 + if (cookingCount <= 10)
105 141 return 2;
106   - if (::cookingCount <= 15)
  142 + if (cookingCount <= 15)
107 143 return 3;
108   - if (::cookingCount <= 20)
  144 + if (cookingCount <= 20)
109 145 return 4;
110 146 return 5;
111 147 }
112 148  
113 149 void DirtyLevel::setCookingTime(qint64 secs)
114 150 {
115   - ::cookingTime = secs;
  151 + ::setCookingTime(secs);
116 152 }
117 153  
118 154 int DirtyLevel::cookingTime()
119 155 {
120   - return ::cookingTime;
  156 + return ::getCookingTime();
121 157 }
122 158  
123 159 int DirtyLevel::cookingCount()
124 160 {
125   - return ::cookingCount;
  161 + return ::getCookingCount();
126 162 }
127 163  
128 164 void DirtyLevel::setCookingCount(int count)
129 165 {
130   - ::cookingCount = count;
  166 + ::setCookingCount(count);
131 167 }
... ...