direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
consoleGui.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) Markus Knapp *
3  * www.direcs.de *
4  * *
5  * This file is part of direcs. *
6  * *
7  * direcs is free software: you can redistribute it and/or modify it *
8  * under the terms of the GNU General Public License as published *
9  * by the Free Software Foundation, version 3 of the License. *
10  * *
11  * direcs is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with direcs. If not, see <http://www.gnu.org/licenses/>. *
18  * *
19  *************************************************************************/
20 
21 #include "consoleGui.h"
22 
23 
25 {
26 }
27 
28 
30 {
31 }
32 
33 /*
34 \todo void ConsoleGui::closeEvent()
35 {
36  qDebug("closeEvent");
37  emit shutdown();
38 }
39 */
40 
41 
43 {
44  // store the state
45  robotIsOn = state;
46 }
47 
48 
49 void ConsoleGui::appendLog(QString text, bool CR, bool sayIt)
50 {
51  Q_UNUSED(CR);
52  Q_UNUSED(sayIt);
53  QByteArray textForConsole;
54 
55  //------------------------------
56  // remove HTML tags from string
57  //------------------------------
58  int start= -1;
59  do
60  {
61  // search for the first HTML "<"
62  start = text.indexOf("<");
63 
64  if (start != 1)
65  {
66  text.remove(start, text.indexOf(">") + 1 - start );
67  }
68  } while (text.contains(">"));
69  // till the last HTML ">" is found
70 
71  // print text to console
72  // qDebug() << text; is NOT used, because it adds quotation marks to all strings
73  textForConsole = text.toLatin1();
74  qDebug("%s", textForConsole.data());
75 }
76 
77 
78 void ConsoleGui::appendNetworkLog(QString text, bool CR, bool sayIt)
79 {
80  Q_UNUSED(CR);
81  Q_UNUSED(sayIt);
82  QByteArray textForConsole;
83 
84  // print text to console
85  // qDebug() << text; is NOT used, because it adds quotation marks to all strings
86  textForConsole = text.toLatin1();
87  qDebug("NETWORK COMMAND: %s", textForConsole.data());
88 }
89 
90 
91 void ConsoleGui::appendSerialLog(QString text, bool CR)
92 {
93  Q_UNUSED(CR);
94  QByteArray textForConsole;
95 
96  //------------------------------
97  // remove HTML tags from string
98  //------------------------------
99  int start= -1;
100  do
101  {
102  // search for the first HTML "<"
103  start = text.indexOf("<");
104 
105  if (start != 1)
106  {
107  text.remove(start, text.indexOf(">") + 1 - start );
108  }
109  } while (text.contains(">"));
110  // till the last HTML ">" is found
111 
112  // print text to console
113  // qDebug() << text; is NOT used, because it adds quotation marks to all strings
114  textForConsole = text.toLatin1();
115  qDebug("%s", textForConsole.data());
116 }
117 
118 
119 
120 
121 void ConsoleGui::showDistanceGraphical(int sensor, int distance)
122 {
123  if ((sensor < SENSOR1) || (sensor > SENSOR16))
124  {
125  return;
126  }
127 
128 
129  switch (sensor)
130  {
131  /*
132  case SENSOR1:
133  ui.progressBarSensor1->setValue(distance);
134  return;
135  break;
136  case SENSOR2:
137  ui.progressBarSensor2->setValue(distance);
138  return;
139  break;
140  case SENSOR3:
141  ui.progressBarSensor3->setValue(distance);
142  return;
143  break;
144  case SENSOR4:
145  ui.progressBarSensor4->setValue(distance);
146  return;
147  break;
148  case SENSOR5:
149  ui.progressBarSensor5->setValue(distance);
150  return;
151  break;
152  case SENSOR6:
153  ui.progressBarSensor6->setValue(distance);
154  return;
155  break;
156  case SENSOR7:
157  ui.progressBarSensor7->setValue(distance);
158  return;
159  break;
160  case SENSOR8:
161  ui.progressBarSensor8->setValue(distance);
162  return;
163  break;
164  */
165  case SENSOR16:
166  // TODO:show values in console
167  Q_UNUSED(sensor);
168  Q_UNUSED(distance);
169  return;
170  break;
171  }
172 }
173 
174 
175 void ConsoleGui::showDrivenDistance(int sensor, int distance)
176 {
177  // show distance value in centimeters in a text label
178  // erwartet den value als distance (z.B. in cm)!
179  if ((sensor < MOTORSENSOR1) || (sensor > MOTORSENSOR2))
180  {
181  return;
182  }
183 
184  Q_UNUSED(sensor);
185  Q_UNUSED(distance);
186 
187  switch (sensor)
188  {
189  case MOTORSENSOR1:
190  // TODO:show values in console
191  return;
192  break;
193  case MOTORSENSOR2:
194  // TODO:show values in console
195  return;
196  break;
197  }
198 }
199 
200 
201 void ConsoleGui::showAlarm(short int sensor, bool state)
202 {
203  if ((sensor < SENSOR1) || (sensor > SENSOR16))
204  {
205  qDebug("error in showAlarm! sensorValue=%d", sensor);
206  return;
207  }
208 
209  Q_UNUSED(sensor);
210  Q_UNUSED(state);
211 
212  switch (sensor)
213  {
214  /*
215  case SENSOR1:
216  if (state == ON)
217  {
218  // change sensor-pixmap color to red [blue = 0, 70, 213]
219  //ui.labelSensorPic1->setPalette(QPalette(labelFillColorRed));
220  //ui.labelSensorAlarm1->setEnabled(true);
221  //ui.frameSensorAlarm1->setPalette(QPalette(labelFillColorRed));
222  // red progressBar background
223  ui.progressBarSensor1->setPalette(QPalette(labelFillColorRed));
224  }
225  else
226  {
227  // change sensor-pixmap color to white
228  //ui.labelSensorPic1->setPalette(QPalette(QColor(255,255,255)));
229  //ui.labelSensorAlarm1->setEnabled(false);
230  //ui.frameSensorAlarm1->setPalette(QPalette(QColor(255,255,255)));
231  // progressBar background white
232  ui.progressBarSensor1->setPalette(QPalette(QColor(255, 255, 255)));
233  }
234  return;
235  break;
236  case SENSOR2:
237  if (state == ON)
238  {
239  // change sensor-pixmap color to red [blue = 0, 70, 213]
240  //ui.labelSensorPic2->setPalette(QPalette(labelFillColorRed));
241  //ui.labelSensorAlarm2->setEnabled(true);
242  //ui.frameSensorAlarm2->setPalette(QPalette(labelFillColorRed));
243  // red progressBar background
244  ui.progressBarSensor2->setPalette(QPalette(labelFillColorRed));
245  }
246  else
247  {
248  // change sensor-pixmap color to white
249  //ui.labelSensorPic2->setPalette(QPalette(QColor(255,255,255)));
250  //ui.labelSensorAlarm2->setEnabled(false);
251  //ui.frameSensorAlarm2->setPalette(QPalette(QColor(255,255,255)));
252  // progressBar background white
253  ui.progressBarSensor2->setPalette(QPalette(QColor(255, 255, 255)));
254  }
255  return;
256  break;
257  case SENSOR3:
258  if (state == ON)
259  {
260  // change sensor-pixmap color to red [blue = 0, 70, 213]
261  //ui.labelSensorPic3->setPalette(QPalette(labelFillColorRed));
262  //ui.labelSensorAlarm3->setEnabled(true);
263  //ui.frameSensorAlarm3->setPalette(QPalette(labelFillColorRed));
264  // red progressBar background
265  ui.progressBarSensor3->setPalette(QPalette(labelFillColorRed));
266  }
267  else
268  {
269  // change sensor-pixmap color to white
270  //ui.labelSensorPic3->setPalette(QPalette(QColor(255,255,255)));
271  //ui.labelSensorAlarm3->setEnabled(false);
272  //ui.frameSensorAlarm3->setPalette(QPalette(QColor(255,255,255)));
273  // progressBar background white
274  ui.progressBarSensor3->setPalette(QPalette(QColor(255, 255, 255)));
275  }
276  return;
277  break;
278  case SENSOR4:
279  if (state == ON)
280  {
281  // change sensor-pixmap color to red [blue = 0, 70, 213]
282  //ui.labelSensorPic4->setPalette(QPalette(labelFillColorRed));
283  //ui.labelSensorAlarm4->setEnabled(true);
284  //ui.frameSensorAlarm4->setPalette(QPalette(labelFillColorRed));
285  // red progressBar background
286  ui.progressBarSensor4->setPalette(QPalette(labelFillColorRed));
287  }
288  else
289  {
290  // change sensor-pixmap color to white
291  //ui.labelSensorPic4->setPalette(QPalette(QColor(255,255,255)));
292  //ui.labelSensorAlarm4->setEnabled(false);
293  //ui.frameSensorAlarm4->setPalette(QPalette(QColor(255,255,255)));
294  // progressBar background white
295  ui.progressBarSensor4->setPalette(QPalette(QColor(255, 255, 255)));
296  }
297  return;
298  break;
299  case SENSOR5:
300  if (state == ON)
301  {
302  // change sensor-pixmap color to red [blue = 0, 70, 213]
303  //ui.labelSensorPic5->setPalette(QPalette(labelFillColorRed));
304  //ui.labelSensorAlarm5->setEnabled(true);
305  //ui.frameSensorAlarm5->setPalette(QPalette(labelFillColorRed));
306  // red progressBar background
307  ui.progressBarSensor5->setPalette(QPalette(labelFillColorRed));
308  }
309  else
310  {
311  // change sensor-pixmap color to white
312  //ui.labelSensorPic5->setPalette(QPalette(QColor(255,255,255)));
313  //ui.labelSensorAlarm5->setEnabled(false);
314  //ui.frameSensorAlarm5->setPalette(QPalette(QColor(255,255,255)));
315  // progressBar background white
316  ui.progressBarSensor5->setPalette(QPalette(QColor(255, 255, 255)));
317  }
318  return;
319  break;
320  case SENSOR6:
321  if (state == ON)
322  {
323  // change sensor-pixmap color to red [blue = 0, 70, 213]
324  //ui.labelSensorPic6->setPalette(QPalette(labelFillColorRed));
325  //ui.labelSensorAlarm6->setEnabled(true);
326  //ui.frameSensorAlarm6->setPalette(QPalette(labelFillColorRed));
327  // red progressBar background
328  ui.progressBarSensor6->setPalette(QPalette(labelFillColorRed));
329  }
330  else
331  {
332  // change sensor-pixmap color to white
333  //ui.labelSensorPic6->setPalette(QPalette(QColor(255,255,255)));
334  //ui.labelSensorAlarm6->setEnabled(false);
335  //ui.frameSensorAlarm6->setPalette(QPalette(QColor(255,255,255)));
336  // progressBar background white
337  ui.progressBarSensor6->setPalette(QPalette(QColor(255, 255, 255)));
338  }
339  return;
340  break;
341  case SENSOR7:
342  if (state == ON)
343  {
344  // change sensor-pixmap color to red [blue = 0, 70, 213]
345  //ui.labelSensorPic7->setPalette(QPalette(labelFillColorRed));
346  //ui.labelSensorAlarm7->setEnabled(true);
347  //ui.frameSensorAlarm7->setPalette(QPalette(labelFillColorRed));
348  // red progressBar background
349  ui.progressBarSensor7->setPalette(QPalette(labelFillColorRed));
350  }
351  else
352  {
353  // change sensor-pixmap color to white
354  //ui.labelSensorPic7->setPalette(QPalette(QColor(255,255,255)));
355  //ui.labelSensorAlarm7->setEnabled(false);
356  //ui.frameSensorAlarm7->setPalette(QPalette(QColor(255,255,255)));
357  // progressBar background white
358  ui.progressBarSensor7->setPalette(QPalette(QColor(255, 255, 255)));
359  }
360  return;
361  break;
362  case SENSOR8:
363  if (state == ON)
364  {
365  // change sensor-pixmap color to red [blue = 0, 70, 213]
366  //ui.labelSensorPic8->setPalette(QPalette(labelFillColorRed));
367  //ui.labelSensorAlarm8->setEnabled(true);
368  //ui.frameSensorAlarm8->setPalette(QPalette(labelFillColorRed));
369  // red progressBot background
370  ui.progressBarSensor8->setPalette(QPalette(labelFillColorRed));
371  }
372  else
373  {
374  // change sensor-pixmap color to white
375  //ui.labelSensorPic8->setPalette(QPalette(QColor(255,255,255)));
376  //ui.labelSensorAlarm8->setEnabled(false);
377  //ui.frameSensorAlarm8->setPalette(QPalette(QColor(255,255,255)));
378  // progressBar background white
379  ui.progressBarSensor8->setPalette(QPalette(QColor(255, 255, 255)));
380  }
381  return;
382  break;
383  */
384  case SENSOR16:
385  if (state == ON)
386  {
387  // change sensor-pixmap color to red [blue = 0, 70, 213]
388  //ui.labelSensorPic16->setPalette(QPalette(labelFillColorRed));
389  //ui.labelSensorAlarm16->setEnabled(true);
390  //ui.frameSensorAlarm16->setPalette(QPalette(labelFillColorRed));
391  // TODO:show values RED in console
392  }
393  else
394  {
395  // change sensor-pixmap color to white
396  //ui.labelSensorPic16->setPalette(QPalette(QColor(255,255,255)));
397  //ui.labelSensorAlarm16->setEnabled(false);
398  //ui.frameSensorAlarm16->setPalette(QPalette(QColor(255,255,255)));
399  // TODO:show values NORMAL in console
400  }
401  return;
402  break;
403  }
404 }
405 
406 
407 void ConsoleGui::showMotorStatus(unsigned char motor, bool power, unsigned char direction)
408 {
409 
410  Q_UNUSED(motor);
411  Q_UNUSED(power);
412  Q_UNUSED(direction);
413 /*
414  switch (motor)
415  {
416  //-------------
417  case MOTOR1:
418  //-------------
419  switch (power)
420  {
421  case ON:
422  // TODO:show value/state in console
423  break;
424  // TODO:show value/state in console
425  break;
426  case SAME:
427  break;
428  }
429 
430  switch (direction)
431  {
432  case CLOCKWISE:
433  // TODO:show value/state in console
434  break;
435  case COUNTERCLOCKWISE:
436  // TODO:show value/state in console
437  break;
438  case SAME:
439  break;
440  }
441  break;
442 
443  //-------------
444  case MOTOR2:
445  //-------------
446  switch (power)
447  {
448  case ON:
449  // TODO:show value/state in console
450  break;
451  case OFF:
452  // TODO:show value/state in console
453  break;
454  case SAME:
455  break;
456  }
457 
458  switch (direction)
459  {
460  case CLOCKWISE:
461  // TODO:show value/state in console
462  break;
463  case COUNTERCLOCKWISE:
464  // TODO:show value/state in console
465  break;
466  case SAME:
467  break;
468  }
469  break;
470 
471  //-------------
472  case MOTOR3:
473  //-------------
474  switch (power)
475  {
476  case ON:
477  // TODO:show value/state in console
478  break;
479  case OFF:
480  // TODO:show value/state in console
481  break;
482  case SAME:
483  break;
484  }
485 
486  switch (direction)
487  {
488  case CLOCKWISE:
489  // TODO:show value/state in console
490  break;
491  case COUNTERCLOCKWISE:
492  // TODO:show value/state in console
493  break;
494  case SAME:
495  break;
496  }
497  break;
498 
499  //-------------
500  case MOTOR4:
501  //-------------
502  switch (power)
503  {
504  case ON:
505  // TODO:show value/state in console
506  break;
507  case OFF:
508  // TODO:show value/state in console
509  break;
510  case SAME:
511  break;
512  }
513 
514  switch (direction)
515  {
516  case CLOCKWISE:
517  // TODO:show value/state in console
518  break;
519  case COUNTERCLOCKWISE:
520  // TODO:show value/state in console
521  break;
522  case SAME:
523  break;
524  }
525  break;
526  } // switch
527  */
528 }
529 
530 
531 void ConsoleGui::showLaserFrontAngles(int largestFreeAreaStart, int largestFreeAreaEnd, int centerOfFreeWay, float width)
532 {
533  Q_UNUSED(largestFreeAreaStart);
534  Q_UNUSED(largestFreeAreaEnd);
535  Q_UNUSED(centerOfFreeWay);
536  Q_UNUSED(width);
537  // TODO:show value/state in console
538 }
539 
540 
541 void ConsoleGui::showPreferredDirection(QString direction)
542 {
543  Q_UNUSED(direction);
544  // TODO:show value/state in console
545  if (direction == "FORWARD")
546  {
547  return;
548  }
549 
550  if (direction == "LEFT")
551  {
552  return;
553  }
554 
555  if (direction == "RIGHT")
556  {
557  return;
558  }
559 }
560 
561 
562 void ConsoleGui::refreshLaserViewFront(QList <float> laserScannerValues, QList <int> laserScannerFlags)
563 {
564  // TODO:show value/state in console
565  Q_UNUSED(laserScannerValues);
566  Q_UNUSED(laserScannerFlags);
567 }
568 
569 
570 void ConsoleGui::refreshLaserViewRear(QList <float> laserScannerValues, QList <int> laserScannerFlags)
571 {
572  // TODO:show value/state in console
573  Q_UNUSED(laserScannerValues);
574  Q_UNUSED(laserScannerFlags);
575 }
576 
577 
578 void ConsoleGui::setLaserscannerAngle(short int laserscanner, int angle)
579 {
580  Q_UNUSED(laserscanner);
581  Q_UNUSED(angle);
582 }
583 
584 
585 void ConsoleGui::setLaserscannerResolution(short int laserscanner, float resolution)
586 {
587  Q_UNUSED(laserscanner);
588  Q_UNUSED(resolution);
589 }