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