Advertisement
Guest User

wolne wyświetlanie QLCDNumber

a guest
Jul 20th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1.  
  2.     #include "mainwindow.h"
  3.     #include "ui_mainwindow.h"
  4.     #include <QMessageBox>
  5.      
  6.     extern bool brak_fl;
  7.     int new_temp1_val;
  8.     int old_temp1_val;
  9.     int new_temp2_val;
  10.     int old_temp2_val;
  11.     int new_temp3_val;
  12.     int old_temp3_val;
  13.      
  14.     //Przykładowa ramka z MCU : @100,200,300$
  15.     //
  16.     //
  17.     //
  18.     //
  19.      
  20.      
  21.     // aktualizacja widgetów, po odebraniu danych
  22.     void MainWindow::update(int value, int which_LCD)
  23.     {
  24.         // ustawiamy wartość temperatury
  25.         if(which_LCD == 1) ui->temperatura1->display(value);
  26.         else if(which_LCD == 2) ui->temperatura2->display(value);
  27.         else if(which_LCD == 3) ui->temperatura3->display(value);
  28.         // zmieniamy date ostatniej aktualizacji
  29.         ui->lastUpdate->setDateTime(QDateTime(QDate::currentDate(),QTime::currentTime()));
  30.     }
  31.      
  32.     // wczytywanie danych
  33.     void MainWindow::readData()
  34.     {
  35.             array = port->readAll();
  36.             while(port->waitForReadyRead(100))
  37.             array += port->readAll();
  38.             port->clear(QSerialPort::AllDirections);
  39.              
  40.             QString a(array);
  41.              
  42.             if(a.at(0) == '@' && a.at(a.size()-1) == '$')
  43.             {
  44.                 a.remove('$');
  45.                 a.remove('@');
  46.                 QStringList list = a.split(",");
  47.                 QString temp1 = list.at(0);
  48.                 QString temp2 = list.at(1);
  49.                 QString temp3 = list.at(2);
  50.              
  51.                 new_temp1_val = temp1.toInt();
  52.                 new_temp2_val = temp2.toInt();
  53.                 new_temp3_val = temp3.toInt();
  54.                 if(new_temp1_val != old_temp1_val) update(new_temp1_val,1);
  55.                 if(new_temp2_val != old_temp2_val) update(new_temp2_val,2);
  56.                 if(new_temp3_val != old_temp3_val) update(new_temp3_val,3);
  57.                  
  58.                 old_temp1_val = new_temp1_val;
  59.                 old_temp2_val = new_temp2_val;
  60.                 old_temp3_val = new_temp3_val;
  61.              
  62.              
  63.                 array.clear();
  64.             }
  65.      
  66.      
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement