2 #include "ui_displayqt.h"
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"
14 DisplayQT::DisplayQT(QWidget *parent) :
20 /* create the window without the title bar */
21 Qt::WindowFlags flags = this->windowFlags();
22 flags |= Qt::FramelessWindowHint;
23 this->setWindowFlags(flags);
25 //cursor will be hidden
26 setCursor(QCursor(Qt::BlankCursor));
28 //na zacatku nazname polohu
29 this->pos.positionIsActual=false;
32 pomoci timeru je kazdych 500 ms
33 vyvolan signal pro pohnuti tocitka
36 QTimer *timer = new QTimer(this);
38 connect(timer, SIGNAL(timeout()), this, SLOT(alive()));
41 //premalovavani kompasu
42 connect(this, SIGNAL(repaintCompass()), this, SLOT(update()));
45 //sipka od uhlu natoceni
46 void DisplayQT::paintEvent(QPaintEvent *)
48 //umisteni stredu kompasu
51 int const dimension=80;
53 static const QPoint arrow[3] = {
56 QPoint(0, -((dimension/2)-15))
61 QColor prvniColor(127, 0, 127);
62 QColor druhaColor(0, 127, 127, 191);
63 QColor pozadi(240, 240, 240);
65 QPainter painter(this);
68 painter.fillRect(x-dimension/2, y-dimension/2, dimension, dimension, pozadi);
70 painter.setRenderHint(QPainter::Antialiasing);
71 painter.translate(x,y);
73 painter.setPen(Qt::NoPen);
74 painter.setBrush(prvniColor);
77 //namalovani sipky p.t.k. je aktualni pozice
78 if(pos.positionIsActual){
79 painter.rotate(90-pos.phi);
80 painter.drawConvexPolygon(arrow, 3);
84 //namaluju 4 cary po 90 stupnich
85 painter.setPen(prvniColor);
86 for(int i=0; i<4; i++){
87 painter.drawLine((dimension/2)-10, 0, (dimension/2)-5, 0);
91 //namaluju mensi cary mezi ty predchozi
92 painter.setPen(druhaColor);
94 for(int j=0; j<12; j++){
96 painter.drawLine((dimension/2)-12, 0, (dimension/2)-7, 0);
101 DisplayQT::~DisplayQT()
106 void DisplayQT::alive(void)
108 static char aliveState=0;
113 case 0: ui->ziju->setText("|");break;
114 case 1: ui->ziju->setText("/");break;
115 case 2: ui->ziju->setText("-");break;
116 case 3: ui->ziju->setText("\\");break;
122 void DisplayQT::setTeamColor(char color)
126 ui->our_color->setStyleSheet("background-color: blue");
129 ui->our_color->setStyleSheet("background-color: rgb(213, 40, 24)");
133 void DisplayQT::setPosition(double x, double y, double phi)
139 //prevod z radianu na stupne a uprava
140 pos.phi = RAD2DEG(pos.phi);
141 pos.phi = fmod(pos.phi, 360);
145 ui->position_x->setText("x: "+QString::number(pos.x, 10, 3)+" m");
146 ui->position_y->setText("y: "+QString::number(pos.y, 10, 3)+" m");
147 ui->position_phi->setText("phi: "+QString::number(pos.phi, 10, 1)+" deg");
149 pos.positionIsActual=true;
150 emit repaintCompass();
153 void DisplayQT::display_status(UDE_component_t c, UDE_hw_status_t s)
159 ui->comp_MOT->setStyleSheet(GREEN);
160 else if(s==STATUS_FAILED)
161 ui->comp_MOT->setStyleSheet(RED);
163 ui->comp_MOT->setStyleSheet(YELLOW);
167 ui->comp_ODO->setStyleSheet(GREEN);
168 else if(s==STATUS_FAILED)
169 ui->comp_ODO->setStyleSheet(RED);
171 ui->comp_ODO->setStyleSheet(YELLOW);
175 ui->comp_CAM->setStyleSheet(GREEN);
176 else if(s==STATUS_FAILED)
177 ui->comp_CAM->setStyleSheet(RED);
179 ui->comp_CAM->setStyleSheet(YELLOW);
183 ui->comp_PWR->setStyleSheet(GREEN);
184 else if(s==STATUS_FAILED){
185 ui->comp_PWR->setStyleSheet(RED);
187 ui->voltage_33->setText("v.33 = ?");
188 ui->voltage_50->setText("v.50 = ?");
189 ui->voltage_80->setText("v.80 = ?");
190 ui->voltage_BAT->setText("v.BAT = ?");
192 ui->voltage_33->setStyleSheet(YELLOW);
193 ui->voltage_50->setStyleSheet(YELLOW);
194 ui->voltage_80->setStyleSheet(YELLOW);
195 ui->voltage_BAT->setStyleSheet(YELLOW);
198 ui->comp_PWR->setStyleSheet(YELLOW);
202 ui->comp_HOK->setStyleSheet(GREEN);
203 else if(s==STATUS_FAILED)
204 ui->comp_HOK->setStyleSheet(RED);
206 ui->comp_HOK->setStyleSheet(YELLOW);
210 ui->comp_APP->setStyleSheet(GREEN);
211 else if(s==STATUS_FAILED){
212 ui->comp_APP->setStyleSheet(RED);
214 pos.positionIsActual=false;
215 ui->position_x->setText("x: ?");
216 ui->position_y->setText("y: ?");
217 ui->position_phi->setText("phi: ?");
218 emit repaintCompass();
221 ui->comp_APP->setStyleSheet(YELLOW);
225 ui->comp_VID->setStyleSheet(GREEN);
226 else if(s==STATUS_FAILED)
227 ui->comp_VID->setStyleSheet(RED);
229 ui->comp_VID->setStyleSheet(YELLOW);
233 ui->comp_STA->setStyleSheet(GREEN);
234 else if(s==STATUS_FAILED)
235 ui->comp_STA->setStyleSheet(RED);
237 ui->comp_STA->setStyleSheet(YELLOW);
242 void DisplayQT::display_fsm(UDE_fsm_t fsm, QString state){
246 ui->fsm_main->setText(state);
249 ui->fsm_move->setText(state);
252 ui->fsm_act->setText(state);
257 void DisplayQT::display_voltage(double voltage33, double voltage50, double voltage80, double voltageBAT){
258 ui->voltage_33->setText("v.33 = "+QString::number(voltage33, 10, 2)+" V");
259 ui->voltage_50->setText("v.50 = "+QString::number(voltage50, 10, 2)+" V");
260 ui->voltage_80->setText("v.80 = "+QString::number(voltage80, 10, 2)+" V");
261 ui->voltage_BAT->setText("v.BAT = "+QString::number(voltageBAT, 10, 2)+" V");
264 if( voltageBAT < WARNING_VOLTAGEBAT && voltageBAT > TRESHOLDS_VOLTAGEBAT )
265 ui->voltage_BAT->setStyleSheet(YELLOW);
266 else if( voltageBAT < TRESHOLDS_VOLTAGEBAT )
267 ui->voltage_BAT->setStyleSheet(RED);
269 ui->voltage_BAT->setStyleSheet(GREEN);
274 if( voltage33 < TRESHOLDS_VOLTAGE33 )
275 ui->voltage_33->setStyleSheet(YELLOW);
277 ui->voltage_33->setStyleSheet(GREEN);
279 if( voltage50 < TRESHOLDS_VOLTAGE50 )
280 ui->voltage_50->setStyleSheet(YELLOW);
282 ui->voltage_50->setStyleSheet(GREEN);
284 if( voltage80 < TRESHOLDS_VOLTAGE80 )
285 ui->voltage_80->setStyleSheet(YELLOW);
287 ui->voltage_80->setStyleSheet(GREEN);