Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QMessageBox>
- extern bool brak_fl;
- int new_temp1_val;
- int old_temp1_val;
- int new_temp2_val;
- int old_temp2_val;
- int new_temp3_val;
- int old_temp3_val;
- //Przykładowa ramka z MCU : @100,200,300$
- //
- //
- //
- //
- // aktualizacja widgetów, po odebraniu danych
- void MainWindow::update(int value, int which_LCD)
- {
- // ustawiamy wartość temperatury
- if(which_LCD == 1) ui->temperatura1->display(value);
- else if(which_LCD == 2) ui->temperatura2->display(value);
- else if(which_LCD == 3) ui->temperatura3->display(value);
- // zmieniamy date ostatniej aktualizacji
- ui->lastUpdate->setDateTime(QDateTime(QDate::currentDate(),QTime::currentTime()));
- }
- // wczytywanie danych
- void MainWindow::readData()
- {
- array = port->readAll();
- while(port->waitForReadyRead(100))
- array += port->readAll();
- port->clear(QSerialPort::AllDirections);
- QString a(array);
- if(a.at(0) == '@' && a.at(a.size()-1) == '$')
- {
- a.remove('$');
- a.remove('@');
- QStringList list = a.split(",");
- QString temp1 = list.at(0);
- QString temp2 = list.at(1);
- QString temp3 = list.at(2);
- new_temp1_val = temp1.toInt();
- new_temp2_val = temp2.toInt();
- new_temp3_val = temp3.toInt();
- if(new_temp1_val != old_temp1_val) update(new_temp1_val,1);
- if(new_temp2_val != old_temp2_val) update(new_temp2_val,2);
- if(new_temp3_val != old_temp3_val) update(new_temp3_val,3);
- old_temp1_val = new_temp1_val;
- old_temp2_val = new_temp2_val;
- old_temp3_val = new_temp3_val;
- array.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement