Blame view

app/gui/oven_control/fantestwindow.cpp 6.89 KB
8c2952457   김태훈   응용 프로그램 추가
1
2
3
4
5
6
7
8
  #include "fantestwindow.h"
  #include "ui_fantestwindow.h"
  
  FanTestWindow::FanTestWindow(QWidget *parent, UdpHandler *udp) :
      QMainWindow(parent),
      ui(new Ui::FanTestWindow), udp(udp)
  {
      ui->setupUi(this);
6f96c947a   김태훈   GUI 0.1.4
9
8c2952457   김태훈   응용 프로그램 추가
10
      ui->clockContainer->setParent(ui->upperStack);
6f96c947a   김태훈   GUI 0.1.4
11
      setAttribute(Qt::WA_DeleteOnClose);
8c2952457   김태훈   응용 프로그램 추가
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
      connect(udp, SIGNAL(changed()), this, SLOT(onDataChanged()));
  
      currentFan = Fan1;
      direction1 = direction2 = ClockWise;
      rpm1 = rpm2 = 500;
  
      udp->set(TG_OVEN_MODE, 4);
      udp->turnOn(TG_SYSTEM);
      udp->turnOn(TG_MANUAL_FAN1);
      udp->turnOn(TG_MANUAL_FAN2);
      udp->set(TG_FAN1_RPM, rpm1);
      udp->set(TG_FAN2_RPM, rpm2);
      udp->set(TG_FAN1_RPM, direction1);
      udp->set(TG_FAN2_RPM, direction2);
  
      onDataChanged();
  }
  
  FanTestWindow::~FanTestWindow()
  {
      delete ui;
  }
  
  void FanTestWindow::onDataChanged()
  {
      if (udp->convection1())
          ui->start1Button->setText("STOP");
      else
          ui->start1Button->setText("START");
  
      if (udp->convection2())
          ui->start2Button->setText("STOP");
      else
          ui->start2Button->setText("START");
  
      int rpm;
      Direction dir;
  
      QString unselectedStyle("color: white");
      QString selectedStyle("color: yellow");
  
      ui->motorLabel1->setStyleSheet(unselectedStyle);
      ui->motorLabel2->setStyleSheet(unselectedStyle);
      ui->directionLabelLeft->setStyleSheet(unselectedStyle);
      ui->directionLabelRight->setStyleSheet(unselectedStyle);
      ui->rpmLabel500->setStyleSheet(unselectedStyle);
      ui->rpmLabel725->setStyleSheet(unselectedStyle);
      ui->rpmLabel950->setStyleSheet(unselectedStyle);
      ui->rpmLabel1175->setStyleSheet(unselectedStyle);
      ui->rpmLabel1400->setStyleSheet(unselectedStyle);
  
      switch (currentFan)
      {
      case Fan1:
          rpm = rpm1;
          dir = direction1;
05f2a7552   김태훈   image 관리 구조 변경
68
          ui->fanLabel->setPixmap(QPixmap(":/images/config/service/fan_sel_1.png"));
8c2952457   김태훈   응용 프로그램 추가
69
70
71
72
73
          ui->motorLabel1->setStyleSheet(selectedStyle);
          break;
      case Fan2:
          rpm = rpm2;
          dir = direction2;
05f2a7552   김태훈   image 관리 구조 변경
74
          ui->fanLabel->setPixmap(QPixmap(":/images/config/service/fan_sel_2.png"));
8c2952457   김태훈   응용 프로그램 추가
75
76
77
78
79
          ui->motorLabel2->setStyleSheet(selectedStyle);
          break;
      default:
          rpm = 500;
          dir = ClockWise;
05f2a7552   김태훈   image 관리 구조 변경
80
          ui->fanLabel->setPixmap(QPixmap(":/images/config/service/fan_sel_1.png"));
8c2952457   김태훈   응용 프로그램 추가
81
82
83
84
85
86
          ui->motorLabel1->setStyleSheet(selectedStyle);
      }
  
      switch (rpm)
      {
      case 500:
05f2a7552   김태훈   image 관리 구조 변경
87
          ui->rpmLabel->setPixmap(QPixmap(":/images/config/service/fan_level_1.png"));
8c2952457   김태훈   응용 프로그램 추가
88
89
90
          ui->rpmLabel500->setStyleSheet(selectedStyle);
          break;
      case 725:
05f2a7552   김태훈   image 관리 구조 변경
91
          ui->rpmLabel->setPixmap(QPixmap(":/images/config/service/fan_level_2.png"));
8c2952457   김태훈   응용 프로그램 추가
92
93
94
          ui->rpmLabel725->setStyleSheet(selectedStyle);
          break;
      case 950:
05f2a7552   김태훈   image 관리 구조 변경
95
          ui->rpmLabel->setPixmap(QPixmap(":/images/config/service/fan_level_3.png"));
8c2952457   김태훈   응용 프로그램 추가
96
97
98
          ui->rpmLabel950->setStyleSheet(selectedStyle);
          break;
      case 1175:
05f2a7552   김태훈   image 관리 구조 변경
99
          ui->rpmLabel->setPixmap(QPixmap(":/images/config/service/fan_level_4.png"));
8c2952457   김태훈   응용 프로그램 추가
100
101
102
          ui->rpmLabel1175->setStyleSheet(selectedStyle);
          break;
      case 1400:
05f2a7552   김태훈   image 관리 구조 변경
103
          ui->rpmLabel->setPixmap(QPixmap(":/images/config/service/fan_level_5.png"));
8c2952457   김태훈   응용 프로그램 추가
104
105
106
          ui->rpmLabel1400->setStyleSheet(selectedStyle);
          break;
      default:
05f2a7552   김태훈   image 관리 구조 변경
107
          ui->rpmLabel->setPixmap(QPixmap(":/images/config/service/fan_level_1.png"));
8c2952457   김태훈   응용 프로그램 추가
108
109
110
111
112
113
          ui->rpmLabel500->setStyleSheet(selectedStyle);
      }
  
      switch (dir)
      {
      case ClockWise:
05f2a7552   김태훈   image 관리 구조 변경
114
          ui->directionLabel->setPixmap(QPixmap(":/images/config/service/fan_dir_cw.png"));
8c2952457   김태훈   응용 프로그램 추가
115
116
117
          ui->directionLabelRight->setStyleSheet(selectedStyle);
          break;
      case CounterClockWise:
05f2a7552   김태훈   image 관리 구조 변경
118
          ui->directionLabel->setPixmap(QPixmap(":/images/config/service/fan_dir_ccw.png"));
8c2952457   김태훈   응용 프로그램 추가
119
120
121
          ui->directionLabelLeft->setStyleSheet(selectedStyle);
          break;
      default:
05f2a7552   김태훈   image 관리 구조 변경
122
          ui->directionLabel->setPixmap(QPixmap(":/images/config/service/fan_dir_cw.png"));
8c2952457   김태훈   응용 프로그램 추가
123
124
125
126
127
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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
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
          ui->directionLabelRight->setStyleSheet(selectedStyle);
      }
  
      QString buf;
      ui->motor1RpmLabel->setText(buf.sprintf("%d rpm", rpm1));
      ui->motor2RpmLabel->setText(buf.sprintf("%d rpm", rpm2));
  }
  
  void FanTestWindow::on_rpmButton_clicked()
  {
      int *target;
      switch (currentFan)
      {
      case Fan1:
          target = &rpm1;
          break;
      case Fan2:
          target = &rpm2;
          break;
      default:
          return;
      }
  
      switch (*target)
      {
      case 500:
          *target = 725;
          break;
      case 725:
          *target = 950;
          break;
      case 950:
          *target = 1175;
          break;
      case 1175:
          *target = 1400;
          break;
      case 1400:
          *target = 500;
          break;
      default:
          *target = 500;
      }
  
      setRpm(currentFan, *target);
  
      onDataChanged();
  }
  
  void FanTestWindow::on_directionButton_clicked()
  {
      Direction *target;
      switch (currentFan)
      {
      case Fan1:
          target = &direction1;
          break;
      case Fan2:
          target = &direction2;
          break;
      default:
          return;
      }
  
      switch (*target)
      {
      case ClockWise:
          *target = CounterClockWise;
          break;
      case CounterClockWise:
          *target = ClockWise;
          break;
      default:
          return;
      }
  
      setDirection(currentFan, *target);
  
      onDataChanged();
  }
  
  void FanTestWindow::on_motorButton_clicked()
  {
      switch (currentFan)
      {
      case Fan1:
          currentFan = Fan2;
          break;
      case Fan2:
          currentFan = Fan1;
          break;
      default:
          currentFan = Fan1;
      }
  
      onDataChanged();
  }
  
  void FanTestWindow::on_start1Button_clicked()
  {
      if (udp->convection1())
          stop(Fan1);
      else
          start(Fan1);
  }
  
  void FanTestWindow::on_start2Button_clicked()
  {
      if (udp->convection2())
          stop(Fan2);
      else
          start(Fan2);
  }
  
  void FanTestWindow::on_backButton_clicked()
  {
      stop(Fan1);
      stop(Fan2);
  
      udp->turnOff(TG_MANUAL_FAN1);
      udp->turnOff(TG_MANUAL_FAN2);
      udp->turnOff(TG_SYSTEM);
  
      deleteLater();
  }
  
  void FanTestWindow::setRpm(Fan fan, int rpm)
  {
      switch (fan)
      {
      case Fan1:
          udp->set(TG_FAN1_RPM, rpm);
          break;
      case Fan2:
          udp->set(TG_FAN2_RPM, rpm);
          break;
      }
  }
  
  void FanTestWindow::setDirection(Fan fan, Direction direction)
  {
      int dir;
      switch (direction)
      {
      case ClockWise:
          dir = 0;
          break;
      case CounterClockWise:
          dir = 1;
          break;
      default:
          return;
      }
  
      switch (fan)
      {
      case Fan1:
          udp->set(TG_FAN1_DIRECTOIN, dir);
          break;
      case Fan2:
          udp->set(TG_FAN2_DIRECTOIN, dir);
          break;
      }
  }
  
  void FanTestWindow::start(Fan fan)
  {
      switch (fan)
      {
      case Fan1:
          udp->turnOn(TG_FAN1_MANUAL);
          break;
      case Fan2:
          udp->turnOn(TG_FAN2_MANUAL);
          break;
      }
  }
  
  void FanTestWindow::stop(Fan fan)
  {
      switch (fan)
      {
      case Fan1:
          udp->turnOff(TG_FAN1_MANUAL);
          break;
      case Fan2:
          udp->turnOff(TG_FAN2_MANUAL);
          break;
      }
  }