]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/display-qt/displayqt.cpp
display-qt : Some files and function were renamed (only).
[eurobot/public.git] / src / display-qt / displayqt.cpp
1 #include "displayqt.h"
2 #include "ui_displayqt.h"
3 #include <QtGui>
4 #include <QObject>
5 #include <QTimer>
6 #include <QString>
7 #include <robomath.h>
8
9 //backround colors for labels
10 #define GREEN "background-color:rgb(27, 255, 11)"
11 #define RED "background-color:red"
12 #define YELLOW "background-color:yellow"
13
14 DisplayQT::DisplayQT(QWidget *parent) :
15         QWidget(parent),
16         ui(new Ui::DisplayQT)
17 {
18         ui->setupUi(this);
19
20         //na zacatku nazname polohu
21         this->pos.positionIsActual=false;
22
23         /*ASCII tocitko
24         pomoci timeru je kazdych 500 ms
25         vyvolan signal pro pohnuti tocitka
26         */
27
28         //pomocna promenna pro ASCII tocitko
29         aliveState=0;
30
31         QTimer *timer = new QTimer(this);
32         timer->start(500);
33         connect(timer, SIGNAL(timeout()), this, SLOT(alive()));
34     ///***///
35
36     //premalovavani kompasu
37     connect(this, SIGNAL(repaintCompass()), this, SLOT(update()));
38 }
39
40 //sipka od uhlu natoceni
41 void DisplayQT::paintEvent(QPaintEvent *)
42 {
43         //umisteni stredu kompasu
44         int const x=405;
45         int const y=105;
46         int const dimension=80;
47
48         static const QPoint hourHand[3] = {
49                 QPoint(4, 4),
50                 QPoint(-4, 4),
51                 QPoint(0, -((dimension/2)-15))
52     };
53
54
55         //barvy pro malovani
56         QColor prvniColor(127, 0, 127);
57         QColor druhaColor(0, 127, 127, 191);
58         QColor pozadi(240, 240, 240);
59
60         QPainter painter(this);
61
62         //background
63         painter.fillRect(x-dimension/2, y-dimension/2, dimension, dimension, pozadi);
64
65         painter.setRenderHint(QPainter::Antialiasing);
66         painter.translate(x,y);
67
68         painter.setPen(Qt::NoPen);
69         painter.setBrush(prvniColor);
70         painter.save();
71
72     //namalovani sipky p.t.k. je aktualni pozice
73         if(pos.positionIsActual){
74                 painter.rotate(90-pos.phi);
75                 painter.drawConvexPolygon(hourHand, 3);
76         }
77         painter.restore();
78
79     //namaluju 4 cary po 90 stupnich
80         painter.setPen(prvniColor);
81         for(int i=0; i<4; i++){
82                 painter.drawLine((dimension/2)-10, 0, (dimension/2)-5, 0);
83                 painter.rotate(90.0);
84         }
85
86         //namaluju mensi cary mezi ty predchozi
87         painter.setPen(druhaColor);
88
89         for(int j=0; j<12; j++){
90                 if(j%3)
91                         painter.drawLine((dimension/2)-12, 0, (dimension/2)-7, 0);
92                 painter.rotate(30.0);
93         }
94 }
95
96 DisplayQT::~DisplayQT()
97 {
98         delete ui;
99 }
100
101 void DisplayQT::alive(void)
102 {
103         if(++aliveState==4)
104                 aliveState=0;
105
106         switch(aliveState){
107                 case 0: ui->ziju->setText("|");break;
108                 case 1: ui->ziju->setText("/");break;
109                 case 2: ui->ziju->setText("-");break;
110                 case 3: ui->ziju->setText("\\");break;
111         }
112 }
113
114 // 0-modra
115 // 1-cervena
116 void DisplayQT::setTeamColor(char color)
117 {
118         if(color==0){
119                 color=0;
120                 ui->our_color->setStyleSheet("background-color: blue");
121         }else if(color==1){
122                 color=1;
123                 ui->our_color->setStyleSheet("background-color: rgb(213, 40, 24)");
124         }
125 }
126
127 void DisplayQT::setPosition(double x, double y, double phi)
128 {
129         this->pos.x=x;
130         this->pos.y=y;
131         this->pos.phi=phi;
132
133         //prevod z radianu na stupne a uprava
134         pos.phi = RAD2DEG(pos.phi);
135         pos.phi = fmod(pos.phi, 360);
136         if ( pos.phi < 0 )
137                 pos.phi += 360;
138
139         ui->position_x->setText("x: "+QString::number(pos.x, 10, 3)+" m");
140         ui->position_y->setText("y: "+QString::number(pos.y, 10, 3)+" m");
141         ui->position_phi->setText("phi: "+QString::number(pos.phi, 10, 1)+" deg");
142
143         pos.positionIsActual=true;
144         emit repaintCompass();
145 }
146
147 void DisplayQT::display_status(UDE_component_t c, UDE_hw_status_t s)
148 {
149         switch(c){
150                 case 0:break;
151                 case MOT:
152                         if(s==STATUS_OK)
153                                 ui->comp_MOT->setStyleSheet(GREEN);
154                         else if(s==STATUS_FAILED)
155                                 ui->comp_MOT->setStyleSheet(RED);
156                         else
157                                 ui->comp_MOT->setStyleSheet(YELLOW);
158                 break;
159                 case ODO:
160                         if(s==STATUS_OK)
161                                 ui->comp_ODO->setStyleSheet(GREEN);
162                         else if(s==STATUS_FAILED)
163                                 ui->comp_ODO->setStyleSheet(RED);
164                         else
165                                 ui->comp_ODO->setStyleSheet(YELLOW);
166                 break;
167                 case CAM:
168                         if(s==STATUS_OK)
169                                 ui->comp_CAM->setStyleSheet(GREEN);
170                         else if(s==STATUS_FAILED)
171                                 ui->comp_CAM->setStyleSheet(RED);
172                         else
173                                 ui->comp_CAM->setStyleSheet(YELLOW);
174                         break;
175                 case PWR:
176                         if(s==STATUS_OK)
177                                 ui->comp_PWR->setStyleSheet(GREEN);
178                         else if(s==STATUS_FAILED){
179                                 ui->comp_PWR->setStyleSheet(RED);
180
181                                 ui->voltage_33->setText("v.33 = ?");
182                                 ui->voltage_50->setText("v.50 = ?");
183                                 ui->voltage_80->setText("v.80 = ?");
184                                 ui->voltage_BAT->setText("v.BAT = ?");
185
186                                 ui->voltage_33->setStyleSheet(YELLOW);
187                                 ui->voltage_50->setStyleSheet(YELLOW);
188                                 ui->voltage_80->setStyleSheet(YELLOW);
189                                 ui->voltage_BAT->setStyleSheet(YELLOW);
190                         }
191                         else
192                                 ui->comp_PWR->setStyleSheet(YELLOW);
193                 break;
194                 case HOK:
195                         if(s==STATUS_OK)
196                                 ui->comp_HOK->setStyleSheet(GREEN);
197                         else if(s==STATUS_FAILED)
198                                 ui->comp_HOK->setStyleSheet(RED);
199                         else
200                                 ui->comp_HOK->setStyleSheet(YELLOW);
201                         break;
202                 case APP:
203                         if(s==STATUS_OK)
204                                 ui->comp_APP->setStyleSheet(GREEN);
205                         else if(s==STATUS_FAILED){
206                                 ui->comp_APP->setStyleSheet(RED);
207
208                                 pos.positionIsActual=false;
209                                 ui->position_x->setText("x: ?");
210                                 ui->position_y->setText("y: ?");
211                                 ui->position_phi->setText("phi: ?");
212                                 emit repaintCompass();
213                         }
214                         else
215                                 ui->comp_APP->setStyleSheet(YELLOW);
216                         break;
217                 case VID:
218                         if(s==STATUS_OK)
219                                 ui->comp_VID->setStyleSheet(GREEN);
220                         else if(s==STATUS_FAILED)
221                                 ui->comp_VID->setStyleSheet(RED);
222                         else
223                                 ui->comp_VID->setStyleSheet(YELLOW);
224                         break;
225                 case STA:
226                         if(s==STATUS_OK)
227                                 ui->comp_STA->setStyleSheet(GREEN);
228                         else if(s==STATUS_FAILED)
229                                 ui->comp_STA->setStyleSheet(RED);
230                         else
231                                 ui->comp_STA->setStyleSheet(YELLOW);
232                 break;
233         }
234 }
235
236 void DisplayQT::display_fsm(UDE_fsm_t fsm, QString state){
237
238         switch(fsm){
239                 case FSM_MAIN:
240                         ui->fsm_main->setText(state);
241                 break;
242                 case FSM_MOVE:
243                         ui->fsm_move->setText(state);
244                 break;
245                 case FSM_ACT:
246                         ui->fsm_act->setText(state);
247                 break;
248         }
249 }
250
251 void DisplayQT::display_voltage(double voltage33, double voltage50, double voltage80, double voltageBAT){
252         ui->voltage_33->setText("v.33 = "+QString::number(voltage33, 10, 2)+" V");
253         ui->voltage_50->setText("v.50 = "+QString::number(voltage50, 10, 2)+" V");
254         ui->voltage_80->setText("v.80 = "+QString::number(voltage80, 10, 2)+" V");
255         ui->voltage_BAT->setText("v.BAT = "+QString::number(voltageBAT, 10, 2)+" V");
256
257
258         if( voltageBAT < WARNING_VOLTAGEBAT && voltageBAT > TRESHOLDS_VOLTAGEBAT )
259                 ui->voltage_BAT->setStyleSheet(YELLOW);
260         else if( voltageBAT < TRESHOLDS_VOLTAGEBAT )
261                 ui->voltage_BAT->setStyleSheet(RED);
262         else
263                 ui->voltage_BAT->setStyleSheet(GREEN);
264
265
266
267
268         if( voltage33 < TRESHOLDS_VOLTAGE33 )
269                 ui->voltage_33->setStyleSheet(YELLOW);
270         else
271                 ui->voltage_33->setStyleSheet(GREEN);
272
273         if( voltage50 < TRESHOLDS_VOLTAGE50 )
274                 ui->voltage_50->setStyleSheet(YELLOW);
275         else
276                 ui->voltage_50->setStyleSheet(GREEN);
277
278         if( voltage80 < TRESHOLDS_VOLTAGE80 )
279                 ui->voltage_80->setStyleSheet(YELLOW);
280         else
281                 ui->voltage_80->setStyleSheet(GREEN);
282 }