# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-07-05 21:43:23 # Node ID 1c804a335df5e32387b64fa27c7bbd99f0e8adbc # Parent a3a98f85e1c27a71b1757e91b33e082a3ac3bc5c move binary sample printing to its own function diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -577,12 +577,28 @@ template double MainWindow:: T data; this->serialPort.read((char*) &data, sizeof(data)); + printBinarySample((char*) &data, sizeof(data)); + + if (ui->rbLittleE->isChecked()) + { + data = qFromLittleEndian(data); + } + else + { + data = qFromBigEndian(data); + } + + return double(data); +} + +void MainWindow::printBinarySample(char* data, int size) +{ // print data in hex format if (ui->cbEnableTextView->isChecked()) { QTextCursor cursor(ui->ptTextView->document()); cursor.movePosition(QTextCursor::End); - QByteArray ba((char*) &data, sizeof(data)); + QByteArray ba(data, size); QScrollBar* vbar = ui->ptTextView->verticalScrollBar(); bool isEnd = (vbar->value() == vbar->maximum()); @@ -599,17 +615,6 @@ template double MainWindow:: vbar->setValue(vbar->maximum()); } } - - if (ui->rbLittleE->isChecked()) - { - data = qFromLittleEndian(data); - } - else - { - data = qFromBigEndian(data); - } - - return double(data); } bool MainWindow::isDemoRunning() diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -99,6 +99,9 @@ private: unsigned int sampleCount; QTimer spsTimer; + // prints to text view if its is enabled + void printBinarySample(char* data, int size); + // demo QTimer demoTimer; int demoCount;